Errors and status codes
Every error the API sends, what causes it and what to do about it.
Error format
On the OpenAI-format endpoints (/v1/chat/completions, /v1/responses, /v1/models) an error is a JSON body with an HTTP status code that is not 2xx:
{
"error": {
"message": "The model 'gpt-4o' does not exist on FreeModel. Only models listed on https://freemodel.in/models are supported.",
"type": "invalid_request_error",
"code": "model_not_found",
"param": "model"
}
}
Use code in your program and show message to people. param is only present when one field caused the error.
Anthropic format
Requests to /v1/messages, and requests that carry an anthropic-version, x-api-key or anthropic-api-key header, get the Anthropic error shape instead. It has no code field; the type follows the HTTP status:
{
"type": "error",
"error": {
"type": "billing_error",
"message": "Your plan tokens are used up. Renew or upgrade your plan at freemodel.in/dashboard/plan to continue. Your wallet balance is never charged automatically."
}
}
| HTTP status | Anthropic error.type |
|---|---|
| 401 | authentication_error |
| 402 | billing_error |
| 403 | permission_error |
| 404 | not_found_error |
| 429 | rate_limit_error |
| 503 (sent as 529) | overloaded_error |
| 500, 502, 504 | api_error |
| anything else | invalid_request_error |
In this format a 503 is sent as HTTP 529, and 429 and 529 responses carry Retry-After: 3 and retry-after-ms: 3000, which Anthropic SDKs and Claude Code use for their automatic retry.
The Gemini endpoints use Google's error shape for errors from the model call; see Gemini API format.
Error reference
401 — authentication
| Code | Cause | Fix |
|---|---|---|
invalid_api_key | No key was sent, the key is wrong, or it was revoked. | Send Authorization: Bearer fm_… or x-api-key: fm_…. Check the key at Dashboard → API keys; a rotated or revoked key stops working at once. |
key_expired | The key has an expiry date and it has passed. | Extend the date on the key or create a new key. |
user_not_found | The account that owned the key no longer exists. | Create a new account and key. |
402 — tokens or limits used up
A 402 means the request was refused before it reached a model. Nothing was charged. Retrying will not help until the limit changes, so do not retry in a loop.
| Code | Cause | Fix |
|---|---|---|
tokens_exhausted | The plan tokens of the account are used up. On the free plan: the free tokens are used up. | Renew or upgrade at Pricing; on the free plan, buy a plan for more usage or invite a friend. The wallet balance is never charged automatically. |
prompt_exceeds_quota | The estimated prompt size, times the model's multiplier, is more than the tokens you have left. | Shorten the prompt, use a model with a lower multiplier, or add tokens. |
key_token_limit_reached | This API key reached the token limit you set on it. | Raise or remove the limit on the key in the dashboard. |
key_spend_limit_reached | This API key reached the spend limit you set on it. | Raise or remove the spend limit on the key. |
403 — not allowed
| Code | Cause | Fix |
|---|---|---|
upgrade_required | A free account asked for a model that needs a paid plan. The message lists the models your free tokens work with. | Use one of the free models (GPT-6.2 Astra, GPT-6 Luna, Grok 4.6, Grok 4.7, Claude Haiku 5.5, GLM-5.3 Flash, Qwen 3.8 Omni Flash and DeepSeek V4.1 Flash 1017) or buy a plan. |
telegram_verification_required | A free account has not done the one-time Telegram verification yet. | Verify Telegram in the dashboard. See Free plan. |
insufficient_scope | The key does not have the scope this endpoint needs (inference, models:read or embeddings). | Create a key with that scope. See API keys. |
key_paused | You paused this key in the dashboard. | Resume the key. |
account_banned | The account was suspended. | Contact support. |
400, 404, 413, 422 — the request itself
| Status | Code | Cause | Fix |
|---|---|---|---|
| 404 | model_not_found | The model id is not on our list. We only serve listed models: a name such as gpt-4o or claude-3-5-sonnet is not mapped to another model. | Use an id from Models or GET /v1/models. See Model IDs. |
| 404 | model_not_available | The model exists but is not available on this account. | Pick another model from the list. |
| 400 / 422 | invalid_json | The body is not valid JSON (422 on chat completions, 400 on messages and responses). | Send a JSON body with Content-Type: application/json. |
| 400 / 422 | validation_error | model or a non-empty messages array is missing. | Add the required fields. |
| 400 | missing_input, bad_request | /v1/responses got an empty body or no usable input. | Send input as a string or an array of items. |
| 400 / 413 | context_length_exceeded | The conversation is longer than the model's context, or a free account sent a request of more than 128,000 tokens. | Shorten or compact the conversation. |
429 — too many requests
| Code | Cause | Fix |
|---|---|---|
rate_limit_exceeded | This key sent more requests in the last 60 seconds than its requests-per-minute limit. | Wait the number of seconds in Retry-After. |
account_rate_limit_exceeded | All keys of the account together passed the plan's requests per minute. | Wait for Retry-After, or upgrade. More keys do not add more requests. |
too_many_concurrent | Too many requests are running at the same moment for this account (10 normally, 3 on the free plan, fewer when tokens are nearly used up). | Retry when a running request finishes. |
free_tpm_limit | A free account sent more than 400K tokens in a minute (all keys and models together). | Wait the number of seconds in Retry-After. |
Details are on Rate limits.
502, 503 — temporary problems
| Status | Code | Cause | Fix |
|---|---|---|---|
| 503 | model_temporarily_unavailable | The model you asked for has no working route right now. We do not answer it with a different model. | Retry after a short wait, or pick another model. |
| 503 | model_under_maintenance | The model is in scheduled maintenance. | Use another model or try again later. |
| 503 | service_under_maintenance | The API is in maintenance. Sent with Retry-After: 1800. | Try again later; see Status. |
| 503 | free_tokens_paused | Free usage is paused for a while because of load. Paid plans are not affected. Sent with Retry-After: 300. | Retry later. |
| 503 | no_upstream_capacity, upstream_node_overloaded, engine_capacity_exceeded | The model provider failed or is overloaded. | Retry with backoff. |
| 429 | upstream_capacity_exhausted | The model provider is rate limiting. Sent with Retry-After: 5. | Retry with backoff. |
| 502 | upstream_malformed | The provider's answer could not be read. | Retry. |
Errors during a stream
If a streamed chat completion fails after the first bytes were sent, the HTTP status is already 200. The error then arrives as a server-sent event:
event: error
data: {"error":{"message":"…","type":"api_error","code":"upstream_node_overloaded"}}
On /v1/responses a failure after the stream started is sent as a response.failed event whose response.error holds a code and message.
Billing and retries
- A request that ends with an error status (400 or higher), or that produced no output, is not charged. It still appears in your usage log with its status and error, so you can see what happened.
- Retry 429, 502, 503 and 529 with exponential backoff, and respect
Retry-After. - Do not retry 401, 402, 403 or 404 without changing something first: the same request will fail the same way.
import time
from openai import OpenAI, APIStatusError
client = OpenAI(api_key="fm_your_key_here", base_url="https://freemodel.in/v1")
def ask(prompt, tries=4):
for attempt in range(tries):
try:
r = client.chat.completions.create(
model="gpt-6-luna",
messages=[{"role": "user", "content": prompt}],
)
return r.choices[0].message.content
except APIStatusError as e:
if e.status_code in (429, 502, 503, 529) and attempt < tries - 1:
wait = int(e.response.headers.get("retry-after", 2 ** attempt))
time.sleep(wait)
continue
raise
The OpenAI and Anthropic SDKs already retry some of these statuses themselves; check their max_retries setting before adding your own loop.