Public API

建立專案 API Key

Management key required. 建立綁定專案的模型 API Key,密鑰只回傳一次。

URL 中的 api_key_id 就是建立模型 API Key(POST /public/v1/api-keys)回應中的 id,格式為 ak_...。 請儲存此值,以便停用、刪除、設定額度及查詢用量。回應中的 key(apikey-...)用於模型呼叫;管理操作的驗證標頭仍使用 mgmt-...。

POST
/public/v1/api-keys

Management key required. Use a Management API Key (mgmt-...) for your Team, created by a Team Owner.

Create a model API key (apikey-...) bound to the specified active project. This returns a model key, not another management key. The model key owner is the current Team Owner. Existing account, project and member spending rules apply; this endpoint does not set an additional key-level allowance.

Save both fields from the successful creation response: id is the stable ak_... identifier to use as {api_key_id} in the disable, delete, allowance and usage URLs. The JSON field is named id. The key field is the apikey-... secret for model calls and is returned only once. Management calls continue to use mgmt-... in the authorization header.

For example, an id of ak_0123456789ABCDEFGHIJKL gives the usage URL /public/v1/api-keys/ak_0123456789ABCDEFGHIJKL/usage. The Public API currently has no key list endpoint; save id when creating the key.

Key names must be unique among non-deleted keys in the account. Retrying with the same name returns 409 and does not recover the original secret. There is currently no fixed per-account or per-project key count limit. Request rate limits still apply.

Authorization

ManagementKeyBearer
AuthorizationBearer <token>

Management key required. Send Authorization: Bearer mgmt-....

In: header

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://example.com/public/v1/api-keys" \  -H "Content-Type: application/json" \  -d '{    "name": "customer-123-primary",    "project_id": "019a6eab-7c00-7000-8000-000000000123"  }'
{  "object": "api_key",  "id": "ak_0123456789ABCDEFGHIJKL",  "name": "customer-123-primary",  "project_id": "019a6eab-7c00-7000-8000-000000000123",  "key": "apikey-REPLACE_WITH_SECRET_RETURNED_ONCE",  "redacted": "apikey-xxxx********xxxx",  "enabled": true,  "created_at": "2026-11-11T00:00:00Z",  "expires_at": null,  "request_id": "req_example"}

Last updated on