Skip to content

Reliability and error handling

How to build clients that handle errors gracefully and keep working under load.

Error responses

Mango Inference returns standard HTTP status codes with a JSON body. The body's shape depends on which endpoint family you called, so a client that uses both has to parse both.

/v1/models, /v1/chat/completions

{"error": {"message": "invalid API key", "type": "authentication_error", "code": "invalid_api_key"}}

/v1/messages

{"type": "error", "error": {"type": "authentication_error", "message": "invalid API key"}}

Read the status code first and the body second: the status is what your retry logic should branch on, and the message is for your logs.

Status codes

Status Meaning What to do
400 Invalid request, or a model refused the input (for example an image it cannot read) Fix the request; do not retry unchanged.
401 Missing, malformed, or unknown API key Check your API key. Not retryable.
402 API key has insufficient balance Top up your balance.
403 Key disabled, expired, under legal hold, or model not allowed; or a dedicated endpoint is paused Check the error message for the specific cause. Not retryable.
404 No such endpoint, or no such model Check the code: unknown_endpoint means a path Mango Inference does not serve (see OpenAI compatibility); model_not_found means the model ID is wrong.
405 Wrong method for the path /v1/chat/completions and /v1/messages are POST; /v1/models is GET.
413 Request body too large The body exceeds the 32 MiB limit. See Request size limit. Not retryable unchanged.
429 Rate limited by your key's or organization's limits, or a dedicated endpoint's request queue is full Back off and retry. See rate limits.
500 Internal server error Retry with backoff.
502 Upstream unreachable The middleware could not reach any inference engine. Retry with backoff.
503 Service unavailable (capacity, an engine that is full, maintenance, or backend), or a dedicated endpoint that isn't ready yet Retry with backoff. Respect Retry-After if present.
529 Upstream overloaded The inference engine is shedding load. Retry with backoff. Respect Retry-After.

An unknown path answers 404 with code unknown_endpoint and a message naming the method and path. If you get one for a call you expected to work, you have the URL wrong; the usual cause is a /v1 that is doubled or missing. A plain-text or HTML 404 did not come from Mango Inference at all: check the host.

Error types and codes

Every error response carries a JSON body with a type field, and some also carry a machine-readable code that names the specific failure. A client that branches on the code can distinguish errors that share an HTTP status. For example, it can tell a 429 from the platform's own rate limiter (rate_limit_error) apart from a 429 relayed from an upstream engine (upstream_error with code upstream_rate_limited).

The OpenAI-compatible envelope includes code when the middleware sets one; the Anthropic envelope derives its error type from the HTTP status and does not carry a separate code.

Authentication and key errors

Status Error type Error code Message
401 authentication_error invalid_api_key invalid API key
402 invalid_request_error insufficient_balance API key has insufficient balance
403 authentication_error legal_hold API key is under legal hold; an org admin must accept the pending document in the dashboard
403 authentication_error revoked_api_key API key is disabled
403 authentication_error expired_api_key API key has expired
503 internal_error auth_unavailable authentication backend unavailable

Model authorization errors

Status Error type Error code Message
403 permission_error model_not_allowed model {model} is not allowed for this API key
403 permission_error model_not_allowed model {model} is not available to this organization
404 invalid_request_error model_not_found model {model} does not exist
404 invalid_request_error api_not_supported model {model} is not available on this API
503 invalid_request_error model_under_maintenance model {model} is under maintenance
503 internal_error entitlements_unavailable model entitlements are temporarily unavailable

Model IDs are case-sensitive. When the ID you sent differs from a model you can call only in letter case, the model_not_found message adds "did you mean {model}?".

Rate limiting

Status Error type Error code Message
429 rate_limit_error (names the limit dimension) rate limit exceeded: {N} {resource} per minute for this API key

A 429 from the platform's own rate limiter carries these headers:

Header Meaning
Retry-After Seconds until the limit resets.
X-RateLimit-Limit The limit on the dimension that tripped.
X-RateLimit-Remaining Remaining requests in the window.
X-RateLimit-Reset Seconds until reset (same value as Retry-After).
X-RateLimit-Resource Which limit dimension was hit (e.g. requests, tokens).

Dedicated endpoint errors

A call to a dedicated endpoint's model ID can also return these. The order they are checked in, and what to do about each, is on that page.

Status Error type Error code Message
403 permission_error endpoint_paused This endpoint is paused: {reason}. Contact [email protected].
503 invalid_request_error endpoint_not_ready This endpoint isn't ready yet.
429 rate_limit_error rate_limited This endpoint is at capacity. Try again shortly.

Upstream and capacity errors

Status Error type Error code Message
500 internal_error upstream_error upstream inference engine returned an error
502 upstream_error upstream_unreachable failed to reach upstream inference engine
503 upstream_error upstream_at_capacity model {model} is at capacity
503 upstream_error upstream_draining model {model} is not currently accepting requests
503 upstream_error no_healthy_upstream model {model} is temporarily unavailable
503 upstream_error upstream_rate_limited upstream inference engine is rate limiting requests
503 upstream_error upstream_unavailable upstream inference engine is temporarily unavailable
529 upstream_error upstream_overloaded upstream inference engine is overloaded

The only 429 you receive is the platform's own rate limiter. When an inference engine itself is full, you get a 503 with code upstream_rate_limited, so it is never mistaken for your key's quota. A 503 or 529 relayed from an engine carries Retry-After if the engine sent one. The platform's own 503 capacity and availability errors also carry Retry-After.

Request size limit

A request body may be at most 32 MiB (33,554,432 bytes) on /v1/chat/completions, /v1/messages and /v1/messages/count_tokens. A larger body is rejected before it reaches a model:

Status Error type Error code Message
413 invalid_request_error request_too_large request body exceeds the maximum size of 33554432 bytes (32 MiB); …

On /v1/messages the same rejection has error.type request_too_large.

The limit applies to the encoded request, so images and PDFs sent inline count at their base64 size, about 4/3 of the file size. A 20 MiB PDF is about 26.7 MiB in the request, which fits; a file larger than about 24 MiB does not.

Upstream 400 relay

When the upstream engine rejects the request with a 400 (or 422), the status is relayed with the engine's explanation, always in the endpoint's own error envelope. The engine's raw error body is never passed through.

On /v1/chat/completions:

  • message is the engine's message.
  • code is the engine's own error code when it gives one, for example image_url_not_accepted (see Images and PDFs). Branch on it to handle specific refusals. When the engine gives no usable code, code is upstream_invalid_request, which distinguishes a request the engine rejected from one the platform's own validation rejected.
  • param names the offending request field, when the engine names one.
{
  "error": {
    "message": "…",
    "type": "invalid_request_error",
    "code": "image_url_not_accepted",
    "param": "messages[0].content[1].image_url"
  }
}

On /v1/messages the Anthropic envelope has no code or param, so only the status and message are relayed.

In-stream errors

A streaming response that started with 200 can still fail mid-stream: the engine sends an error frame inside the SSE stream after tokens have already been generated. The client sees the stream end; the error is captured in the platform's logs and usage records. Tokens generated before the error frame are billed.

Retries and backoff

  • Retry only transient failures: 429 and 5xx. Never retry a 400 or 401 unchanged; the second attempt fails identically and costs you a round trip.
  • Use exponential backoff with jitter. Without jitter, a fleet that hits a limit together retries together and hits it again.
  • Respect a Retry-After header if one is present, in preference to your own schedule.
  • Cap total attempts and total elapsed time. An unbounded retry loop against a rate limit is indistinguishable from an attack on your own quota.
  • Streamed responses can fail mid-stream, after a 200. Decide whether a partial completion is usable before you retry, because retrying charges you for the tokens twice.

Timeouts and streaming

  • Set a client-side timeout appropriate to your max_tokens. Reasoning models generate far more tokens than their visible answer suggests, so a timeout tuned on a standard model will fire early on one. See Reasoning.
  • For long generations, prefer streaming so partial output arrives incrementally and an idle connection is distinguishable from a slow one.

Reporting a problem

Every response carries x-request-id and x-trace-id. Log them. When something looks like a platform fault rather than a client bug, quote them, with the timestamp and the model ID, in a Support request or to [email protected]. They are how the team finds your specific request. See Platform support.