查询令牌余额
- 按 Key 维度查询剩余额度
- 走 /api/token/{id} 管理接口
- unlimited_quota 为真时只看账户余额
认证
账户相关接口走 New-API 的管理通道,需要系统访问令牌,与调用模型的 API Key 不是一回事。在控制台「个人设置 → 安全设置 → 系统访问令牌」生成,请求头写成 Authorization: Bearer YOUR_ACCESS_TOKEN。
当前登录用户的 ID。值必须与令牌所属用户一致,否则返回 401。
Account endpoints use New API's management channel and need a system access token, which is not the same as a model API key. Create one under Settings → Security → System access tokens and send it as Authorization: Bearer YOUR_ACCESS_TOKEN.
The signed-in user's ID. It must match the token's owner or the request returns 401.
路径与查询参数
先列出自己的 Key 拿到 id,再按 id 查具体额度。
路径参数,Key 的 ID。可从 GET /api/token/ 的返回里取。
列表接口的模糊搜索,按名称过滤 Key。
列表接口的页码,从 1 开始。
列表接口的每页条数,上限 100。
List your keys to get an id, then query that id for its quota.
Path parameter: the key's ID, available from GET /api/token/.
Fuzzy search on the list endpoint, filtering keys by name.
List page number, starting at 1.
List page size, capped at 100.
响应
返回 Key 对象,额度字段有三个:
{
"success": true,
"message": "",
"data": {
"id": 12,
"user_id": 1,
"name": "prod-key",
"key": "sk-abcd...wxyz",
"status": 1,
"remain_quota": 1500000,
"unlimited_quota": false,
"used_quota": 500000,
"expired_time": -1,
"model_limits_enabled": false,
"model_limits": "",
"group": "default"
}
}data.remain_quota(integer) — 该 Key 的剩余额度。data.unlimited_quota(boolean) — 为true时忽略remain_quota,只受账户余额约束。data.used_quota(integer) — 该 Key 的累计已用额度。data.expired_time(integer) — 过期时间戳,-1表示永不过期。data.model_limits_enabled/model_limits— 模型白名单开关与清单。data.status(integer) —1启用,2禁用。
quota 的换算比例由实例配置决定,New-API 默认 500000 额度 = 1 美元。展示时用 quota / 500000 得到美元,具体数值以你所在实例的配置为准。
Returns the key object; three fields carry quota:
{
"success": true,
"message": "",
"data": {
"id": 12,
"user_id": 1,
"name": "prod-key",
"key": "sk-abcd...wxyz",
"status": 1,
"remain_quota": 1500000,
"unlimited_quota": false,
"used_quota": 500000,
"expired_time": -1,
"model_limits_enabled": false,
"model_limits": "",
"group": "default"
}
}data.remain_quota(integer) — remaining quota for this key.data.unlimited_quota(boolean) — whentrue,remain_quotais ignored and only the account balance binds.data.used_quota(integer) — cumulative usage on this key.data.expired_time(integer) — expiry timestamp;-1means never.data.model_limits_enabled/model_limits— the model allowlist switch and list.data.status(integer) —1enabled,2disabled.
The quota scale is instance-configured; New API defaults to 500000 quota per US dollar, so divide by 500000 for dollars. Check your own instance's setting.
说明
额度分为三层:
| 层级 | 含义 |
|---|---|
| 账户余额 | 整个账号的总余额,/api/user/self 的 quota |
| Key 额度 | 单个 Key 的上限,本接口的 remain_quota |
| 单次请求成本 | 按 token 用量或按次扣费 |
本接口返回的是 Key 这一层。要看账户层,用查询用户余额。
额度是实时扣减的。并发请求较多时,两次查询之间可能出现较小偏差,这不代表计费错误。
Quota lives on three levels:
| Level | Meaning |
|---|---|
| Account balance | The whole account's balance: quota from /api/user/self |
| Key quota | The per-key cap: remain_quota on this endpoint |
| Per-request cost | Charged by token usage or per image |
This endpoint reports the key level. For the account level, see Get user balance.
Quota is deducted in real time. Under concurrency, two reads may differ slightly; that isn't a billing error.
错误码
| HTTP | 含义 |
|---|---|
| 200 | 请求成功。Key 不存在时 success 为 false |
| 401 | 令牌缺失、无效,或 New-Api-User 与令牌归属不一致 |
| 403 | 该 Key 不属于当前用户 |
| HTTP | Meaning |
|---|---|
| 200 | Success. A missing key returns success: false |
| 401 | Token missing or invalid, or New-Api-User doesn't match the token owner |
| 403 | The key doesn't belong to the current user |
For more status codes and retry guidance see Error codes and rate limits; for troubleshooting see the FAQ.
使用示例
列出全部 Key
先拿到 id,再逐个查额度。列表接口本身也带 remain_quota,Key 不多时可以一次拿完。
查询单个 Key 的额度
适合做客户端余额预警:拿当前 Key 的 id 查 remain_quota。
在本地算剩余额度
unlimited_quota 为 true 时不要用 remain_quota 做判断,改用账户余额。
List every key
Get the id first, then query each one. The list response also carries remain_quota, so with few keys one call is enough.
Check one key
Good for client-side low-balance warnings: look up remain_quota for the current key's id.
Computing the remainder locally
When unlimited_quota is true, don't judge by remain_quota; use the account balance instead.