> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crazyrouter.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 新增令牌

> 创建新的 API 令牌

> 更新日期：2026-06-06

## 接口说明

创建一个新的 API 令牌（Token），用于调用 AI 模型 API。

<Note>
  这组 `/api/token/*` 接口主要用于 Crazyrouter 控制台中的 API Key 管理自动化。它们需要用户 `access token` 与 `New-Api-User` 请求头，不是给普通 `sk-xxx` 模型调用流程直接使用的接口。
</Note>

## 认证方式

该接口需要用户侧认证：

```text theme={null}
Authorization: Bearer your_access_token
New-Api-User: 1
```

## 请求参数

<ParamField body="name" type="string" required>
  令牌名称，便于识别用途
</ParamField>

<ParamField body="remain_quota" type="integer" default="0">
  初始额度（单位：内部额度值）。设置为 0 时需配合 `unlimited_quota` 使用
</ParamField>

<ParamField body="unlimited_quota" type="boolean" default="false">
  是否设为无限额度
</ParamField>

<ParamField body="expired_time" type="integer" default="-1">
  过期时间（Unix 时间戳），`-1` 表示永不过期
</ParamField>

<ParamField body="model_limits_enabled" type="boolean" default="false">
  是否启用模型白名单限制
</ParamField>

<ParamField body="model_limits" type="string">
  模型限制配置，当前接口字段是字符串，通常保存为 JSON 字符串，例如 `["gpt-5.5","claude-opus-4-8"]`
</ParamField>

<ParamField body="allow_ips" type="string">
  IP 白名单字符串。可填写单个 IP，或用换行分隔多个 IP
</ParamField>

<ParamField body="group" type="string">
  令牌所属分组。只有当前用户有权使用的分组才可设置
</ParamField>

## 响应格式

当前接口创建成功后仅返回成功状态：

```json theme={null}
{
  "success": true,
  "message": ""
}
```

## 代码示例

<CodeGroup>
  ```python Python theme={null}
  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://api.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.5", "claude-opus-4-8"]),
          "allow_ips": "203.0.113.10"
      }
  )

  print(response.json())
  ```

  ```bash cURL theme={null}
  curl -X POST https://api.crazyrouter.com/api/token/ \
    -H "Authorization: Bearer your_access_token" \
    -H "New-Api-User: 1" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "生产环境",
      "remain_quota": 100000,
      "expired_time": -1,
      "model_limits_enabled": true,
      "model_limits": "[\"gpt-5.5\"]"
    }'
  ```
</CodeGroup>

<Warning>
  当前创建接口不会在响应中返回新生成的完整 `key`。如果你的流程要求立即复制完整密钥，请优先通过控制台页面创建并保存。
</Warning>
