Optimize
Errors
In short: An API error is an HTTP status code plus a JSON message; this page explains each code, how to fix 401, 403, 404 and 429 errors, low balance and when to retry.
On this page
- What does an error response look like?
- What do errors look like on /v1/messages?
- Where do I find the request id?
- What do the HTTP status codes mean?
- Why do I get an invalid or missing key error?
- What does an insufficient balance error mean?
- What does 402 Payment Required mean?
- What do the coupon errors mean?
- What do the other 403 errors mean?
- Why do I get a model not found error?
- What causes a 400 or a context length error?
- What does 501 Not Implemented mean?
- What does a 429 rate limit error mean?
- What do 500, 502 and 503 errors mean?
- When do requests time out?
- How should I retry failed requests?
- Quick answers
- How do I get help with an error?
An API error is a normal HTTP status code with a JSON body that says what went wrong. Most problems are one of three things: the key, the base URL, or the balance. This page helps you tell them apart quickly.
What does an error response look like?#
Errors use the OpenAI-style error envelope, which every OpenAI SDK already understands. Errors that come from the model provider keep the provider's status code and message.
{
"error": {
"code": "",
"message": "Invalid token (request id: 20261008101503123456789abcdef)",
"type": "api_error"
}
}{
"error": {
"code": "insufficient_user_quota",
"message": "Your balance is too low for this request. Add credit under Billing in the console. (request id: 20261008101503123456789abcdef)",
"type": "api_error"
}
}{
"error": {
"code": "model_not_found",
"message": "No available channel for model qwen-qwen3.8-27b:free under group default (distributor) (request id: 20261008101503123456789abcdef)",
"type": "api_error"
}
}{
"error": {
"message": "Unknown endpoint. The API lives under /v1 (for example POST /v1/chat/completions).",
"type": "invalid_request_error",
"param": null,
"code": "not_found"
}
}Branch on the HTTP status first, then on error.code where it is set (for example model_not_found or insufficient_user_quota). Match on the code, not on the message text: messages are written for people and can change. Log error.message anyway, since it names the model, group or limit involved.
What do errors look like on /v1/messages?#
Errors on the Anthropic endpoint use Anthropic's shape once a request reaches the model step. Checks that run before that (key, model allowlist, IP allowlist, model availability) answer with the OpenAI envelope above on every endpoint. The Anthropic SDKs raise an error from the HTTP status either way.
{
"type": "error",
"error": {
"type": "api_error",
"message": "Your balance is too low for this request. Add credit under Billing in the console. (request id: 20261008101503123456789abcdef)"
}
}Where do I find the request id?#
The request id is in the X-Request-Id header on every response, and gateway error messages end with (request id: …). Log it with failures; it is the fastest way for support to find your request.
What do the HTTP status codes mean?#
Each status code below shows its usual cause, the fix, and whether the request is safe to retry.
Fix the request, do not retry Safe to retry with backoff
- 400Bad RequestBad RequestFix, do not retry
Cause: Invalid JSON, a missing or invalid field, a prompt longer than the context window, a model that is listed but not priced yet (model_price_error), or an image or video request refused by the content policy (content_policy).
Fix: Read the message, fix the body, shorten the input. Details
- 401UnauthorizedUnauthorizedFix, do not retry
Cause: Key missing, mistyped, disabled, expired or deleted, or sent in a header the endpoint does not read.
Fix: Check the header and that the environment variable is loaded. Create a new key if needed. Details
- 402Payment RequiredPayment RequiredFix, do not retry
Cause: A paid model from an account whose balance is $0 (paid_needs_deposit); or a free model at a $0 balance on an account that has never topped up (free_needs_topup).
Fix: Add balance under Billing. Details
- 403ForbiddenForbiddenFix, do not retry
Cause: Balance, plan allowance or the key spending limit is used up; the key may not use this model or group; or the request came from an IP the key does not allow.
Fix: Add credit, raise the key limit, or edit the key settings. Details
- 404Not FoundNot FoundFix, do not retry
Cause: Wrong URL path, usually /v1 missing (OpenAI format) or doubled (Anthropic format).
Fix: Use the base URLs exactly as shown in the docs. Details
- 413Payload Too LargePayload Too LargeFix, do not retry
Cause: The request body is over 64 MB, usually from large base64 images or files.
Fix: Shrink or split the input. Details
- 429Too Many RequestsToo Many RequestsRetry with backoff
Cause: The model provider is throttling, a per-model rate limit is in force, or the key reached a requests-per-minute limit or spend budget you set (key_rate_limit, key_daily_budget), or one end user reached the spend per end user set on the key (end_user_budget). Also the daily limit on free models (daily_limit_free), images or videos.
Fix: Back off and retry. Reduce parallel requests. Details
- 500Internal Server ErrorInternal Server ErrorRetry with backoff
Cause: Unexpected error in the gateway or at the provider.
Fix: Retry with backoff. Report it with the request id if it persists. Details
- 501Not ImplementedNot ImplementedFix, do not retry
Cause: An OpenAI endpoint the gateway does not offer, such as Files, fine-tuning or image variations.
Fix: Use a supported endpoint (see the API reference). Details
- 502Bad GatewayBad GatewayRetry with backoff
Cause: The provider returned an invalid response or dropped the connection.
Fix: Retry with backoff. Details
- 503Service UnavailableService UnavailableRetry with backoff
Cause: No provider route is available for the model right now, the model is not enabled for your account, or the provider is overloaded.
Fix: Check the model id; retry later or switch to a sibling model. Details
Why do I get an invalid or missing key error?#
Every key problem returns 401 with the message Invalid token, whatever the exact cause, so check each of these:
- Print the variable in the same terminal (
echo $ONEAIAPIKEY_API_KEY, or$env:ONEAIAPIKEY_API_KEYin PowerShell). An empty value is the most common cause. - Make sure the value starts with
sk-and has no quotes, spaces or line breaks copied along with it. - OpenAI clients send
Authorization: Bearer; Anthropic clients sendx-api-key.x-api-keyis read only on/v1/messagesand/v1/models; everywhere else use the Bearer header. - Check under API keys that the key is enabled, not past its expiry date, and not deleted.
What does an insufficient balance error mean?#
When the request cannot be paid for, the gateway rejects it before calling the model, with 403. Nothing is charged. The code tells you which limit was hit:
insufficient_user_quota: the account balance (or the plan allowance, if billing uses a plan only) is too low. Add credit under Billing, or switch to a free model.pre_consume_token_quota_failed: this key's own spending limit is reached, even though the account may have money. Raise or remove the limit under API keys.
Before a request runs, the gateway reserves an estimate of its cost, so a request can be refused while the balance is still slightly above zero. A lower max_tokens lowers the reservation. New balance applies to the next request immediately.
What does 402 Payment Required mean?#
A 402 means the balance cannot pay for the request. Any balance above $0, the $10.00 sign-up credit and coupon credit included, pays for every model at its listed price. Requests the balance cannot pay for are refused with 402 before any model runs, so nothing is charged. The code says why:
paid_needs_deposit: a paid model from an account with no plan whose balance is $0. Add balance under Billing.video_needs_paid: rarely used now; a video request on too little balance. Add credit under Billing.
What do the coupon errors mean?#
Coupon errors come only from a request that named a code in X-Coupon (see Coupons): the coupon was asked to pay, so if it cannot, the call fails instead of charging your balance. Redeeming the same code in the console answers coupon_not_found, coupon_rate_limited and the 409 codes the same way; coupon_not_applicable, coupon_busy and coupon_unavailable exist only while a request runs. coupon_budget_empty is the exception in another way: it can come on any request a coupon would have paid, without a header.
| Status | code | Meaning |
|---|---|---|
| 402 | coupon_not_applicable | The code's credit is used up, expired or switched off, it does not cover this model, or what is left is too small for the request. Coupon … cannot pay for this request… |
| 404 | coupon_not_found | No coupon has that code, or it is a gift code for another email address. That code is not valid. Check it and try again. |
| 409 | coupon_ended | The code is past the date it can be redeemed on, or its credit has ended. This code can no longer be redeemed. |
| 409 | coupon_disabled | The code was withdrawn. This code has been switched off. |
| 409 | coupon_used_by_you | Redemption happens once per account; the credit it gave is listed under Billing. You have already redeemed this code. |
| 409 | coupon_used_up | Every use of the code is taken. This code has already been used. |
| 409 | coupon_off | Coupons are not open at the moment, so no code can be redeemed. Coupons are not available yet. |
| 429 | coupon_busy | Three coupon-paid requests are already running on this account. Up to 3 coupon-paid requests run at once per account. Try again when one has finished. |
| 429 | coupon_rate_limited | Ten unknown codes were tried on this account in the last hour, in the console or through the header. Too many tries. Try again in an hour. |
| 503 | coupon_unavailable | The coupon could not be checked because of a temporary fault; nothing was charged. Could not check the coupon. Try again shortly. |
| 503 | coupon_budget_empty | The coupon budget behind all coupons is used up. Any request a coupon would have paid is refused until it is topped up; send X-Coupon: off to have your own balance pay instead. Coupon credit is paused for now because the coupon budget is used up. Try again later, or use your own balance by adding credit under Billing. |
What do the other 403 errors mean?#
The table lists every 403 message the gateway can return, and what each one means:
| Message | code | Meaning |
|---|---|---|
| Your balance is too low for this request. Add credit under Billing in the console. | insufficient_user_quota | Your account balance cannot cover the request. |
| Your plan allowance is used up or no plan is active. Add balance, or wait for the allowance to reset. | insufficient_user_quota | Billing is set to use a plan only, and the plan allowance is spent. |
| token quota is not enough, token remain quota: …, need quota: … | pre_consume_token_quota_failed | This key reached the spending limit you set on it. The account balance is not the problem. |
| This token has no access to model … | (empty) | The key has a model allowlist and this model is not on it. |
| This key or account cannot use the … group | (empty) | The key is pinned to a group your account cannot use, often after a plan change. |
| The … group is no longer available | (empty) | The key is pinned to a group that was retired. |
| Your IP address is not on this key's allowed list | access_denied | The key has an IP allowlist and the request came from another address. Check the key’s Allowed IP addresses on the keys page, or clear the field to accept any address. |
Spend limit, expiry and model list are on the key's edit dialog under API keys. See Authentication and keys.
Why do I get a model not found error?#
If no model has the id you sent, the gateway answers 404 with code model_not_found and "Model … does not exist." If the model exists but your account cannot use it right now, it answers 503 with code model_not_found and either "Model … needs a paid balance." (no top-up yet) or "Model … is not available right now. Try again shortly or pick another model."
- Copy ids exactly from
GET /v1/modelsor the models table. Ids are case-sensitive:qwen-qwen3.8-27b:free, not a display name. - A
404here is never about your balance. A paid model on an account whose balance is $0 returns402paid_needs_deposit(see payment required), and a balance too low for the request returns an insufficient-balance error; add credit under Billing. - Calling an OpenAI-only model on
/v1/messages? Use the OpenAI endpoint instead (see models by format).
What causes a 400 or a context length error?#
A 400 means the request itself needs changing, so retrying it unchanged will fail again. Typical messages mention an invalid parameter, a missing model, an image the model cannot read, or a prompt that exceeds the context window. For long conversations, trim or summarise old turns, and keep max_tokens within the model's output limit.
model_price_error("Model … has not been priced by the administrator yet"): the model is listed but not open for use yet. Pick another model, or tell us which one you need.content_policy("This request was refused: sexual content involving minors is never generated."): an image or video prompt was refused before any model ran. Nothing is charged and it does not count against your daily caps. Change the prompt; the same prompt is refused again.413: the body is larger than 64 MB, almost always because of inline images or files. Resize them or send fewer per request.
What does 501 Not Implemented mean?#
A 501 means the gateway does not offer that endpoint. Some OpenAI endpoints are not offered: Files (/v1/files), fine-tuning, image variations, deleting models, and /v1/messages/count_tokens. They return 501 with code api_not_implemented (or 404). The API reference lists what is available.
What does a 429 rate limit error mean?#
A 429 means slow down, not stop. Today it almost always comes from the model provider during peak load; the gateway does not apply its own per-account request limit to paid models on the API. If a per-model limit is switched on, its message says so: "Rate limit reached: at most N requests per M minutes". Two codes come from limits you set on a key yourself: key_rate_limit (the key's requests per minute) and key_daily_budget (the key's spend budget, which resets daily, weekly or monthly, UTC); both send Retry-After in seconds, and you change them under Keys in the console. A key set to block at its budget gets key_budget_blocked until you unblock it there; retrying does not help. With a spend limit per end user, end_user_budget means that one end user (the request's useror metadata.user_id) reached it; Retry-After says when they can send again (per-key limits). Retry with exponential backoff, honour a Retry-After header when present, and cap how many requests you run in parallel. See Rate limits and retries.
Free models (ids ending in :free) share one allowance of 100 requests a day for every account, in Chat and through the API. Past it they return 429 with code daily_limit_free and the message "You have used today's 100 free requests or 3,000,000 tokens. They refill tomorrow at 05:30 IST (00:00 UTC). To raise your limit, contact support to switch to a paid plan." Only an owner grant, a coupon or a paid subscription raises that number, and no account is uncapped. The allowance refills at 00:00 UTC, which is 05:30 IST; the 429 carries Retry-After, and retrying sooner does not help.
What do 500, 502 and 503 errors mean?#
500, 502 and 503 are usually short-lived: a provider hiccup or a capacity spike for one model. Retry with backoff. The gateway has already retried the call up to two more times on the same model (a failed attempt is not billed), so an error that reaches your code failed every attempt. If one model keeps failing, switch to a sibling model temporarily; the rest of your code does not change because every model shares the same API.
When do requests time out?#
A stream closes after 300 seconds without data from the provider, and a long non-streaming request can be cut off by your client or a proxy.
- Streaming: the gateway closes a stream when the provider sends nothing for 300 seconds. Reasoning models with long thinking phases are the usual cause.
- Non-streaming: the gateway does not cut the request off, but your HTTP client and any proxy on the way may. A long answer with nothing sent until the end is the most likely to time out.
- Use
stream: truefor long outputs: tokens flow continuously, so nothing sits idle. Set your client's read timeout to a few minutes. - Do not blindly retry a timed-out request: the model may have finished and been billed even though your client never saw the answer. If you disconnect early, you pay for the tokens produced up to that point.
How should I retry failed requests?#
Retry only on 429, 500, 502, 503 and network errors. Wait longer after each attempt (1s, 2s, 4s… with random jitter) and give up after about five tries. Never retry 400, 401, 403, 404 or 501: they will fail the same way.
import os, random, time
from openai import OpenAI, APIStatusError, APIConnectionError
client = OpenAI(
base_url="https://api.oneaiapikey.com/v1",
api_key=os.environ["ONEAIAPIKEY_API_KEY"],
max_retries=0, # we handle retries ourselves below
)
RETRYABLE = {429, 500, 502, 503}
def backoff(attempt, retry_after=None):
if retry_after and retry_after.isdigit():
return int(retry_after) # honour the server's hint
return min(30, 2 ** attempt) + random.random() # 1s, 2s, 4s… + jitter
def chat(attempts=5, **kwargs):
for attempt in range(attempts):
try:
return client.chat.completions.create(**kwargs)
except APIStatusError as e:
if e.status_code not in RETRYABLE or attempt == attempts - 1:
raise
time.sleep(backoff(attempt, e.response.headers.get("retry-after")))
except APIConnectionError:
if attempt == attempts - 1:
raise
time.sleep(backoff(attempt))
reply = chat(model="gpt-6-luna:free", messages=[{"role": "user", "content": "ping"}])const RETRYABLE = new Set([429, 500, 502, 503]);
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const backoff = (i) => Math.min(30_000, 1000 * 2 ** i) + Math.random() * 1000;
export async function chat(body, attempts = 5) {
for (let i = 0; i < attempts; i++) {
let res;
try {
res = await fetch("https://api.oneaiapikey.com/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ONEAIAPIKEY_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify(body),
});
} catch (err) {
if (i === attempts - 1) throw err; // network error
await sleep(backoff(i));
continue;
}
if (res.ok) return res.json();
if (!RETRYABLE.has(res.status) || i === attempts - 1) {
throw new Error(`${res.status} ${res.headers.get("x-request-id")}: ${await res.text()}`);
}
const hint = Number(res.headers.get("retry-after"));
await sleep(hint > 0 ? hint * 1000 : backoff(i));
}
}Quick answers#
Why does my request return 401 Unauthorized?
The API key is missing, mistyped, disabled, expired or deleted, or it is sent in the wrong header. OpenAI clients use Authorization: Bearer; Anthropic clients use x-api-key.
Why do I get 404 Not Found?
The base URL is wrong. OpenAI-format clients need the URL ending in /v1; Anthropic-format clients and Claude Code need the origin without /v1.
What does insufficient_user_quota mean?
Your account balance, or your plan allowance, cannot cover the request. Add credit under Billing in the console. Nothing is charged for the rejected request.
What does pre_consume_token_quota_failed mean?
The API key reached the spending limit set on it. Raise or remove the limit on the key in the console; the account balance is not affected.
How do I get help with an error?#
If an error persists, email support@oneaiapikey.com with:
- the request id (from the
X-Request-Idheader or the end of the error message); - the time of the request (with timezone), the endpoint and the model id;
- the HTTP status and the full error message;
- the key's name or its last four characters. Never send the full key.
curl -i https://api.oneaiapikey.com/v1/chat/completions \
-H "Authorization: Bearer $ONEAIAPIKEY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "z-ai-glm-5.3-flash:free", "messages": [{"role": "user", "content": "ping"}]}'