API error
unauthorized
HTTP 401 · no credit is used for a request that ends in an error.
No API key was sent, or the key is not valid: unknown, revoked, expired or replaced by a roll.
What to do
Send a current key as Authorization: Bearer <key> (or X-Api-Key). Create a new key in the dashboard if needed.
Retry
No: fix the request. When and how often to retry any error: retrying safely.
The answer
{
"error": {
"code": "unauthorized",
"message": "A valid API key or session is required.",
"request_id": "req_7Hq2LmX9cV4bN8tR1zK6wD"
}
}No API key sent:
{
"error": {
"code": "unauthorized",
"message": "Send your API key in the Authorization header: Bearer <key>.",
"request_id": "req_7Hq2LmX9cV4bN8tR1zK6wD"
}
}API key not valid:
{
"error": {
"code": "unauthorized",
"message": "The API key is not valid.",
"request_id": "req_7Hq2LmX9cV4bN8tR1zK6wD"
}
}Branch on code, which is stable; message is for people and may change. Keep request_id in your logs.
Headers that come with it:
X-Request-Id: Our ID for the request (same asrequest_idin bodies).WWW-Authenticate: The authentication scheme and the OAuth protected resource metadata (RFC 9728;/mcpanswers withWwwAuthenticateMcp). When a key or access token was sent and refused, the challenge also carrieserror="invalid_token", as in the example.
Endpoints that can answer it
GET /v1/validate(401)POST /v1/validate(401)GET /v1/credits(401)GET /v1/usage(401)POST /v1/bulk(401)GET /v1/bulk/{id}(401)DELETE /v1/bulk/{id}(401)POST /v1/bulk/{id}/start(401)GET /v1/bulk/{id}/results(401)GET /mcp(401)POST /mcp(401)POST /a2a(401)