余额与用量查询
在控制台查看
Section titled “在控制台查看”- 账户余额:控制台首页或 钱包 页。
- 每次请求的扣费:日志 页(/console/log),可以按令牌、模型和时间筛选,也可以导出。
- 令牌的已用量和剩余额度:令牌 页的列表。
用 API Key 查询
Section titled “用 API Key 查询”网关提供两个与 OpenAI 旧版账单接口格式兼容的端点,用 sk- 令牌就能调用:
# 额度与过期时间curl https://api.openpalmlab.com/v1/dashboard/billing/subscription \ -H "Authorization: Bearer sk-xxxx"
# 已用量curl https://api.openpalmlab.com/v1/dashboard/billing/usage \ -H "Authorization: Bearer sk-xxxx"/v1/dashboard/billing/subscription 返回:
| 字段 | 含义 |
|---|---|
soft_limit_usd / hard_limit_usd |
有额度上限的令牌:这个令牌的总额度(已用 + 剩余)。无限额度的令牌:固定返回占位值 100000000,不代表余额。 |
access_until |
令牌过期时间(Unix 秒),0 表示永不过期。 |
/v1/dashboard/billing/usage 返回:
| 字段 | 含义 |
|---|---|
total_usage |
已用金额,单位是 0.01 美元,换算成美元要除以 100。 |
计算剩余额度
Section titled “计算剩余额度”有额度上限的令牌:剩余 = soft_limit_usd − total_usage / 100无限额度的令牌: 这两个端点算不出剩余,请到控制台查看账户余额例:soft_limit_usd = 100,total_usage = 3500,那么已用 35 美元,剩余 65 美元。
const base = 'https://api.openpalmlab.com';const headers = { Authorization: `Bearer ${process.env.OPENPALMLAB_API_KEY}` };
const sub = await fetch(`${base}/v1/dashboard/billing/subscription`, { headers }).then((r) => r.json());const usage = await fetch(`${base}/v1/dashboard/billing/usage`, { headers }).then((r) => r.json());
const total = sub.soft_limit_usd ?? sub.hard_limit_usd;const used = (usage.total_usage ?? 0) / 100;const unlimited = total >= 1e8;
console.log({ used, remaining: unlimited ? null : +(total - used).toFixed(4), unlimitedToken: unlimited, expiresAt: sub.access_until ? new Date(sub.access_until * 1000).toISOString() : 'never',});余额低于设定的阈值时,网关会发送提醒,通知方式可以在控制台的 个人设置 里配置。