Skip to content
Docs

Account

Limits and errors

Errors come in the format of the endpoint you called, so your SDK raises them the way it always does. The status tells you what kind of error it is; the code tells you exactly what happened.

Error format

  • /v1/chat/completions and /v1/responses answer in the OpenAI format: {"error": {"message", "type", "code"}}.
  • /v1/messages answers in the Anthropic format: {"type": "error", "error": {"type", "message"}}. It has no code: the HTTP status and error.type tell errors apart.
{
  "error": {
    "message": "Insufficient balance for this request. Lower max_tokens to 1843 or add credits.",
    "type": "billing_error",
    "code": "insufficient_balance"
  }
}

Concurrency and the queue

Capacity on each model is shared. Your account can run several requests at once, and every account gets a fair share: one busy account cannot take all the slots.

  • A request that arrives when no slot is free waits in a queue instead of failing, in the order it arrived. You see it as a slower first byte.
  • How many of your requests run at once has a limit that grows with what your account has deposited in total. Your current limit, and what you need for the next one, are in Limits in the console. Requests over it wait in the same queue.
  • If no slot frees up within 20 seconds, it returns 429 queue_timeout.
  • If too many of your requests are already waiting, a new one returns 429 queue_full right away, without queuing.
  • Both come with a Retry-After header. Nothing is charged for a request that never started.

The OpenAI and Anthropic SDKs retry 429 and 5xx on their own, with backoff. For agents that send many requests at once, raise their retries:

client = OpenAI(
    base_url="https://api.libremodel.ai/v1",
    api_key=os.environ["LIBREMODEL_API_KEY"],
    max_retries=5,  # the default is 2; agents that fan out want more
)

Status codes

Error codes
StatusCodeType (OpenAI · Anthropic)MeaningWhat to do
400invalid_requestinvalid_request_error · invalid_request_errorThe body is not valid JSON, model is missing, or the model rejected a parameter.Fix the request. The message says what is wrong.
401invalid_api_keyauthentication_error · authentication_errorNo key, or the key does not exist, has expired or was deleted.Check the header and the key. See Authentication.
402insufficient_balancebilling_error · billing_errorYour balance does not cover this request.Top up, or lower max_tokens to the value the message suggests. See Billing and credits.
403account_suspendedpermission_error · permission_errorYour account is suspended. Every key of the account gets this error.Contact us.
403key_limit_exceededpermission_error · permission_errorThe key reached its spending limit, or what is left of it does not cover this request.Raise the key’s limit in API keys, or lower max_tokens to the value the message suggests. If the limit resets, the message says when.
403model_not_allowedpermission_error · permission_errorThe key is not allowed to use this model.Use a model the key allows, or add this one to the key in API keys.
404model_not_foundinvalid_request_error · not_found_errorThere is no model with that ID.Check the ID in Models.
413request_too_largeinvalid_request_error · request_too_largeThe body or the context is over the limit.Send less: shorter history, fewer or smaller images.
429queue_timeoutrate_limit_error · rate_limit_errorYour request waited in the queue and no capacity freed up in time.Wait the seconds in Retry-After and retry. The SDKs do it for you.
429queue_fullrate_limit_error · rate_limit_errorToo many requests are already waiting, so this one was not queued.Wait the seconds in Retry-After and retry, or send fewer requests at once.
429rate_limitedrate_limit_error · rate_limit_errorThe model is at capacity right now.Wait the seconds in Retry-After and retry. The SDKs do it for you.
503upstream_unavailableserver_error · overloaded_errorThe model is temporarily unavailable, the service is restarting, or the model cannot take this request right now (for example, a max_tokens above its output limit).Retry after a short wait, with backoff, or after the seconds in Retry-After when it comes. If it repeats, check max_tokens and the size of the request.
503upstream_timeoutserver_error · overloaded_errorThe model took too long to respond.Retry. If it repeats, send a smaller request.
503server_busyserver_error · overloaded_errorToo many requests are being processed right now.Retry after the seconds in Retry-After. The SDKs do it for you.

A request that fails before the response starts is not charged.

Errors inside a stream

Once a stream has started, the status is already 200. A failure from then on arrives as an error event, in the format of the endpoint you called, with the codes upstream_interrupted, upstream_timeout, insufficient_balance or key_limit_exceeded. You pay only for what was delivered. Details in Streaming. A request without streaming can also get its 200 before the response is complete; then an error comes in the body: see Without streaming.

Which errors to retry

  • Retry: 429 (after Retry-After) and 503 (with a short, growing wait). The OpenAI and Anthropic SDKs already retry both.
  • Do not retry as is: 400, 401, 403, 404 and 413. The same request will fail the same way.
  • `402`: retry only after topping up or lowering max_tokens.
import os
import openai

# The SDK retries 429 and 5xx responses on its own, honoring Retry-After.
client = openai.OpenAI(
    base_url="https://api.libremodel.ai/v1",
    api_key=os.environ["LIBREMODEL_API_KEY"],
    max_retries=3,
)

try:
    response = client.chat.completions.create(
        model="deepseek-v4.1-flash-1017",
        messages=[{"role": "user", "content": "Hello, Libremodel"}],
    )
except openai.APIStatusError as err:
    # err.body["code"] is the Libremodel error code, e.g. "insufficient_balance"
    print(err.status_code, err.body)
    print("request id:", err.response.headers.get("x-request-id"))

Request ID

Every API response, error or not, carries an x-request-id header. If something looks wrong, write to us with that ID and we can find the request.