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_KEY

Authentication errors

Authentication errors
Statuserror.codeMeaning
401invalid_api_keythe key is unknown, revoked, expired or malformed
401no key was sent (the body is {"detail": "unauthorized"})
403scope_missingthe key may not use this endpoint
403model_not_allowedthe key may not use this model
403organization_pending, organization_suspendedthe workspace is not active yet, or suspended: contact support
403test_key_not_supportedtest keys cannot call the model endpoints yet
429too many failed attempts from one address: wait for retry-after (60 s)
503auth_unavailablekeys 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"}}