Error Handling
Understanding HTTP status codes and error responses helps you build robust applications.
HTTP Status Codes
| Code | Meaning | Action |
|---|---|---|
| 200 | Success | Process response |
| 400 | Bad Request | Check parameters |
| 401 | Unauthorized | Verify API key |
| 402 | Payment Required | Check billing/credits |
| 404 | Not Found | Check IDs |
| 422 | Validation Error | Fix input format |
| 429 | Rate Limited | Wait and retry |
| 500 | Server Error | Retry later |
Error Response Format
All error responses follow this format:
{ "detail": "Error message describing the issue"}Common Error Scenarios
401 Unauthorized
Your API key is invalid or missing:
{ "detail": "API key not found"}Solution: Verify your API key format and ensure it's included in the X-API-Key header.
400 Bad Request
Invalid parameters or missing required fields:
{ "detail": "prompt is required when no files are provided"}Solution: Check the endpoint documentation and ensure all required parameters are provided.
429 Rate Limited
You've exceeded your rate limit:
{ "detail": "Rate limit exceeded. Please try again later."}Solution: Wait for the rate limit window to reset or upgrade your plan. Check the X-RateLimit-Reset header for the reset time.
Best Practices
- Always check HTTP status codes before processing responses
- Implement retry logic for 429 and 500 errors
- Log error details for debugging
- Display user-friendly error messages
- Handle network timeouts gracefully
- Validate inputs before sending requests