Skip to content

Docs / Errors

Errors

Every Yunshu Router error code in the OpenAI and Anthropic formats: what it means, whether to retry, and what to do next to fix it.

Get an API key

Errors come back in the format of the endpoint you called, so your SDK raises its usual exceptions. Every error has our own code, which is the same on both formats, and a request id you can quote to support.

Error messages never name the company that hosted the request, and never pass on a raw message from it.

Where to look

Situation Where the error is
Request refused before it starts HTTP status and JSON body
Stream fails after it has started An error event inside the stream; the HTTP status is already 200. See Streaming
One request in a batch fails error on that item in GET /v1/batches/{id}/results
A whole batch is refused HTTP status and JSON body; the message names the bad item
Anything GET /v1/generation?id= shows status and error for a request that reached a model

Error shapes

OpenAI format

Used by /v1/chat/completions, /v1/responses, /v1/models, /v1/generation, /v1/batches and every other path outside /v1/messages.

{
  "error": {
    "type": "insufficient_balance",
    "code": "insufficient_balance",
    "message": "Account balance is zero or negative. Please top up to continue.",
    "request_id": "4f1c..."
  }
}

type and code both hold our code. There is no param field.

Anthropic format

Used by /v1/messages and /v1/messages/count_tokens.

{
  "type": "error",
  "error": {
    "type": "billing_error",
    "message": "Account balance is zero or negative. Please top up to continue.",
    "code": "insufficient_balance"
  },
  "request_id": "4f1c..."
}

error.type is Anthropic’s own type, so Anthropic SDKs and Claude Code react as they would to Anthropic. error.code is our code.

Headers on every error

Header When
x-yunshu-request-id Always. Quote it when you contact support
Retry-After On rate_limited (1 second), no_route_available (5 seconds) and overloaded (1 second)

Error codes

The table lists every code a /v1/ request can return. “Retry” means the same request may succeed later without changes.

HTTP code Anthropic error.type Meaning Retry? What to do
400 invalid_request invalid_request_error The body is not valid: not JSON, a missing or wrong field, empty messages, an unknown model suffix, previous_response_id on /v1/responses, a bad batch item No Read message; it names the field. Fix the request
400 context_length_exceeded invalid_request_error The prompt is longer than the model’s context window No Shorten the prompt, use a model with a larger window, or add one as a fallback
401 authentication_failed authentication_error No key, or the key is wrong, revoked or deleted No Check the header and the key. See Authentication
402 insufficient_balance billing_error Balance is empty, or too low to hold this request’s maximum price No Top up, switch on automatic top-up, or lower max_tokens
402 budget_exceeded billing_error The key’s monthly budget is spent, or this request could pass it No Wait for the next UTC month, or use another key. See Budgets and limits
403 offer_not_permitted permission_error The key’s allow-list does not include this model No Use an allowed model or another key
403 account_suspended permission_error Your organisation is suspended No Contact support
403 permission_denied permission_error Not allowed for this organisation, for example a batch with zero retention on No Read message
404 offer_not_found not_found_error The model ID is unknown, unpublished, or a combo that does not exist No Check the ID against GET /v1/models. Check the spelling and the case
404 not_found not_found_error The path, batch or request id does not exist in your organisation No Check the URL and the base URL. A /v1/v1/... path means /v1 is in the base URL twice. See Base URLs
405 method_not_allowed api_error Wrong HTTP method for this path No For example, POST to /v1/chat/completions, not GET
413 request_too_large request_too_large The body is over 2 MiB No Send less: fewer or smaller messages, images by URL
429 rate_limited rate_limit_error Over the key’s or the organisation’s requests per minute, or over 10 batch submissions per minute Yes Wait for Retry-After, then back off
500 internal_error api_error An unexpected error on our side Yes, a few times Retry with backoff. If it continues, contact support with the request id
500 configuration_error api_error A setup problem on our side No Contact support with the request id
502 upstream_unavailable api_error The model could not answer: it was unreachable or returned an error Yes Retry with backoff, or add a fallback
503 no_route_available api_error No capacity for this model right now Yes Wait for Retry-After (5 s), or add a fallback
503 quote_expired api_error This model’s pricing is being renewed, so it cannot be priced Yes, later Use a fallback, or retry later
503 overloaded overloaded_error We are shedding load Yes Wait for Retry-After, then back off
504 upstream_timeout timeout_error The model took too long to answer Yes Retry, lower max_tokens, or use streaming for long answers

Requests that end in any error are not charged.

Codes inside streams and batches

  • Streams. A failure after the first event carries one of the 5xx codes above, usually upstream_unavailable, in the stream’s own error event. On the Anthropic format its error.type is api_error; on Responses it is response.failed with error.code.
  • Batch items can also end with cancelled (the batch was cancelled before the item ran) or expired (the completion window closed first), or with the code of the error that failed it.

Anthropic types that differ from Anthropic’s own API

  • Anthropic returns 529 for overloaded_error. We return 503.
  • Anthropic’s billing_error is 402 on both.
  • 413 request_too_large keeps Anthropic’s type name.

How the SDKs see these errors

Both SDKs choose the exception class from the HTTP status.

HTTP OpenAI SDK (Python / TypeScript) Anthropic SDK (Python / TypeScript)
400 BadRequestError BadRequestError
401 AuthenticationError AuthenticationError
402 APIStatusError (status 402) APIStatusError (status 402)
403 PermissionDeniedError PermissionDeniedError
404 NotFoundError NotFoundError
413 APIStatusError (status 413) —
429 RateLimitError RateLimitError
5xx InternalServerError InternalServerError (OverloadedError is for 529 only)

Both SDKs retry 429, 5xx and connection errors twice by default, reading Retry-After. Set max_retries to change this.

Branch on our code, not on the message text. Messages may change and are translated in the console.

import openai
from openai import OpenAI

client = OpenAI(base_url="https://api.yunshurouter.com/v1", api_key="tq-...")

try:
    client.chat.completions.create(model="deepseek-v4-pro", messages=[{"role": "user", "content": "Hi"}])
except openai.APIStatusError as err:
    body = err.response.json().get("error", {})
    code = body.get("code")
    request_id = err.response.headers.get("x-yunshu-request-id")
    if code == "insufficient_balance":
        ...  # ask for a top-up
    elif code == "context_length_exceeded":
        ...  # trim the conversation
    else:
        raise
import anthropic

client = anthropic.Anthropic(base_url="https://api.yunshurouter.com", api_key="tq-...")

try:
    client.messages.create(model="deepseek-v4-pro", max_tokens=256, messages=[{"role": "user", "content": "Hi"}])
except anthropic.APIStatusError as err:
    code = err.body.get("error", {}).get("code") if isinstance(err.body, dict) else None
    print(err.status_code, code, err.response.headers.get("x-yunshu-request-id"))
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.yunshurouter.com/v1", apiKey: "tq-..." });

try {
  await client.chat.completions.create({ model: "deepseek-v4-pro", messages: [{ role: "user", content: "Hi" }] });
} catch (err) {
  if (err instanceof OpenAI.APIError) {
    const code = (err.error as { code?: string } | undefined)?.code;
    console.log(err.status, code, err.headers?.["x-yunshu-request-id"]);
  } else {
    throw err;
  }
}

Retry guidance

  • Retry: 429, 500 internal_error, 502, 503, 504. Use exponential backoff with jitter, and honour Retry-After.
  • Do not retry unchanged: 400, 401, 402, 403, 404, 405, 413. The same request will fail the same way.
  • Retrying a failed request is safe for billing: a request that ended in an error was not charged.
  • For model failures (502, 503, 504), a fallback chain is often better than a retry: the next model is tried at once, within the same request.

Common setup errors

What you see Usual cause
404 not_found on every request /v1 is missing from, or doubled in, the base URL. See Base URLs
401 authentication_failed with a key you just created Extra characters copied with the key, or the key is in the wrong variable (for example ANTHROPIC_API_KEY when the tool reads ANTHROPIC_AUTH_TOKEN)
404 offer_not_found A model ID from another provider’s API (for example gpt-4o). Use an ID from GET /v1/models
402 insufficient_balance on a new account No top-up yet. There is no free credit
400 invalid_request mentioning previous_response_id A Responses client using stored state. Send the whole conversation with store: false

Contacting support

Send the x-yunshu-request-id value, the time of the request (with time zone) and the endpoint.