管理
更新 API Key
更新目前組織中的既有使用者 API Key。
PATCHhttps://api.tokenlab.sh/v1/management/api-keys/{keyId}
概覽
這個 endpoint 可更新既有 API Key 的名稱、額度、模型白名單、過期時間或狀態。
請求主體
PATCH 請求至少需要提供一個欄位。
| 欄位 | 型別 | 預設值 / 限制 | 說明 |
|---|---|---|---|
status | enum | - | active, inactive, revoked |
name | string | 長度 1-50 | 更新後的顯示名稱 |
limitAmount | number | string | null | 0–100000 USD | null 表示不設限,0 表示無法產生費用。十進位字串最多支援 6 位小數。 |
limitCurrency | 列舉 | 預設 USD | 僅限 USD。傳送 CNY 會回傳 400 currency_retired。 設定時必須同時提供 limitAmount。 |
models | string[] | - | 更新後的模型白名單 |
deliveryPolicy | string | null | auto, verified, official, null | null 表示繼承工作區交付策略。 |
expiresAt | string | null | RFC3339 datetime | null 表示移除過期時間 |
說明
-
金額欄位僅支援 USD。
CNY輸入已停用,並會回傳400 currency_retired。 -
Management API v1 故意不支援硬刪除。
-
revoked通常視為終態;若需要重新使用,通常建議直接建立一把新的 Key。
請求
curl -X PATCH "https://api.tokenlab.sh/v1/management/api-keys/key_abc123def456" \
-H "Authorization: Bearer mt-your-management-token" \
-H "Content-Type: application/json" \
-d '{
"status": "inactive",
"limitAmount": 0
}'請求 / 回應
本頁提供 OpenAPI 結構說明及可複製的請求範例。請在終端機或用戶端使用 Management Token 傳送管理請求;本頁不提供直接傳送功能。
回應
{
"id": "key_abc123def456",
"name": "Backend Worker",
"key_prefix": "sk-live...",
"status": "inactive",
"limit_amount": 0,
"limit_amount_decimal": "0",
"used_amount": 148.25,
"used_amount_decimal": "148.25",
"models": [
"gpt-5.6-luna",
"claude-3-7-sonnet"
],
"expires_at": "2026-12-31T23:59:59.000Z",
"last_used_at": "2026-07-08T03:12:45.000Z",
"created_at": "2026-07-01T10:00:00.000Z",
"delivery_policy": null
}重要欄位
idstring
用於後續管理 API 呼叫的 API Key 識別碼。
namestring
API Key 的顯示名稱。
key_prefixstring
用於顯示和支援排查的非敏感 Key 前綴。
statusstring
值為
active、inactive、suspended 或 revoked。limit_amountnumber | null
以 JSON 數字回傳的 USD 消費上限,供顯示使用。
null 表示不設限。limit_amount_decimalstring | null
以十進位字串回傳的 USD 精確消費上限。
null 表示不設限。used_amountnumber
以 JSON 數字回傳的 USD 累計用量支出,供顯示使用。
used_amount_decimalstring
以十進位字串回傳的 USD 精確累計用量支出。
modelsstring[]
單一 Key 的模型白名單。空陣列表示沒有額外的 Key 層級模型限制。
delivery_policystring | null
auto, verified, official, null. null 表示繼承工作區交付策略。expires_atstring | null
Key 到期時間的 ISO 時間戳記;
null 表示永不到期。last_used_atstring | null
最近一次使用的 ISO 時間戳記;從未使用時為
null。created_atstring
建立時間的 ISO 時間戳記。
授權
ManagementTokenAuth AuthorizationBearer <token>
管理權杖驗證。請在 Dashboard > API > Management Tokens 建立或管理管理權杖。
位置: header
路徑參數
keyId*string
請求主體
application/json
必須提供至少一個欄位。
屬性
1 <= properties回應
application/json
application/json
application/json
application/json
application/json
application/json