·Error Codes

Error Codes

All API errors follow a consistent structure. Check the error.code field for programmatic error handling.

400missing_fieldsBad Request

Required fields are missing from the request body.

400invalid_modelBad Request

The model field contains an invalid value.

401unauthorizedUnauthorized

Missing or malformed Authorization header.

401invalid_keyUnauthorized

The API key does not exist or has been deleted.

401key_revokedUnauthorized

The API key exists but has been revoked.

402insufficient_creditsPayment Required

The account does not have enough credits for this operation.

429rate_limit_exceededToo Many Requests

The key has exceeded the 100 requests/minute limit.

500generation_failedServer Error

The image generation failed on the upstream provider.

Handling errors in code

  • Always check HTTP status code first, then error.code for specifics
  • Retry 500 errors with exponential backoff
  • For 429 errors, respect the Retry-After header
  • Never retry 401 or 402 without fixing the underlying issue first