TokenLab

管理

更新 API Key

更新目前組織中的既有使用者 API Key。

PATCHhttps://api.tokenlab.sh/v1/management/api-keys/{keyId}

概覽

這個 endpoint 可更新既有 API Key 的名稱、額度、模型白名單、過期時間或狀態。

請求主體

PATCH 請求至少需要提供一個欄位。

欄位型別預設值 / 限制說明
statusenum-active, inactive, revoked
namestring長度 1-50更新後的顯示名稱
limitAmountnumber | string | null0–100000 USDnull 表示不設限,0 表示無法產生費用。十進位字串最多支援 6 位小數。
limitCurrency列舉預設 USD僅限 USD。傳送 CNY 會回傳 400 currency_retired。 設定時必須同時提供 limitAmount。
modelsstring[]-更新後的模型白名單
deliveryPolicystring | nullauto, verified, official, nullnull 表示繼承工作區交付策略。
expiresAtstring | nullRFC3339 datetimenull 表示移除過期時間

說明

  • 金額欄位僅支援 USD。CNY 輸入已停用,並會回傳 400 currency_retired。

  • Management API v1 故意不支援硬刪除。

  • revoked 通常視為終態;若需要重新使用,通常建議直接建立一把新的 Key。

範例

請求

cURL
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 傳送管理請求;本頁不提供直接傳送功能。

回應範例

回應

200 OK
{
  "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