AI 网关 / 计费与私钥
计费与私钥
金额统一记 USD,按实际用量扣费。
计费单位
| 类型 | 单位 | 默认单价 |
|---|---|---|
| 文本 | 1M token | 输入 0.28 / 缓存 0.028 / 输出 0.42 |
| 图片 | 张 | 0.02 |
| TTS | 1K 字符 | 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
改配置不需要改代码,也不需要重启。
余额与用量
- 余额 = 已支付订单
quota之和 −usage.cost。 - 余额不足返回 402,并带
needsRecharge: true。 usage同时记录kind、units、unit,可区分文本、图片、TTS、ASR、视频。
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- 私钥访问网关。