跳转到主要内容
PUT
/
api
/
token
修改令牌
curl --request PUT \
  --url https://api.example.com/api/token/ \
  --header 'Content-Type: application/json' \
  --data '
{
  "id": 123,
  "name": "<string>",
  "remain_quota": 123,
  "unlimited_quota": true,
  "expired_time": 123,
  "model_limits_enabled": true,
  "model_limits": "<string>",
  "status": 123,
  "allow_ips": "<string>",
  "group": "<string>"
}
'

接口说明

修改已有令牌的名称、额度、过期时间、模型权限等配置。
这组 /api/token/* 接口主要用于 Crazyrouter 控制台中的 API Key 管理自动化。它们需要用户 access tokenNew-Api-User 请求头,不是给普通 sk-xxx 模型调用流程直接使用的接口。

认证方式

使用用户侧认证,请在请求头中携带:
Authorization: Bearer your_access_token
New-Api-User: 1

请求参数

id
integer
必填
令牌 ID
name
string
令牌名称
remain_quota
integer
剩余额度
unlimited_quota
boolean
是否无限额度
expired_time
integer
过期时间戳,-1 为永不过期
model_limits_enabled
boolean
是否启用模型白名单
model_limits
string
模型限制配置字符串,例如 ["gpt-5.4","claude-sonnet-4-6"]
status
integer
状态:1=启用,2=禁用
allow_ips
string
IP 白名单字符串
group
string
分组

响应格式

当前接口会返回更新后的 token 对象:
{
  "success": true,
  "message": "",
  "data": {
    "id": 10,
    "name": "生产环境-已更新",
    "status": 1,
    "remain_quota": 200000,
    "unlimited_quota": false,
    "model_limits_enabled": true,
    "model_limits": "[\"gpt-5.4\",\"claude-sonnet-4-6\"]",
    "allow_ips": "203.0.113.10",
    "group": "default"
  }
}

代码示例

import json
import requests

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

response = requests.put(
    "https://crazyrouter.com/api/token/",
    headers=headers,
    json={
        "id": 10,
        "name": "生产环境-已更新",
        "remain_quota": 200000,
        "model_limits_enabled": True,
        "model_limits": json.dumps(["gpt-5.4", "claude-sonnet-4-6"])
    }
)

print(response.json())
修改令牌不会重新生成 API Key。如需更换 Key,请删除后重新创建。