Developers
Keys and guides for the OpenAI- and Anthropic-compatible API. Requests are paid from the same balance as chat.
Error format
/api/v1/messages and /api/v1/messages/count_tokens return errors in Anthropic's format. Every other endpoint uses OpenAI's. Both carry the same code, which is stable, so match on it rather than on the message.
{
"error": {
"message": "Insufficient balance. Top up your account to continue.",
"type": "insufficient_quota",
"code": "insufficient_balance",
"param": null
}
}Status codes
- 400 invalid_request
- The request is malformed or uses a feature we don't support. The message names the parameter.
- 401 invalid_api_key
- The key is missing, mistyped or revoked.
- 402 insufficient_balance
- Your available balance can't cover the request. Add funds on the Billing page.
- 402 key_spend_limit_reached
- The key has reached its spending limit. Raise or remove the limit on the API keys tab.
- 403 key_disabled, account_disabled
- The key or the account has been disabled. Contact support.
- 404 model_not_found
- The model ID doesn't exist or isn't available. Check it against
GET /api/v1/models. - 404 not_found
- Unknown endpoint. Check the path and the base URL.
- 413 request_too_large
- The request body is over 32 MB.
- 429 rate_limit_exceeded
- Too many requests for the key, or too many at once for your account. Wait for the number of seconds in the
Retry-Afterheader. - 502 upstream_error
- The model provider returned an error or couldn't be reached. Retry with backoff.
- 503 service_unavailable
- Requests are paused for a short time, for example during maintenance. Retry after the
Retry-Afterdelay.
Rate limits
Each key allows 120 requests per minute unless you give it its own limit, from 1 to 10,000, on the API keys tab. Going over returns 429 with a Retry-After header.
Concurrent requests
Your account can run a limited number of requests at the same time, across all keys. The limit grows with your available balance:
- Less than $5
- 4 requests at a time
- $5 to $49.99
- 16 requests at a time
- $50 or more
- 64 requests at a time
A request over the limit gets 429. It can be retried as soon as another request finishes.
Balance holds
While a request runs, it holds an estimate of its maximum cost from your balance. Your available balance is the balance minus these holds, and GET /api/v1/balance returns both.
A request fails with 402 insufficient_balance when the available balance can't cover its hold, even if the balance itself is higher. Holds also count toward a key's spending limit. Setting max_tokens keeps holds small.
Retries
Retry 429, 502 and 503 responses with exponential backoff, waiting at least as long as Retry-After when it's present. The official OpenAI and Anthropic SDKs do this for you.
Don't retry other 4xx errors unchanged: the same request fails the same way. Fix the request, the key or the balance first.