Errors
Every error returns a consistent JSON envelope with the correct HTTP status code. Credits are never charged on a failed operation.
{
"error": {
"code": "insufficient_credits",
"message": "This operation costs 1 credit; your balance is 0."
}
}Status codes
| Status | Code | Meaning |
|---|---|---|
400 | invalid_input | Malformed request or missing image. |
401 | unauthorized | Missing, invalid, or revoked API key. |
402 | insufficient_credits | Your balance is too low. Top up to continue. |
413 | payload_too_large | The image exceeds the maximum upload size. |
422 | unsupported_format | The file is not a supported image type. |
422 | unprocessable_image | The image could not be processed. |
429 | rate_limited | Too many requests. Honor the Retry-After header. |
404 | not_found | The resource does not exist. |
500 | provider_error | Processing failed upstream. You were not charged. |
500 | internal | Unexpected server error. |
Handling errors
- Check the HTTP status first, then read
error.codefor branching. - On
402, prompt the user to top up at the billing page. - On
429, wait for the seconds inRetry-Afterand retry. - On
500, retry with backoff; you are never charged for failures.