跳转到主要内容
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>"
}
'
import requests

url = "https://api.example.com/api/token/"

payload = {
"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>"
}
headers = {"Content-Type": "application/json"}

response = requests.put(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
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>'
})
};

fetch('https://api.example.com/api/token/', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/token/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'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>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.example.com/api/token/"

payload := strings.NewReader("{\n \"id\": 123,\n \"name\": \"<string>\",\n \"remain_quota\": 123,\n \"unlimited_quota\": true,\n \"expired_time\": 123,\n \"model_limits_enabled\": true,\n \"model_limits\": \"<string>\",\n \"status\": 123,\n \"allow_ips\": \"<string>\",\n \"group\": \"<string>\"\n}")

req, _ := http.NewRequest("PUT", url, payload)

req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.put("https://api.example.com/api/token/")
.header("Content-Type", "application/json")
.body("{\n \"id\": 123,\n \"name\": \"<string>\",\n \"remain_quota\": 123,\n \"unlimited_quota\": true,\n \"expired_time\": 123,\n \"model_limits_enabled\": true,\n \"model_limits\": \"<string>\",\n \"status\": 123,\n \"allow_ips\": \"<string>\",\n \"group\": \"<string>\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.example.com/api/token/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": 123,\n \"name\": \"<string>\",\n \"remain_quota\": 123,\n \"unlimited_quota\": true,\n \"expired_time\": 123,\n \"model_limits_enabled\": true,\n \"model_limits\": \"<string>\",\n \"status\": 123,\n \"allow_ips\": \"<string>\",\n \"group\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
更新日期:2026-06-06

接口说明

修改已有令牌的名称、额度、过期时间、模型权限等配置。
这组 /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.5","claude-opus-4-8"]
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.5\",\"claude-opus-4-8\"]",
    "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://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())
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\"]"
  }'
修改令牌不会重新生成 API Key。如需更换 Key,请删除后重新创建。