API

Errors & retries

The error body, every error code with its HTTP status, and when to retry.

Every error answer has the same JSON body:

JSON
{
  "error": {
    "code": "INVALID_INPUT",
    "message": "wait must be an integer from 0 to 60 (seconds).",
    "retryable": false,
    "field": "wait"
  }
}
FieldDescription
error.codeStable, machine-readable code (table below). Branch on this, not on the message.
error.messageHuman-readable explanation. The wording can change.
error.retryabletrue when the same call can succeed later without changes.
error.fieldThe input field at fault, when there is one (snake_case, for example items[1].model_id).
error.retry_after_secondsHow long to wait before retrying, when known. Sent together with a Retry-After header.
error.suggestionsMODEL_NOT_FOUND only: close matches, each { id, name, type }.
request_idTop level, next to error: present when the request was recorded before it failed. Check GET /v1/requests/{request_id} before retrying.

Errors of a finished request (status failed, or a failed item of a batch) use the same error object inside the request object.

#Error codes

HTTPCodeMeaning
400INVALID_INPUTA field is missing, has the wrong type or value (see field), or the body is not valid JSON.
400URL_NOT_ALLOWEDA URL (for example webhook_url or source_url) is not https, carries credentials, or points to a non-public address.
400INVALID_RUN_TOKENA run behind the request could not be identified.
400MODEL_REQUIREDA model id is missing (for example in a batch item).
400MODEL_KIND_MISMATCHThe model does not produce the requested kind (for example a video model in an image batch item).
400MODEL_NOT_ALLOWEDThe model is not one of AITOPIA's recommended models for this operation; pick one of the suggestions.
400DUPLICATE_ITEMIdentical batch items with a model that takes no seed; vary the prompts.
401UNAUTHENTICATEDMissing, malformed, unknown or revoked key (Authentication).
401KEY_SESSION_EXPIREDThe key's aitopia.ai session ended. Sign in to aitopia.ai to reactivate the key.
402INSUFFICIENT_CREDITSNot enough credits on the account.
402KEY_CREDIT_CAP_REACHEDThe key's monthly credit cap would be passed (Billing).
402OVER_BUDGETThe plan costs more than max_credits.
404MODEL_NOT_FOUNDNo model with this id; see suggestions.
404NOT_FOUNDNo such request in your account, or no such endpoint.
404TOOL_NOT_FOUNDThe requested operation does not exist.
409PRICE_CHANGEDThe price changed since the dry run. Nothing was run or charged; run a new dry run.
409PRICE_UNKNOWNThe price could not be checked before running, so nothing ran (for example an edit step without a fixed price).
409PLAN_EXPIREDThe plan_token expired (plans are kept 1 hour and run once), was already used, or belongs to another file or instruction; run a new dry run.
413FILE_TOO_LARGEThe body or file is over the size limit (File uploads).
413INPUT_TOO_LARGEThe model input is over the size limit (the message names the limit).
422PLAN_INVALIDNo valid edit plan could be built.
422ASSET_UNREACHABLEAn input file could not be downloaded (unreachable or too slow).
422NOT_SUPPORTEDNo AITOPIA model, agent or tool can do this edit.
429RATE_LIMITToo many requests (Rate limits).
429RUN_LIMITEDA generation limit on the account. Retry only after retry_after_seconds when it is given; otherwise read message.
429QUEUE_LIMIT_EXCEEDEDOnly a few runs can be active at once per account; wait for running jobs to finish.
500INTERNAL_ERRORAn unexpected error on our side.
502UPSTREAM_5XXA service behind the API failed.
502UPSTREAM_UNCERTAINThe run may have started and may be charged. Check the request_id and your balance before retrying.
503MODEL_UNAVAILABLEThe model (and its fallbacks) is unavailable right now. Nothing was run or charged.
503SERVER_RESTARTINGThe server is restarting. Always retryable.
503SESSION_UNAVAILABLEThe sign-in service is temporarily unreachable (not a problem with your key). Always retryable.
504TIMEOUTAn upstream step timed out.

A code not listed here is answered with HTTP 502. Treat it like UPSTREAM_5XX and follow retryable.

#Codes inside a request

These appear in the error of a request or a batch item, not as an HTTP error status:

CodeWhereMeaning
STATUS_CHECK_FAILED, RUN_STALE, KEY_SESSION_EXPIREDopen request (queued / running)A status check did not get through; the request stays open (details).
OUTPUT_INCOMPLETE, NO_OUTPUTfailedThe run finished but its output was missing or unreadable.
UPSTREAM_RUN_FAILEDfailed (request or batch item)The model provider ran the job and reported a failure; message gives the provider's reason. Follow retryable. The sandbox returns it for X-Sandbox-Outcome: failed / partial.
RUN_INTERRUPTED, RUN_LOSTfailedA background run was interrupted, for example by a server restart.
FAILEDfailedThe run failed without a more specific code; see message.

#When to retry

The retryable flag in the body is authoritative. As a rule:

  • retryable: true: retry the same call. Wait retry_after_seconds when present (or the Retry-After header), otherwise back off exponentially (for example 1 s, 2 s, 4 s ... up to a minute). Unless the body says otherwise, 429, 503 and 504 answers are retryable; SERVER_RESTARTING and SESSION_UNAVAILABLE always are.
  • retryable: false: change something first (fix the input, add credits, sign in to aitopia.ai, raise the cap). Retrying the same call gives the same answer.

Submits are not idempotent: the API has no idempotency keys, and every accepted submit is a new, separately charged run. Before you retry a submit that failed with a 5xx or a network error:

  1. If the error body has a request_id, GET /v1/requests/{request_id} first: the run may exist.
  2. On 502 UPSTREAM_UNCERTAIN (retryable: false) check the request and your balance; do not retry blindly.
  3. On a network error with no answer at all, check GET /v1/account/balance before submitting again.

GET calls (models, requests, balance) are safe to retry at any time.

AITOPIA REST API · Live https://api-live.aitopia.ai/v1 · Sandbox https://api-sandbox.aitopia.ai/v1