NB文档doc.nbjs.ai
AI 网关 / 计费与私钥

计费与私钥

金额统一记 USD,按实际用量扣费。

计费单位

类型单位默认单价
文本1M token输入 0.28 / 缓存 0.028 / 输出 0.42
图片张0.02
TTS1K 字符0.028
ASR分钟0.002
视频秒0.034

默认值在 ai/src/rates.js,可用 ai/nb.toml 覆盖:

[config.rates]
markup = 1

[config.rates.text."deepseek-flash"]
input = 0.28
cache = 0.028
output = 0.42

[config.rates.image."wanx2.1-t2i-turbo"]
per_image = 0.02

改配置不需要改代码,也不需要重启。

余额与用量

GET /v1/balance
GET /v1/usage?limit=30
GET /api/orders?limit=20

应用继承

远程部署时 app 控制台会在租户 nb.toml 追加:

[config]
ai_url = "https://ai.nbjs.ai"
ai_key = "<当前用户、当前应用的 JWT>"

应用里直接调用:

const response = await fetch(nb.config.ai_url + "/v1/chat/completions", {
  method: "POST",
  headers: {
    authorization: "Bearer " + nb.config.ai_key,
    "content-type": "application/json",
  },
  body: JSON.stringify({ messages: [{ role: "user", content: "你好" }] }),
});

计费记在部署者邮箱,重新部署自动续期。

私钥

应用不需要接触 DeepSeek / 百炼私钥。平台私钥只留在 ai 服务端,应用用 ai_key 或 sk-nb- 私钥访问网关。