管理
建立 API Key
為目前組織建立新的使用者 API Key。
POSThttps://api.tokenlab.sh/v1/management/api-keys
概覽
這個 endpoint 會在目前管理令牌所屬的組織下,建立一把新的 type=user API Key。
請求主體
| 欄位 | 型別 | 預設值 / 限制 | 說明 |
|---|---|---|---|
name | string | 選填,預設 Default Key,長度 1-50 | 顯示名稱,伺服器端會先去除前後空白 |
limitAmount | number | string | null | 0–100000 USD | null 表示不設限,0 表示無法產生費用。十進位字串最多支援 6 位小數。 建立時省略此欄位表示不設限。 |
limitCurrency | 列舉 | 預設 USD | 僅限 USD。傳送 CNY 會回傳 400 currency_retired。 |
models | string[] | 預設 [] | 可選的模型白名單 |
deliveryPolicy | string | null | auto, verified, official, null | null 表示繼承工作區交付策略。 |
expiresAt | string | null | RFC3339 datetime | null 表示沒有到期時間 |
說明
-
金額欄位僅支援 USD。
CNY輸入已停用,並會回傳400 currency_retired。 -
回應中的完整 API Key 只會顯示一次。
-
models: []表示這把 Key 除了組織層政策外,沒有額外的模型限制。 -
limitAmount: 0會建立一把有效、但暫時無法消耗額度的 Key,之後可再更新。
請求
curl -X POST "https://api.tokenlab.sh/v1/management/api-keys" \
-H "Authorization: Bearer mt-your-management-token" \
-H "Content-Type: application/json" \
-d '{
"name": "Backend Worker",
"limitAmount": 500,
"models": ["veo3.1", "kling-3.0-video"],
"expiresAt": "2026-12-31T23:59:59Z"
}'請求 / 回應
本頁提供 OpenAPI 結構說明及可複製的請求範例。請在終端機或用戶端使用 Management Token 傳送管理請求;本頁不提供直接傳送功能。
回應
{
"id": "key_abc123def456",
"name": "Backend Worker",
"key": "sk-live-redacted",
"key_prefix": "sk-live...",
"status": "active",
"limit_amount": 500,
"limit_amount_decimal": "500",
"used_amount": 0,
"used_amount_decimal": "0",
"models": [
"veo3.1",
"kling-3.0-video"
],
"expires_at": "2026-12-31T23:59:59.000Z",
"last_used_at": null,
"created_at": "2026-07-08T03:00:00.000Z",
"delivery_policy": null
}重要欄位
keystring
完整的 API Key 密鑰,只會在建立時回傳一次。
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
請求主體
application/json
回應
application/json
application/json
application/json
application/json