跳转到主要内容
PUT
/
api
/
token
curl -X PUT https://api.cometapi.com/api/token/ \ -H "Authorization: your-access-token" \ -H "Content-Type: application/json" \ -d '{ "id": 1234, "name": "production-renamed", "status": 1, "expired_time": -1, "remain_quota": 100000, "unlimited_quota": false, "model_limits_enabled": false, "model_limits": "", "allow_ips": null, "group": "", "cross_group_retry": false }'
{ "success": true, "message": "", "data": { "id": 1234, "user_id": 5678, "key": "<COMETAPI_KEY>", "status": 1, "name": "production-renamed", "created_time": 1766102400, "accessed_time": 1766102400, "expired_time": -1, "remain_quota": 100000, "unlimited_quota": false, "model_limits_enabled": false, "model_limits": "", "allow_ips": null, "used_quota": 0, "group": "", "cross_group_retry": false } }

Documentation Index

Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt

Use this file to discover all available pages before exploring further.

使用此端点更新 API key 的名称、状态、额度、过期时间、模型限制、IP 允许列表以及分组设置。
Console → Personal Settings 生成个人访问令牌,然后将其作为原始 Authorization 请求头值发送。不要添加 Bearer 前缀。
此端点使用 PUT /api/token/,并且 id 应放在 JSON 请求体中。请发送你希望保留的可编辑字段;更新时省略的数值、布尔值或字符串字段可能会被重置。

请求体

字段类型说明
idinteger必填。由列出 API key返回的 API key ID。
namestring用户可读的 key 显示名称。长度必须不超过 50 个字符。
statusinteger运行状态。1 表示启用该 key 用于模型请求。2 表示禁用。3 表示已过期。4 表示额度已用尽。被禁用、已过期或额度耗尽的 key 会被模型端点拒绝。
expired_timeintegerkey 过期的 Unix 秒级时间戳。使用 -1 表示永不过期。过去的时间戳会阻止模型请求。
remain_quotaintegerCometAPI 内部额度单位中的剩余额度。如果该值达到 0unlimited_quotafalse,则使用此 key 的模型请求会因额度耗尽而被拒绝。
unlimited_quotaboolean该 key 是否绕过剩余额度检查。仅当即使 remain_quota0,该 key 也应继续可用时,才设置为 true
model_limits_enabledboolean是否将此 key 限制为仅可使用特定模型。当为 false 时,将忽略 model_limits
model_limitsstringmodel_limits_enabledtrue 时,此 key 允许使用的、以逗号分隔的 model ID。请使用 /v1/models 返回的 model ID;使用空字符串表示不限制模型。
allow_ipsstring or null可选的 IP 允许列表。提供一个 JSON 字符串,并使用换行符(\n)分隔各条目。每个条目可以是单个 IPv4 地址、单个 IPv6 地址、IPv4 CIDR 或 IPv6 CIDR。使用 null"" 可禁用 IP 限制。
groupstring可选的账户分组限制。使用空字符串表示不显式指定分组。非空值必须是该账户可用的分组,否则 API 会返回 success: false
cross_group_retryboolean是否启用跨分组重试以进行自动分组路由。仅当该 key 使用自动路由分组时,此项才有意义。

允许列表格式

要允许多个 IP 或 CIDR 范围,请将它们作为一个 JSON 字符串发送,并在条目之间使用 \n 分隔:
{
  "allow_ips": "198.51.100.10\n203.0.113.0/24\n2001:db8::/32"
}
此示例允许一个 IPv4 地址、一个 IPv4 CIDR 范围和一个 IPv6 CIDR 范围。

授权

Authorization
string
header
必填

Personal access token copied from CometAPI Console > Personal Settings. Send the raw token value; do not prefix it with Bearer.

请求体

application/json
id
integer
必填

Numeric API key ID returned by the list endpoint. For updates, send this value in the JSON body, not in the URL.

示例:

1234

name
string

User-readable display name for the API key. The backend accepts up to 50 Unicode characters; longer names return success: false with token name is too long.

Maximum string length: 50
示例:

"production"

status
enum<integer>

Operational status for the key. 1 enables the key for model requests, 2 disables it, 3 marks it expired, and 4 marks it quota exhausted. Disabled, expired, or exhausted keys are rejected by model endpoints.

可用选项:
1,
2,
3,
4
示例:

1

expired_time
integer

Unix timestamp in seconds when the key expires. Use -1 for no expiration. A past timestamp blocks model requests with this key.

示例:

-1

remain_quota
integer

Remaining quota to assign to the key in CometAPI internal quota units. If this reaches 0 while unlimited_quota is false, model requests with this key are rejected as quota exhausted.

示例:

100000

unlimited_quota
boolean

Whether the key bypasses remaining-quota checks. Set true only when the key should keep working even if remain_quota is 0.

示例:

false

model_limits_enabled
boolean

Whether to restrict this key to specific models. When true, only model IDs listed in model_limits are allowed. When false, model_limits is ignored.

示例:

false

model_limits
string

Comma-separated model IDs allowed by this key when model_limits_enabled is true. Use model IDs returned by /v1/models, for example <model-id-1>,<model-id-2>. Use an empty string for no model restriction.

示例:

""

allow_ips
string | null

Optional IP allowlist. Provide one JSON string with entries separated by newline characters (\n). Each entry can be a single IPv4 address, single IPv6 address, IPv4 CIDR, or IPv6 CIDR. Example for three allowlist entries: 198.51.100.10\n203.0.113.0/24\n2001:db8::/32. CometAPI compares the model request client IP to this list. Use null or "" to disable IP restrictions.

示例:

"198.51.100.10\n203.0.113.0/24\n2001:db8::/32"

group
string

Optional account group restriction. Use an empty string for no explicit group restriction. Non-empty values must be available to the account, or the API returns success: false with a no access to group message.

示例:

""

cross_group_retry
boolean

Whether cross-group retry is enabled for automatic group routing. This is only meaningful when the key uses an auto-routed group such as auto.

示例:

false

响应

200 - application/json

Updated API key record.

success
boolean
必填
message
string
必填
data
object
必填