API Keys API
REST endpoints for key management: create, list, usage statistics, and revoke.
Management endpoints use session authentication: the request header Authorization: Bearer <accessToken> (the token returned by the login endpoint, the same as in the Console), not an API Key starting with sk-tp-. Creating a key requires identity verification first.
POST /api/keys
Create a key.
| Parameter | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Key name, 1–50 characters |
| group | string | No | Group tag (e.g. "Production"), ≤ 30 characters |
| quotaLimit | number | No | Total spending limit for this key's subtree (yuan); omit for no limit |
| parentId | string | No | Parent key id; pass it when creating a sub-key |
In the response, key is the plaintext key (sk-tp-...), returned only this once and never viewable again—save it immediately. The remaining fields are key metadata (prefix, depth, quotaLimit, used, status, etc.).
Constraints:
- A key tree has at most 4 levels.
- A sub-key's quota cannot exceed its parent's.
GET /api/keys
Returns all keys for the current user (excluding plaintext), in ascending order of creation time.
GET /api/keys/usage
Returns the 20 most recent call records: model, keyName, inputTokens, outputTokens, cost, createdAt.
GET /api/keys/usage-stats
Returns usage statistics for the last 30 days:
days: cost / tokens / call count aggregated by daymodels: top 8 models by costtotals: total cost, total tokens, total call count
POST /api/keys/{id}/revoke
Revoke a key. After revocation, the key and all of its sub-keys are cascaded out of service; this action cannot be undone. Bills already incurred are unaffected.