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/completionsand/v1/responsesanswer in the OpenAI format:{"error": {"message", "type", "code"}}./v1/messagesanswers in the Anthropic format:{"type": "error", "error": {"type", "message"}}. It has nocode: the HTTP status anderror.typetell errors apart.
{
"error": {
"message": "Insufficient balance for this request. Lower max_tokens to 1843 or add credits.",
"type": "billing_error",
"code": "insufficient_balance"
}
}{
"type": "error",
"error": {
"type": "billing_error",
"message": "Insufficient balance for this request. Lower max_tokens to 1843 or add credits."
}
}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_fullright away, without queuing. - Both come with a
Retry-Afterheader. 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
)const client = new OpenAI({
baseURL: 'https://api.libremodel.ai/v1',
apiKey: process.env.LIBREMODEL_API_KEY,
maxRetries: 5, // the default is 2; agents that fan out want more
})Status codes
| Status | Code | Type (OpenAI · Anthropic) | Meaning | What to do |
|---|---|---|---|---|
400 | invalid_request | invalid_request_error · invalid_request_error | The body is not valid JSON, model is missing, or the model rejected a parameter. | Fix the request. The message says what is wrong. |
401 | invalid_api_key | authentication_error · authentication_error | No key, or the key does not exist, has expired or was deleted. | Check the header and the key. See Authentication. |
402 | insufficient_balance | billing_error · billing_error | Your balance does not cover this request. | Top up, or lower max_tokens to the value the message suggests. See Billing and credits. |
403 | account_suspended | permission_error · permission_error | Your account is suspended. Every key of the account gets this error. | Contact us. |
403 | key_limit_exceeded | permission_error · permission_error | The 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. |
403 | model_not_allowed | permission_error · permission_error | The key is not allowed to use this model. | Use a model the key allows, or add this one to the key in API keys. |
404 | model_not_found | invalid_request_error · not_found_error | There is no model with that ID. | Check the ID in Models. |
413 | request_too_large | invalid_request_error · request_too_large | The body or the context is over the limit. | Send less: shorter history, fewer or smaller images. |
429 | queue_timeout | rate_limit_error · rate_limit_error | Your 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. |
429 | queue_full | rate_limit_error · rate_limit_error | Too 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. |
429 | rate_limited | rate_limit_error · rate_limit_error | The model is at capacity right now. | Wait the seconds in Retry-After and retry. The SDKs do it for you. |
503 | upstream_unavailable | server_error · overloaded_error | The 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. |
503 | upstream_timeout | server_error · overloaded_error | The model took too long to respond. | Retry. If it repeats, send a smaller request. |
503 | server_busy | server_error · overloaded_error | Too 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(afterRetry-After) and503(with a short, growing wait). The OpenAI and Anthropic SDKs already retry both. - Do not retry as is:
400,401,403,404and413. 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"))import OpenAI from 'openai'
// The SDK retries 429 and 5xx responses on its own, honoring Retry-After.
const client = new OpenAI({
baseURL: 'https://api.libremodel.ai/v1',
apiKey: process.env.LIBREMODEL_API_KEY,
maxRetries: 3,
})
try {
await client.chat.completions.create({
model: 'deepseek-v4.1-flash-1017',
messages: [{ role: 'user', content: 'Hello, Libremodel' }],
})
} catch (err) {
if (err instanceof OpenAI.APIError) {
// err.code is the Libremodel error code, e.g. "insufficient_balance"
console.error(err.status, err.code, err.message)
} else {
throw err
}
}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.