Error codes

HTTP status codes and response envelopes used by LLM, media task, and OpenAI-compatible image endpoints.

Error envelopes vary by endpoint family. LLM upstream errors are classified by the readable error message. Only pool-style infrastructure failures that the upstream returns with a non-2xx status are normalized to HTTP 424 so provider details and internal addresses are not exposed. Other upstream non-2xx errors keep the upstream status and retain their public semantics in the protocol-specific envelope (type is upstream_error when the upstream gives none; a non-JSON upstream body is not exposed, and message becomes bad response status code <status> with type and code set to bad_response_status_code; Anthropic Messages appends (request id: …) to message). For an error the upstream returns in an HTTP 200 body (for streams, an error event before any content): streaming OpenAI Chat Completions and Responses requests and native Gemini endpoints receive the upstream HTTP 200 and body unchanged; non-streaming OpenAI Chat Completions and Responses requests receive HTTP 200 with {"error": {...}}; Anthropic Messages returns HTTP 500. When you receive HTTP 200, check the body or stream for error.

LLM and Responses endpoints

Gateway-generated errors normally use:

{
  "error": {
    "message": "Missing model",
    "type": "model_not_found"
  }
}

Common types include invalid_request_error, model_not_found, authentication_error, insufficient_quota, rate_limit_error, api_error, and internal_error.

HTTP 402 (insufficient_quota) states the reason in code:

codeMeaningWhat to do
insufficient_balanceBalance is used up and no credit line is availableTop up.
credit_line_exhaustedBalance is used up and the credit line is used up tooTop up.
credit_line_not_allowedBalance is used up and this model on this channel cannot use the credit line; message names the model and channelTop up, or switch to a model or channel that accepts the credit line.
key_limit_reachedThe key reached its spend limitRaise the key's limit or use another key.

When an LLM upstream reports a pool-style infrastructure failure, the gateway returns HTTP 424 and a neutral error for the calling protocol. Model identifiers in otherwise public error messages are always reported as the public model ID. OpenAI Chat Completions and Responses use:

{
  "error": {
    "code": "provider_error",
    "message": "Provider error (request id: aitk-12345678)",
    "type": "api_error"
  }
}

Anthropic Messages uses { "type": "error", "error": { "type": "api_error", "message": "..." } }; Gemini uses { "error": { "code": 424, "message": "...", "status": "FAILED_PRECONDITION" } }. Diagnostics for pool failures are retained only in server-side logs. Network failures and stream read failures use the same neutral provider error; a stream emits it as a protocol-specific terminal SSE event.

Other upstream non-2xx errors (including non-JSON bodies, upstream 401/402/403, rate limits, and 5xx) keep the upstream HTTP status. OpenAI Chat Completions and Responses preserve message and any supported type, code, and param fields; Anthropic returns its native error envelope; Gemini returns its native { "error": { "code", "message", "status" } } envelope. Malformed, empty, or otherwise unstructured bodies use a safe protocol-compatible fallback with a redacted message.

Async media task endpoints

Route-level errors from /v1/router/... normally use:

{
  "code": 402,
  "message": "Insufficient balance. Top up to continue.",
  "task_id": ""
}

Media task endpoints do not use the LLM account limits or the retired shared per-key/per-IP allowance.

OpenAI-compatible image endpoints

/v1/images/generations and /v1/images/edits use:

{
  "error": {
    "message": "Only n=1 is supported",
    "type": "invalid_request_error",
    "code": null
  }
}

They may also return authentication_error, insufficient_quota, rate_limit_error, api_error, or timeout_error.

HTTP status reference

StatusCommon type / conditionWhat to do
400invalid_request_error or model_not_foundValidate JSON and required fields, then use an ID and endpoint returned by the current key's GET /v1/models; also check its channel and model access.
401authentication_errorCheck that the API Key is present, active, and correctly formatted.
402insufficient_quotaTop up or use a Key that has not reached its spend limit.
403Media model is not available to the callerCheck model access and the Pricing / model list pages.
404Media task not found or not owned by this buyerCheck the task_id and use the same buyer's API Key.
409Media task has no upstream id, or terminal status conflictRe-query the task; contact support if the state does not recover.
424api_error from an LLM endpoint with error.code=provider_errorRecord the request ID; retry only through controlled application-level exponential backoff and jitter.
429LLM account limit, upstream rate limit, or duplicate protectionFor account_rpm_limit, use RateLimit-*; for account_concurrency_limit, use Retry-After. Duplicate protection has neither header set.
5xxupstream_error, api_error, internal_error, or timeout_errorRetry recoverable failures; for image 504, poll the task_id because the task continues running.

If an upstream stream read fails after HTTP 200 has been committed, the status cannot be changed to 424. While the downstream connection remains writable, the gateway emits exactly one protocol-framed provider_error event carrying the request ID, omits the normal completion marker, and closes the stream without exposing the underlying exception. If the client or transport is already gone, no event can be delivered and only the internal failure log remains. Clients should treat either the error event or a stream that ends without its protocol-specific completion event as a failed response; use the request ID from the event or the X-AIToken-Request-Id / X-OneAPI-Request-Id response header when contacting support.

On this page

On this page