Error response format
All errors return a JSON object with anerror field:
HTTP status codes
400 Bad Request
The request body is malformed or missing a required field.- Missing
modelormessagesfield in chat completions - Invalid JSON in the request body
messagesarray is empty
401 Unauthorized
Authentication failed. Either the key is invalid, missing, or the account balance is zero.403 Forbidden
The API key does not have permission to access the requested model.404 Not Found
The model ID is not recognized by Flatkey.429 Too Many Requests
Your key has exceeded the rate limit.500 Internal Server Error
An unexpected error occurred while processing your request.503 Service Unavailable
The model provider is temporarily unavailable.Retry strategy
For429, 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.