Authentication
Create API keys in your dashboard and send them with every request.
API keys
Create keys in your dashboard. A key belongs to your workspace; everything it spends is billed to that workspace. You can give each key its own limits, restrict it to certain models, and revoke it at any time.
- Keep keys on your servers. Never put a key in a web page, a mobile app or a public repository.
- Use one key per application or environment, so you can revoke one without touching the others.
- Rotate a key by creating a new one, switching your application to it, then revoking the old one.
Keys have scopes: messages for both API styles, models for GET /v1/models, and billing for GET /v1/billing/balance (not given by default).
Sending the key
Send the key in either header. Both work on every endpoint and in both API styles.
headers
# either header works on every endpoint
Authorization: Bearer YOUR_API_KEY
x-api-key: YOUR_API_KEYAuthentication errors
| Status | error.code | Meaning |
|---|---|---|
401 | invalid_api_key | the key is unknown, revoked, expired or malformed |
401 | no key was sent (the body is {"detail": "unauthorized"}) | |
403 | scope_missing | the key may not use this endpoint |
403 | model_not_allowed | the key may not use this model |
403 | organization_pending, organization_suspended | the workspace is not active yet, or suspended: contact support |
403 | test_key_not_supported | test keys cannot call the model endpoints yet |
429 | too many failed attempts from one address: wait for retry-after (60 s) | |
503 | auth_unavailable | keys cannot be checked right now: retry shortly (never a 401) |
The body follows the API style you called:
Messages API
HTTP/1.1 401 Unauthorized
{"type": "error",
"error": {"type": "authentication_error", "code": "invalid_api_key", "message": "invalid api key"}}Chat Completions API
HTTP/1.1 401 Unauthorized
{"error": {"type": "invalid_request_error", "code": "invalid_api_key", "message": "invalid api key"}}