Api18.dev

Error handling

Errors return a non-2xx status and a consistent JSON body. Handle the status and the error.type field.

Format#

{
  "error": {
    "type": "invalid_request",
    "message": "Request body failed validation.",
    "details": [ { "path": "duration", "message": "..." } ]
  }
}

Codes#

StatustypeWhen it happens
401missing_authorizationAuthorization header is missing.
401invalid_api_keyKey is invalid or revoked.
400invalid_requestBody failed validation — see error.details.
402insufficient_balanceNot enough balance. Add credits in Billing.
402paid_balance_requiredYou only have test (promo) credit, which the API can't use. Add paid balance. (Test credit works in the playground.)
404model_not_foundThe id in `model` doesn't exist.
404job_not_foundJob doesn't exist or has expired.
502generation_unavailableTransient service failure — retry.

Best practices#

Retry with backoff on 502. On 400, inspect error.details to know which field to fix. On 402, send the user to Billing.

Error handling — Api18.dev Docs