更新成员 API Key

PATCH/enterprise/v1/sub-accounts/{subAccountId}/api-keys/{hash}

即使只改预算也必须传 status:ACTIVE 或 DISABLED。name 可选。allowedIps 省略/null 保持原值,[] 清除限制。spendLimitPresent=true 才应用 spendLimit,含 null(清除限额);limitResetPresent=true 才应用 limitReset,含 null(累计)。不传标志不会更新预算字段。限额单位美元,不会增加账户资金。

身份验证

MANAGEMENT / PROVISIONING Key;tenant:keys:write

Authorization: Bearer <CONTROL_KEY>

路径中的 subAccountId 必须属于当前企业;hash 是 Key 元数据标识,不能传明文密钥。

审批与重试

启用审批的企业需传 Idempotency-Key,可能返回 HTTP 409 / APPROVAL_REQUIRED,data.operation.executed=false;此时尚未执行,不应当作成功。未启用审批时直接执行;不要假设任意 POST 都支持幂等重试。

审批与重试指南

路径参数

subAccountIdstringrequired

10-digit public member ID / 10 位成员编号

hashstringrequired

Public key hash / 公开 Key hash

请求体

statusstringrequired

ACTIVE | DISABLED

namestring

Key name / Key 名称

allowedIpsstring[] | null

null keeps current; [] clears / null 保持;[] 清空

spendLimitnumber | null

USD > 0; null clears with presence flag / 美元正数,配合标志可传 null 清除

spendLimitPresentboolean

true applies spendLimit / true 才应用 spendLimit

limitResetstring | null

daily | weekly | monthly | null

limitResetPresentboolean

true applies limitReset / true 才应用 limitReset

字段使用 camelCase。必填项及可选字段见上文。

JSON
1{
2  "status": "ACTIVE",
3  "spendLimit": 100,
4  "spendLimitPresent": true,
5  "limitReset": "monthly",
6  "limitResetPresent": true
7}

响应

HTTP 200; code: 200. 以下为示例值,字段使用 camelCase。

codeinteger

200

dataobject | null
data.hashstring
data.namestring
data.keyDisplaystring
data.workspaceCodestring
data.statusstring
data.allowedIpsarray
data.spendLimitnumber
data.limitResetstring
data.expiresAtstring | null
data.createdAtstring

错误处理

检查 HTTP 状态和 code,失败时读取 serviceCode、msg、traceId。无效凭证无法读取数据;缺少 scope 返回 API_KEY_SCOPE_DENIED。跨企业资源不可访问。不要把 202 接受或审批待处理当作业务完成。

请求

Shell
1curl -X PATCH "https://api.token360.ai/enterprise/v1/sub-accounts/{subAccountId}/api-keys/{hash}" \
2  -H "Authorization: Bearer $CONTROL_KEY" \
3  -H "Idempotency-Key: <UNIQUE_INTENT_ID>" \
4  -H "Content-Type: application/json" \
5  --data '{"status": "ACTIVE", "spendLimit": 100, "spendLimitPresent": true, "limitReset": "monthly", "limitResetPresent": true}'

响应

JSON
1{
2  "code": 200,
3  "msg": "success",
4  "data": {
5    "hash": "<KEY_HASH>",
6    "name": "service-key",
7    "keyDisplay": "sk-…",
8    "workspaceCode": "DEFAULT",
9    "status": "ACTIVE",
10    "allowedIps": [],
11    "spendLimit": 100,
12    "limitReset": "monthly",
13    "expiresAt": null,
14    "createdAt": "2026-11-03T00:00:00Z"
15  }
16}
此页面对您有帮助吗?
更新成员 API Key · Token360