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

接口说明

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

认证方式

该接口需要用户侧认证:
Authorization: Bearer your_access_token
New-Api-User: 1

请求参数

name
string
必填
令牌名称,便于识别用途
remain_quota
integer
默认值:"0"
初始额度(单位:内部额度值)。设置为 0 时需配合 unlimited_quota 使用
unlimited_quota
boolean
默认值:"false"
是否设为无限额度
expired_time
integer
默认值:"-1"
过期时间(Unix 时间戳),-1 表示永不过期
model_limits_enabled
boolean
默认值:"false"
是否启用模型白名单限制
model_limits
string
模型限制配置,当前接口字段是字符串,通常保存为 JSON 字符串,例如 ["gpt-5.4","claude-sonnet-4-6"]
allow_ips
string
IP 白名单字符串。可填写单个 IP,或用换行分隔多个 IP
group
string
令牌所属分组。只有当前用户有权使用的分组才可设置

响应格式

当前接口创建成功后仅返回成功状态:
{
  "success": true,
  "message": ""
}

代码示例

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.post(
    "https://crazyrouter.com/api/token/",
    headers=headers,
    json={
        "name": "生产环境",
        "remain_quota": 100000,
        "unlimited_quota": False,
        "expired_time": -1,
        "model_limits_enabled": True,
        "model_limits": json.dumps(["gpt-5.4", "claude-sonnet-4-6"]),
        "allow_ips": "203.0.113.10"
    }
)

print(response.json())
当前创建接口不会在响应中返回新生成的完整 key。如果你的流程要求立即复制完整密钥,请优先通过控制台页面创建并保存。