Skip to main content

Error Response Format

All API errors follow a consistent format:

Common Error Codes

400 Bad Request

Invalid input parameters or malformed requests.
Common causes:
  • Missing required fields
  • Invalid parameter values
  • Malformed JSON
  • Unsupported image sizes or formats

401 Unauthorized

Invalid or missing API key.
Common causes:
  • 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.
Common causes:
  • API key tier restrictions
  • Provider not available in your plan
  • Account suspended

402 Payment Required

Insufficient credits to complete the operation.
Common causes:
  • Credit balance is too low
  • Cost of generation exceeds available balance
  • Account needs to add credits
How to handle:
  • 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.
Common causes:
  • Invalid provider name
  • Invalid model name
  • Typo in endpoint URL

429 Too Many Requests

Rate limit exceeded.
Common causes:
  • Too many requests per minute
  • Daily/monthly quota exceeded

500 Internal Server Error

Server-side error.
Common causes:
  • 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

  1. Always check response status before processing
  2. Implement proper retry logic with exponential backoff
  3. Validate input before making requests
  4. Log errors for debugging and monitoring
  5. Handle rate limits gracefully
  6. Use circuit breakers for resilient error handling
  7. Provide meaningful error messages to users
  8. 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.