BUZZ AI Gateway
文档 · API 参考 · 余额查询

余额查询

BUZZ 暴露两个 OpenAI 风格的 dashboard billing 接口,让大量基于 OpenAI /dashboard/billing/* 的余额查询脚本和反代 UI 不改一行代码就能跑起来。返回的数字会按站点配置的展示单位输出。

GET https://buzzai.cc/v1/dashboard/billing/subscription
GET https://buzzai.cc/v1/dashboard/billing/usage
OpenAI 兼容形态,BUZZ 自己的语义。 JSON 形状对齐 OpenAI 旧版 dashboard billing 接口,所以余额查询脚本与反代 UI 可以直接接入。但数字含义取决于站点的 quota 展示设置 — 详见下文 QuotaDisplayType

鉴权

两个接口都需要用户 API token(从 BUZZ 控制台创建的 sk- 前缀 key)。走的是和 /v1/messages/v1/chat/completions 同一条 relay token 鉴权链。

Header说明
Authorization: Bearer sk-<TOKEN>服务端会自动剥离 sk- 前缀,以第一个连字符前的段作为查询 key。

不需要 Buzz-User header,token 自身已绑定持有者。

QuotaDisplayType:数字怎么算出来的

BUZZ 内部统一以原始 quota 整数存储,只在响应这两个接口时换算成可读数字。换算规则取决于站点的 QuotaDisplayType 设置:

QuotaDisplayType换算公式响应数字含义
USD(默认)amount = quota / QuotaPerUnit美元金额。
CNYamount = quota / QuotaPerUnit * USDExchangeRate本地货币,按站点汇率换算。
Tokensamount = quota原始 quota 单位,语义等同于 token 数,不是货币。

这意味着 subscription 响应里的 soft_limit_usd 和 usage 响应里的 total_usage 未必是美元。字段名为了 OpenAI 兼容性保留,但实际单位以站点展示设置为准。请把单位当成 opaque,与控制台展示的货币保持一致。

GET /v1/dashboard/billing/subscription

返回该 token(或者站点未启用 token 维度统计时返回该用户)的"剩余 + 已用"配额,按"信用额度"形态输出。这是大多数余额查询脚本轮询的路径。

数字来源

请求示例

curl -s 'https://buzzai.cc/v1/dashboard/billing/subscription' \
  -H "Authorization: Bearer sk-$BUZZ_TOKEN"
import os, requests

resp = requests.get(
    "https://buzzai.cc/v1/dashboard/billing/subscription",
    headers={"Authorization": f"Bearer sk-{os.environ['BUZZ_TOKEN']}"},
    timeout=10,
)
data = resp.json()
print(data["soft_limit_usd"], data["access_until"])
const resp = await fetch(
  "https://buzzai.cc/v1/dashboard/billing/subscription",
  { headers: { Authorization: `Bearer sk-${process.env.BUZZ_TOKEN}` } },
);
const data = await resp.json();
console.log(data.soft_limit_usd, data.access_until);

实测响应

{
  "object": "billing_subscription",
  "has_payment_method": true,
  "soft_limit_usd": 1234.622754,
  "hard_limit_usd": 1234.622754,
  "system_hard_limit_usd": 1234.622754,
  "access_until": 0
}

2026-05-26 实测,使用普通限额 token。三个 limit 字段同值;access_until = 0 对应无过期时间的 token。

响应字段

字段类型说明
objectstring恒为 "billing_subscription"
has_payment_methodboolean硬编码为 true,只为 OpenAI 形状兼容。不要把它当作真实支付状态判断依据。
soft_limit_usdnumber"剩余 + 已用"配额,按 QuotaDisplayType 换算(见上)。字段名带 USD,但实际单位未必是美元。
hard_limit_usdnumbersoft_limit_usd 同值。
system_hard_limit_usdnumbersoft_limit_usd 同值。
access_untilintegertoken 过期 Unix 时间戳(秒)。无过期则为 0

GET /v1/dashboard/billing/usage

返回当前 token(或用户)的累计已用配额。OpenAI 原始接口按时间段查询;BUZZ 这版返回的是单一累计数,忽略任何 query 参数。

数字来源

请求示例

curl -s 'https://buzzai.cc/v1/dashboard/billing/usage' \
  -H "Authorization: Bearer sk-$BUZZ_TOKEN"
import os, requests

resp = requests.get(
    "https://buzzai.cc/v1/dashboard/billing/usage",
    headers={"Authorization": f"Bearer sk-{os.environ['BUZZ_TOKEN']}"},
    timeout=10,
)
total_cents = resp.json()["total_usage"]
print(f"used: {total_cents / 100:.2f}")  # 除以 100 还原成展示单位
const resp = await fetch(
  "https://buzzai.cc/v1/dashboard/billing/usage",
  { headers: { Authorization: `Bearer sk-${process.env.BUZZ_TOKEN}` } },
);
const { total_usage } = await resp.json();
console.log(`used: ${(total_usage / 100).toFixed(2)}`);

实测响应

{
  "object": "list",
  "total_usage": 117621.9826
}

2026-05-26 实测。返回值是"展示单位 × 100",除以 100 即可还原 dashboard 上看到的数字。

响应字段

字段类型说明
objectstring恒为 "list"(为了 OpenAI 形状兼容保留,即使没有 items 数组)。
total_usagenumber累计消耗 × 100。除以 100 还原展示单位。

错误码

HTTPerror.type典型场景
401buzz_errorsk- token 缺失或非法。
429buzz_error命中全局速率限制。
500upstream_error(subscription)/ buzz_error(usage)取 token 或用户状态失败。两个接口的 error.type 不同:subscription 用 upstream_error,usage 用 buzz_error

相关链接