Error Response Format
All API errors follow a consistent format:Common Error Codes
400 Bad Request
Invalid input parameters or malformed requests.- Missing required fields
- Invalid parameter values
- Malformed JSON
- Unsupported image sizes or formats
401 Unauthorized
Invalid or missing API key.- Missing Authorization header
- Invalid API key
- Expired API key
- Wrong header format (missing “Bearer ” prefix)
403 Forbidden
API key doesn’t have access to requested resource.- API key tier restrictions
- Provider not available in your plan
- Account suspended
402 Payment Required
Insufficient credits to complete the operation.- Credit balance is too low
- Cost of generation exceeds available balance
- Account needs to add credits
- Check your balance using
/api/credits/balance - Add credits via the dashboard or payment endpoint
- Implement balance checks before expensive operations
404 Not Found
Requested resource doesn’t exist.- Invalid provider name
- Invalid model name
- Typo in endpoint URL
429 Too Many Requests
Rate limit exceeded.- Too many requests per minute
- Daily/monthly quota exceeded
500 Internal Server Error
Server-side error.- Model inference timeout
- Provider service unavailable
- Internal system errors
Error Handling Patterns
JavaScript/TypeScript
Python
Retry Logic
Exponential Backoff
Circuit Breaker Pattern
Validation
Input Validation
Monitoring and Logging
Error Tracking
Best Practices
- Always check response status before processing
- Implement proper retry logic with exponential backoff
- Validate input before making requests
- Log errors for debugging and monitoring
- Handle rate limits gracefully
- Use circuit breakers for resilient error handling
- Provide meaningful error messages to users
- Monitor error rates and alert on anomalies
Most errors are transient and can be resolved with retries. Persistent errors may indicate API key issues or account problems.