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

余额查询

下面三个接口都用你的 sk- API key 鉴权——和调用 /v1/messages/v1/chat/completions 用的是同一把 key。其中两个 /v1/dashboard/billing/* 接口对齐 OpenAI 旧版 dashboard 形状,现成的余额查询脚本和反代 UI 不改代码就能用;/api/usage/token/ 是 BUZZ 原生接口,把额度拆成剩余 / 已用 / 总授予三部分。

接口鉴权返回
GET /v1/dashboard/billing/subscriptionsk- key剩余额度(余额)
GET /v1/dashboard/billing/usagesk- key累计已用
GET /api/usage/token/sk- key额度明细(剩余 / 已用 / 上限)
用你的 sk- API key,不是账户 access token。 这三个接口都能用你手里那把 key 直接轮询。另有一个 GET /api/user/self 也能看余额,但它用的是账户 access token(在控制台设置里生成)外加 Buzz-User header——拿 sk- key 调它会被拒,报 "invalid access token"。要用 sk- key 查余额,请用本页这三个接口。
OpenAI 兼容形态,BUZZ 自己的语义。 两个 /v1/dashboard/billing/* 响应对齐 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": 1,
  "hard_limit_usd": 1,
  "system_hard_limit_usd": 1,
  "access_until": 0
}

2026-06-09 实测,普通限额 token(USD 展示)。三个 limit 字段同值;站点未启用 token 维度统计,所以这里不暴露 token 过期时间,access_until = 0

响应字段

字段类型说明
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": 13.6228
}

2026-06-09 实测(与上面同一个 token)。返回值是"展示单位 × 100",除以 100 即可还原 dashboard 上看到的数字(此处约为已用 $0.136)。

响应字段

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

GET /api/usage/token/

BUZZ 原生接口,把当前 token 的额度拆成三部分返回——总授予、已用、剩余——不做任何货币换算。返回的是原始 quota 单位(和内部存储的整数一致;除以 QuotaPerUnit,默认 500000,即得美元)。这是查单把 key 剩余额度最直接的方式。

结尾斜杠不能少。 路径是带结尾斜杠的 /api/usage/token/。请求 /api/usage/token(无斜杠)会返回重定向。

数字来源

请求示例

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

resp = requests.get(
    "https://buzzai.cc/api/usage/token/",
    headers={"Authorization": f"Bearer sk-{os.environ['BUZZ_TOKEN']}"},
    timeout=10,
)
d = resp.json()["data"]
print(d["total_available"] / 500000, "USD 剩余")  # 除以 QuotaPerUnit
const resp = await fetch(
  "https://buzzai.cc/api/usage/token/",
  { headers: { Authorization: `Bearer sk-${process.env.BUZZ_TOKEN}` } },
);
const { data } = await resp.json();
console.log(data.total_available / 500000, "USD 剩余");

实测响应

{
  "code": true,
  "message": "ok",
  "data": {
    "object": "token_usage",
    "name": "claude",
    "total_granted": 500000,
    "total_used": 68114,
    "total_available": 431886,
    "unlimited_quota": false,
    "model_limits_enabled": false,
    "model_limits": {},
    "expires_at": 1781502010
  }
}

2026-06-09 实测。total_granted = total_used + total_available(500000 = 68114 + 431886)。任一字段除以 QuotaPerUnit(500000)即换算成美元——此处约为 $1.00 授予额度下剩余 $0.864。

响应字段

字段类型说明
codeboolean成功为 true。注意此接口用 code/message/data 信封,不是 relay 的 error 信封。
messagestring成功为 "ok"
data.objectstring恒为 "token_usage"
data.namestringtoken 的显示名称。
data.total_grantedinteger剩余 + 已用,原始 quota 单位。
data.total_usedinteger已消耗 quota,原始单位。
data.total_availableinteger剩余 quota,原始单位。超额时可为负。
data.unlimited_quotabooleantoken 无额度上限时为 true,此时三个额度数字均为 0
data.model_limits_enabledboolean该 token 是否启用按模型限制。
data.model_limitsobject按模型限制的映射(未启用时为空)。
data.expires_atintegertoken 过期 Unix 时间戳(秒)。无过期则为 0

错误码

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

相关链接