Errors overview

Every error the router returns is listed, with its status code, error code, and a sample
body, in the Error reference. This page covers what is common to all
of them.

Response format

Every error has the same JSON body, compatible with OpenAI’s:

{
  "error": {
    "message": "Invalid value for 'messages.0.role': Input should be 'user', 'assistant', 'system' or 'tool'",
    "type": "invalid_request_error",
    "param": "messages.0.role",
    "code": "invalid_request",
    "request_id": "4bf92f3577b34da6a3ce929d0e0e4736"
  }
}
Field Type Description
message string What went wrong, for people. The wording can change at any time
type string The error class, as OpenAI names it: invalid_request_error for most 4xx, insufficient_quota for 402, requests for 429, and server_error for every 5xx
param string or null The request field or header the error is about, such as messages.0.role, model, or X-Quantized-Provider. null when the error isn’t about one
code string The machine-readable error code, such as budget_exhausted. See the Error reference
request_id string The same value as the x-request-id header. See Request IDs
metadata object Only present when there is something to add. Today only 402 budget_exhausted carries it: the budget limit that blocked the request

message, type, param, code, and request_id are always present. metadata is
left out when it would be empty.

Branch on the status and code

The status code and code are the stable contract: they will not change for an existing
error. Messages are meant for people and may change, and messages passed through from a
provider are not part of the Quantized contract at all. Never match on message.

Because the body matches OpenAI’s, the OpenAI SDKs parse it for you: an
openai.APIStatusError has status_code, code, type, param, and message, plus
request_id from the header.

Two responses don’t use this body. GET /v1/health answers 503 with
{"status": "error"} when it is unhealthy. And a path the router doesn’t serve is passed
on to the Quantized management API, which answers it with its own response.

Status codes

Status type Codes Meaning Retry?
400 invalid_request_error invalid_request, invalid_metadata_header, context_length_exceeded, no_provider_available The request can’t be served as sent: a field or header fails validation, the prompt doesn’t fit the model, or no provider can serve it No. Fix the request first
401 invalid_request_error missing_api_key, invalid_api_key, api_key_expired, license_inactive Missing, malformed, unknown, inactive, or expired credentials No
402 insufficient_quota budget_exhausted Your license is out of budget Not until the limit resets or is raised
403 invalid_request_error policy_denied, content_policy_violation Your license’s policy does not allow the request, or a guardrail blocked it No
404 invalid_request_error model_not_found, endpoint_not_found The model can’t serve the request on this endpoint, or the provider doesn’t know it No
405 invalid_request_error method_not_allowed Wrong HTTP method for the endpoint No
413 invalid_request_error request_too_large The request body is too large No
429 requests rate_limit_exceeded The provider rate-limited the request Yes, after retry-after when present
500 server_error internal_error An unexpected error on our side No (x-should-retry: false). Report it with the request ID
502 server_error provider_error The provider failed: a 5xx, an invalid response, or a dropped connection Yes, with backoff
503 server_error policy_unavailable, provider_misconfigured Your license’s policy can’t be evaluated, or our credentials for the provider are missing or rejected No (x-should-retry: false). Report it if it persists
504 server_error upstream_timeout The provider timed out Yes, with backoff

Retries

Three headers help a client decide whether, and when, to retry:

  • x-should-retry: false is sent on 500 internal_error, 503 policy_unavailable,
    and 503 provider_misconfigured: errors a retry won’t fix. The OpenAI and Anthropic
    SDKs honour it and don’t retry them, while still retrying 429, 502, and 504.
  • retry-after is sent on 429 rate_limit_exceeded when the provider said how long
    to wait, in seconds.
  • allow is sent on 405 method_not_allowed, listing the methods the endpoint
    accepts.

The order checks run in

A request goes through the same checks, in the same order, on every endpoint that calls a
provider. The first one that fails decides the response.

  1. Authentication. A malformed Authorization header, or a key or JWT that doesn’t
    resolve to an active license, returns 401 straight away (invalid_api_key,
    api_key_expired, or license_inactive).
  2. Body validation. The JSON body is validated against the endpoint’s schema
    (400 invalid_request). This runs before the check for a missing
    Authorization header, so a request with no key and an invalid body gets 400, not
    401.
  3. Missing credentials. No Authorization header returns 401 missing_api_key.
  4. Quantized headers. A malformed X-Quantized-Provider returns
    400 invalid_request; an invalid X-Quantized-Metadata returns
    400 invalid_metadata_header.
  5. Budget. A license with no budget left returns 402 budget_exhausted. A
    misconfigured budget returns 500 internal_error.
  6. Policy. The license-type policy can deny the service or a parameter value
    (403 policy_denied). A policy that can’t be evaluated returns
    503 policy_unavailable.
  7. Provider selection. No provider able to serve the request returns
    400 no_provider_available. A model whose providers can’t take the request’s input
    or output (for example audio sent to a text-only model) returns
    404 model_not_found. A provider connection without usable credentials returns
    503 provider_misconfigured. An unsupported reasoning effort returns
    400 invalid_request.
  8. Guardrails. An input guardrail can block the request
    (403 content_policy_violation).
  9. Provider call. The provider’s own errors are mapped as shown in
    How provider errors are mapped.
  10. Output guardrails. An output guardrail can block the response
    (403 content_policy_violation).

GET /v1/models and GET /v1/license only run steps 1, 3, and 4. GET /v1/health
needs no credentials.

What you are charged for

A request that fails is not charged, whether the router rejects it or the provider
returns an error. The one exception is a response blocked by an output guardrail:
the provider already did the work, so the call is charged even though you receive a
403.

How provider errors are mapped

The router does not pass provider status codes through as-is:

Provider response You receive
400, 413, or 422 saying the prompt doesn’t fit the model’s context window 400 context_length_exceeded, with our own message and param naming the input field (messages on chat completions, input on Responses and embeddings)
400, 413, or 422 for any other reason (request rejected) 400 invalid_request, with the provider’s message
404 (model or resource not found) 404 model_not_found, with the provider’s message and param: "model"
429 (rate limited) 429 rate_limit_exceeded, with retry-after when the provider sent one
401 or 403 (our credentials rejected), 402 or 429 insufficient_quota (our credit with the provider ran out), or the provider’s own plan limit for our account 503 provider_misconfigured
Any 5xx, a 200 whose body isn’t JSON, a dropped connection, or an error event in a stream 502 provider_error
408, or a timeout 504 upstream_timeout
Any other status 500 internal_error

Every 5xx is masked: the message is ours, and no provider name, message, or
infrastructure detail is included. Each provider words a context-window refusal its own
way; the router recognises them and answers all of them with context_length_exceeded.

Who validates the model

Quantized does not keep a gate in front of the providers. A model id we cannot resolve
in the catalog is forwarded to the provider exactly as you sent it, and the provider
decides whether it exists. The message you get back is the provider’s, not ours.

This matters because the same mistake gets a different answer depending on who serves
the endpoint. On the two single-provider endpoints it is at least consistent:

POST /v1/aws-bedrock/embeddings    {"model": "amazon.titan-embed-text-v99:0"}
400  invalid_request  The provided model identifier is invalid.

POST /v1/gemini/embeddings         {"model": "gemini-embedding-9999"}
404  model_not_found  models/gemini-embedding-9999 is not found for API version v1beta,
                      or is not supported for embedContent.

Both are the same class of error. AWS calls it a 400, Google calls it a 404.

Where an endpoint has several eligible providers it is not stable even across repeated
calls, because an unresolved model gives the router nothing to route on. Identical
requests to POST /v1/chat/completions with {"model": "nonexistent-model"} can come
back with different wordings and different codes, depending on which provider served
each one:

404  model_not_found  nonexistent-model is not a valid model ID
404  model_not_found  The model `nonexistent-model` does not exist or you do not have access to it.
404  model_not_found  model: nonexistent-model
400  invalid_request  The provided model identifier is invalid.
Do not expect one answer

Treat 404 model_not_found, and a 400 invalid_request that appears when you change the
model, as “this model is not usable”. Do not match on message text, and do not expect two
identical requests to fail identically.

Checking a model before you use it

Call GET /v1/models and match on id. That is the list of ids the
catalog resolves; anything else depends on the provider accepting it.

Request IDs

Every response carries an x-request-id header: successes and errors, streams (in the
headers sent before the first event), and even an unexpected 500. It is a 32-character
hex string, unique to the request:

x-request-id: 4bf92f3577b34da6a3ce929d0e0e4736

Every error body repeats it as error.request_id. Log it with your errors and include it
when you contact support: it is how we find the request on our side.

  • OpenAI SDKs read the header for you: completion._request_id on a result, and
    err.request_id on an openai.APIStatusError.
  • In a browser the header is readable from JavaScript: the API lists it in
    Access-Control-Expose-Headers.
  • A traceparent you send is not continued. Each request starts its own trace, so
    x-request-id is never your trace ID, even when your HTTP client propagates one.
  • Other IDs are not ours. Our hosting adds headers such as fly-request-id; quote
    x-request-id.

Handling errors

import time

import httpx

RETRYABLE = {429, 502, 504}

def chat(payload, retries=3):
    for attempt in range(retries):
        response = httpx.post(
            "https://api.quantized.us/v1/chat/completions",
            headers={"Authorization": "Bearer sk-quantized-YOUR-KEY"},
            json=payload,
            timeout=60,
        )
        if response.status_code == 200:
            return response.json()

        error = response.json()["error"]
        if response.status_code in RETRYABLE and attempt < retries - 1:
            # Provider failed, throttled, or timed out: back off and retry.
            time.sleep(float(response.headers.get("retry-after", 2**attempt)))
            continue

        if error["code"] == "budget_exhausted":
            print(f"Out of budget: {error.get('metadata')}")
        elif error["code"] == "policy_denied":
            print(f"Not allowed by your license: {error['message']}")
        elif error["param"]:
            print(f"Invalid {error['param']}: {error['message']}")
        else:
            print(f"Error {response.status_code} {error['code']}: {error['message']}")
        print(f"Request ID: {error['request_id']}")
        response.raise_for_status()

With the OpenAI SDK, catch openai.APIStatusError and branch on err.status_code and
err.code. The SDK already retries 429 and 5xx responses, except those sent with
x-should-retry: false, so you don’t need a retry loop of your own.

Streaming requests report errors that happen after the stream starts inside the stream
itself, with a 200 status. See
Errors during a stream.