查询 API Key 用量
接口路径
http
GET /api/open/usage/token认证方式
无 Query / Path / Body 参数。Token 通过 Authorization header 获取。
配额计算说明
用量相关字段为内部额度单位,换算成金额(人民币)的方式:
金额(¥) = quota ÷ quota_per_unit × usd_exchange_rate其中:
quota:按下文「字段使用逻辑」选定展示口径后,取对应字段,例如个人/成员用total_available/total_used/total_granted;业务 Key 用monthly_quota_limit/current_month_usedquota_per_unit、usd_exchange_rate、quota_display_type:来自 查询换算参数 接口(GET /api/open/status)
若 quota_display_type = USD(美元),则去掉 × usd_exchange_rate。
当展示「无限额度」时(unlimited_quota = true 或 monthly_unlimited = true),不必换算剩余金额。
请求示例
JSON
GET 'https://neolink.com/backend/api/open/usage/token/'
Authorization: Bearer sk-<apikey>返回信息
| 字段 | 类型 | 是否必传 | 说明 | 备注 |
|---|---|---|---|---|
| code | bool | 是 | 请求是否成功 | 成功时 true;失败时 false |
| message | string | 是 | 状态消息 | 成功时为 "ok";失败时为错误说明 |
| data | UsageInfo | 否 | Token 使用统计对象 | 仅成功时返回 |
UsageInfo 对象
| 字段 | 类型 | 是否必传 | 说明 | 备注 |
|---|---|---|---|---|
| object | string | 是 | 对象类型 | 固定值 "token_usage" |
| name | string | 是 | Key 名称 | |
| busi_type | int | 是 | 业务类型 | 0=个人 / 1=成员 / 2=业务级;先读它,再选展示口径 |
| remain_quota | int | 是 | 令牌剩余额度(库原值) | 可能为负;展示优先用 total_available;换算见上文「配额计算说明」 |
| total_available | int64 | 是 | 令牌剩余(分子) | max(0, remain_quota);令牌无限时为 0;仅令牌口径;换算见上文「配额计算说明」 |
| total_granted | int64 | 是 | 令牌总额(分母) | total_available + total_used;令牌无限时为 0;仅令牌口径;换算见上文「配额计算说明」 |
| total_used | int64 | 是 | 已使用的总配额 | 仅令牌口径;换算见上文「配额计算说明」 |
| unlimited_quota | bool | 是 | 令牌是否无限(库字段) | 业务 Key 创建时常为 true,不能表示月度无限 |
| monthly_quota_limit | int64 | 是 | 月度限额原值 | -1=不限 / 0=禁止 / >0=上限;仅业务 Key 主用 |
| current_month_used | int64 | 是 | 本月已用原值 | 仅业务 Key 主用 |
| monthly_unlimited | bool | 是 | 月度是否无限 | 等价于 monthly_quota_limit < 0 |
| model_limits_enabled | bool | 是 | 是否启用模型白名单 | |
| model_limits | object | 是 | 模型限制映射 | |
| expires_at | int64 | 是 | 过期时间 | Unix 秒级时间戳;0=永不过期 |
字段使用逻辑(对接伪代码)
先读 busi_type
if busi_type == 2: # 业务级 → 只用月度字段
if monthly_unlimited: # monthly_quota_limit < 0
显示「无限额度」
可选:已用 = current_month_used
else if monthly_quota_limit == 0:
显示 剩余0 / 总额0(禁止调用)
else:
分母 = monthly_quota_limit # 总额度
分子 = max(0, monthly_quota_limit - current_month_used) # 剩余额度
显示 分子 / 分母
else: # 个人/成员 → 只用令牌字段
if unlimited_quota:
显示「无限额度」
可选:已用 = total_used
else:
分子 = total_available # 剩余额度
分母 = total_granted # 总额度
显示 分子 / 分母返回示例
JSON
成功响应(个人/成员 Key,有限额,busi_type=0 或 1)
{
"code": true,
"message": "ok",
"data": {
"object": "token_usage",
"name": "我的Key",
"busi_type": 1,
"remain_quota": 400,
"total_available": 400,
"total_granted": 500,
"total_used": 100,
"unlimited_quota": false,
"monthly_quota_limit": -1,
"current_month_used": 0,
"monthly_unlimited": true,
"model_limits": {},
"model_limits_enabled": false,
"expires_at": 0
}
}
成功响应(个人/成员 Key,令牌无限)
{
"code": true,
"message": "ok",
"data": {
"object": "token_usage",
"name": "我的Key",
"busi_type": 0,
"remain_quota": 0,
"total_available": 0,
"total_granted": 0,
"total_used": 12345,
"unlimited_quota": true,
"monthly_quota_limit": -1,
"current_month_used": 0,
"monthly_unlimited": true,
"model_limits": {},
"model_limits_enabled": false,
"expires_at": 0
}
}
成功响应(业务 Key,有月限额,busi_type=2)
{
"code": true,
"message": "ok",
"data": {
"object": "token_usage",
"name": "业务Key",
"busi_type": 2,
"remain_quota": 0,
"total_available": 0,
"total_granted": 0,
"total_used": 20545,
"unlimited_quota": true,
"monthly_quota_limit": 357143,
"current_month_used": 20545,
"monthly_unlimited": false,
"model_limits": {},
"model_limits_enabled": false,
"expires_at": 0
}
}
成功响应(业务 Key,月度无限)
{
"code": true,
"message": "ok",
"data": {
"object": "token_usage",
"name": "业务Key",
"busi_type": 2,
"remain_quota": 0,
"total_available": 0,
"total_granted": 0,
"total_used": 100,
"unlimited_quota": true,
"monthly_quota_limit": -1,
"current_month_used": 100,
"monthly_unlimited": true,
"model_limits": {},
"model_limits_enabled": false,
"expires_at": 0
}
}
成功响应(业务 Key,月限额为 0,禁止)
{
"code": true,
"message": "ok",
"data": {
"object": "token_usage",
"name": "业务Key",
"busi_type": 2,
"remain_quota": 0,
"total_available": 0,
"total_granted": 0,
"total_used": 50,
"unlimited_quota": true,
"monthly_quota_limit": 0,
"current_month_used": 50,
"monthly_unlimited": false,
"model_limits": {},
"model_limits_enabled": false,
"expires_at": 0
}
}
错误响应
{
"code": false,
"message": "No Authorization header"
}
{
"code": false,
"message": "token not found"
}