令牌用量查询
GET v1/api/usage/token通过认证查询当前 Bearer Token 的额度使用情况:授予总量、已用、剩余、是否无限、模型限额及到期时间。 字段说明(data) object: 固定为 token_usage name: 令牌名称 total_granted: 授予总量(= 已用 + 剩余) total_used: 已使用额度 total_available: 可用剩余额度 unlimited_quota: 是否为无限额度 model_limits: 允许使用的模型列表 model_limits_enabled: 是否启用模型限额 expires_at: 到期时间的 Unix 时间戳(秒)。若永不过期返回 0(由后端将 -1 归一化为 0)
请求参数
Authorization
在 Header 添加参数 Authorization,其值为在 Bearer 之后拼接 Token。
Authorization: Bearer ********************返回响应
200 成功
Content-Type: application/json
响应参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| data | array[object] | 必需 | 模型列表数据 |
| └─id | string | 必需 | 模型 ID |
| └─object | string | 必需 | 对象类型 |
| └─created | integer | 必需 | 创建时间戳 |
| └─owned_by | string | 必需 | 所有者 |
| └─supported_endpoint_types | array[string] | 必需 | 支持的端点类型 |
| object | string | 必需 | 顶层对象类型 |
| success | boolean | 必需 | 是否成功 |
响应示例
{
"data": [
{
"id": "model-id-0",
"object": "model",
"owned_by": "organization-owner",
"permission": []
},
{
"id": "model-id-1",
"object": "model",
"owned_by": "organization-owner",
"permission": []
},
{
"id": "model-id-2",
"object": "model",
"owned_by": "openai",
"permission": []
}
],
"object": "list"
}示例代码
python
import http.client
conn = http.client.HTTPSConnection("nxaiapp.com")
payload = ''
headers = {
'Authorization': 'Bearer <token>'
}
conn.request("GET", "/v1/api/usage/token", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))