Error Handling
Understand and handle API errors gracefully
Error response format
Common error codes
401
INVALID_API_KEYAPI key is missing, malformed, or invalid
429
RATE_LIMIT_EXCEEDEDToo many requests — see the Plan Limits page
402
INSUFFICIENT_CREDITSAccount has run out of credits
503
MODEL_NOT_AVAILABLERequested model is temporarily unavailable
400
INVALID_REQUESTRequest body is malformed or missing required fields
400
CONTEXT_LENGTH_EXCEEDEDMessage exceeds the model context window
404
CONVERSATION_NOT_FOUNDRAG conversation ID does not exist
500
INTERNAL_ERRORInternal server error — please retry
Error handling example
Debugging tips
Always log the requestId for support · check response status codes first · validate request format before sending · monitor error rates in analytics
Production best practices
Implement comprehensive error handling · use retry logic with exponential backoff · set up error monitoring · give users friendly error messages
