Public API

创建项目 API Key

Management key required. 创建绑定项目的模型 API Key,密钥仅返回一次。

URL 中的 api_key_id 就是创建模型 API Key(POST /public/v1/api-keys)响应中的 id,格式为 ak_...。 请保存这个值,用于后续停用、删除、设置额度和查询用量。响应中的 key(apikey-...)用于模型调用;管理这些 Key 时,请求头仍使用 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