跳转到主要内容
POST
/
api
/
token
curl https://api.cometapi.com/api/token/ \
  -H "Authorization: your-access-token" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "production",
    "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": ""
}

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。
Console → Personal Settings 生成个人访问令牌,然后将其作为原始 Authorization 请求头值发送。不要添加 Bearer 前缀。
创建响应仅确认操作成功,不包含新 key 的记录或 key 值。创建后,请调用 列出 API key 以读取最新的 key 记录。

请求体

FieldTypeDescription
namestringkey 的用户可读显示名称。必须不超过 50 个字符。
expired_timeintegerkey 过期的 Unix 时间戳(秒)。使用 -1 表示永不过期。
remain_quotainteger以 CometAPI 内部配额单位表示的初始配额。如果该值达到 0unlimited_quotafalse,则使用此 key 发起的模型请求会因配额耗尽而被拒绝。
unlimited_quotaboolean该 key 是否绕过剩余配额检查。仅当希望该 key 在 remain_quota0 时仍可继续工作时,才设置为 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
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"

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

Starting quota for the new 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

Create result.

success
boolean
必填

Whether the create operation succeeded.

示例:

true

message
string
必填

Backend status message. The value is usually an empty string on success.

示例:

""