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

StatusCodeMeaning
400invalid_inputMalformed request or missing image.
401unauthorizedMissing, invalid, or revoked API key.
402insufficient_creditsYour balance is too low. Top up to continue.
413payload_too_largeThe image exceeds the maximum upload size.
422unsupported_formatThe file is not a supported image type.
422unprocessable_imageThe image could not be processed.
429rate_limitedToo many requests. Honor the Retry-After header.
404not_foundThe resource does not exist.
500provider_errorProcessing failed upstream. You were not charged.
500internalUnexpected server error.

Handling errors

  • Check the HTTP status first, then read error.code for branching.
  • On 402, prompt the user to top up at the billing page.
  • On 429, wait for the seconds in Retry-After and retry.
  • On 500, retry with backoff; you are never charged for failures.