跳转到主要内容
GET
/
api
/
token
获取令牌列表
curl --request GET \
  --url https://api.example.com/api/token/

接口说明

获取当前用户创建的所有 API 令牌(Token),支持分页。
这组 /api/token/* 接口主要用于 Crazyrouter 控制台中的 API Key 管理自动化。它们需要用户 access tokenNew-Api-User 请求头,不是给普通 sk-xxx 模型调用流程直接使用的接口。

认证方式

使用用户的 Access Token 进行认证,需要在请求头中携带:
Authorization: Bearer {access_token}
New-Api-User: {user_id}

请求参数

p
integer
默认值:"1"
页码。代码兼容旧写法,但建议从 1 开始
size
integer
默认值:"10"
每页数量,最大 100

响应格式

{
  "success": true,
  "message": "",
  "data": {
    "page": 1,
    "page_size": 10,
    "total": 1,
    "items": [
      {
        "id": 1,
        "user_id": 1,
        "key": "sk-xxxxxxxxxxxxxxxx",
        "status": 1,
        "name": "我的令牌",
        "created_time": 1706000000,
        "accessed_time": 1706100000,
        "expired_time": -1,
        "remain_quota": 500000,
        "unlimited_quota": false,
        "model_limits_enabled": true,
        "model_limits": "[\"gpt-5.4\",\"claude-sonnet-4-6\"]",
        "allow_ips": "203.0.113.10",
        "used_quota": 12345,
        "group": "default"
      }
    ]
  }
}

字段说明

字段类型说明
idint令牌 ID
keystringAPI Key(sk-xxx 格式)
statusint状态:1=启用,2=禁用
namestring令牌名称
expired_timeint过期时间戳,-1 表示永不过期
remain_quotaint剩余额度
unlimited_quotabool是否无限额度
used_quotaint已使用额度
model_limits_enabledbool是否启用模型白名单
model_limitsstring模型限制配置字符串
allow_ipsstringIP 白名单字符串
groupstring分组

代码示例

import requests

headers = {
    "Authorization": "Bearer your_access_token",
    "New-Api-User": "1",
    "User-Agent": "Mozilla/5.0"
}

response = requests.get(
    "https://crazyrouter.com/api/token/?p=1&size=100",
    headers=headers
)

page = response.json()["data"]
for token in page["items"]:
    print(f"[{token['name']}] {token['key'][:10]}... 额度: {token['remain_quota']}")