Skip to main content
Flatkey returns standard HTTP status codes alongside a JSON error body that describes what went wrong. Error responses follow the same format as the OpenAI API, so existing error-handling code works without modification.

Error response format

All errors return a JSON object with an error field:

HTTP status codes

400 Bad Request

The request body is malformed or missing a required field.
Common causes:
  • Missing model or messages field in chat completions
  • Invalid JSON in the request body
  • messages array is empty

401 Unauthorized

Authentication failed. Either the key is invalid, missing, or the account balance is zero.
Common causes and fixes:

403 Forbidden

The API key does not have permission to access the requested model.
Fix: Check model access settings for this key in the console.

404 Not Found

The model ID is not recognized by Flatkey.
Fix: Verify the model ID in the Model Directory. IDs are case-sensitive.

429 Too Many Requests

Your key has exceeded the rate limit.
Fix: Implement exponential backoff and retry. Contact support@flatkey.ai if you need higher rate limits.

500 Internal Server Error

An unexpected error occurred while processing your request.
Fix: Retry the request. If the error persists, contact support@flatkey.ai.

503 Service Unavailable

The model provider is temporarily unavailable.
Fix: Retry with exponential backoff. The issue typically resolves within seconds. If it persists, contact support@flatkey.ai.

Retry strategy

For 429, 500, and 503 errors, implement exponential backoff:
python
The OpenAI SDK has built-in retry logic via the max_retries parameter. Set max_retries=3 in the OpenAI client constructor to automatically retry on transient errors.