> ## 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.

# 修改令牌

> 更新已有令牌的配置

> 更新日期：2026-06-06

## 接口说明

修改已有令牌的名称、额度、过期时间、模型权限等配置。

<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="id" type="integer" required>
  令牌 ID
</ParamField>

<ParamField body="name" type="string">
  令牌名称
</ParamField>

<ParamField body="remain_quota" type="integer">
  剩余额度
</ParamField>

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

<ParamField body="expired_time" type="integer">
  过期时间戳，`-1` 为永不过期
</ParamField>

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

<ParamField body="model_limits" type="string">
  模型限制配置字符串，例如 `["gpt-5.5","claude-opus-4-8"]`
</ParamField>

<ParamField body="status" type="integer">
  状态：1=启用，2=禁用
</ParamField>

<ParamField body="allow_ips" type="string">
  IP 白名单字符串
</ParamField>

<ParamField body="group" type="string">
  分组
</ParamField>

## 响应格式

当前接口会返回更新后的 token 对象：

```json theme={null}
{
  "success": true,
  "message": "",
  "data": {
    "id": 10,
    "name": "生产环境-已更新",
    "status": 1,
    "remain_quota": 200000,
    "unlimited_quota": false,
    "model_limits_enabled": true,
    "model_limits": "[\"gpt-5.5\",\"claude-opus-4-8\"]",
    "allow_ips": "203.0.113.10",
    "group": "default"
  }
}
```

## 代码示例

<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.put(
      "https://api.crazyrouter.com/api/token/",
      headers=headers,
      json={
          "id": 10,
          "name": "生产环境-已更新",
          "remain_quota": 200000,
          "model_limits_enabled": True,
          "model_limits": json.dumps(["gpt-5.5", "claude-opus-4-8"])
      }
  )

  print(response.json())
  ```

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

<Warning>
  修改令牌不会重新生成 API Key。如需更换 Key，请删除后重新创建。
</Warning>
