Skip to content

Error Handling

Pixapi returns HTTP status codes and machine-readable error codes. Your app should separate user-correctable errors from transient infrastructure failures.

Error shape

json
{
  "error": {
    "code": "model_unavailable",
    "message": "The selected model is temporarily unavailable.",
    "request_id": "req_..."
  }
}

Handling categories

CategoryExamplesAction
Request errorsinvalid_request, model_not_foundFix request validation.
Auth errorsunauthorizedAsk for a valid API key.
Billing errorsinsufficient_creditsShow Credits or Billing.
Policy errorsprompt_rejectedAsk the user to revise input.
Transient errorsrate_limited, model_unavailableRetry with backoff.

Retry pattern

Use exponential backoff for transient failures.

ts
const delays = [500, 1000, 2000];
for (const delay of delays) {
  const res = await callPixapi();
  if (res.ok) return res;
  if (![429, 500, 503].includes(res.status)) break;
  await new Promise((resolve) => setTimeout(resolve, delay));
}

Request ids

Log request_id when available. Include it when opening a support ticket so the team can trace a failing model call without exposing the original prompt to unrelated systems.