Models → Pricing → Docs → Blog → Changelog → Contact → Status →
Get started freeLog in

Handling 402, 403 and 429 Errors on FreeModel

What FreeModel API errors 402, 403 and 429 mean, the error codes behind each one, how to read them in Python and Node, and what fixes each of them.

Three status codes cause most support questions: 402, 403 and 429. They look similar in a stack trace, but they mean very different things and need different fixes. This is a troubleshooting guide: find your code, read what it means, apply the fix.

Step 1: read the error body

The status code tells you the family. The code field tells you the exact cause. On the OpenAI-format endpoints (https://freemodel.in/v1) every error has the same envelope:

{
  "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.",
    "type": "insufficient_quota",
    "code": "tokens_exhausted"
  }
}

The Anthropic-format endpoint (/v1/messages) uses Anthropic's shape instead, which has a type but no code:

{"type": "error", "error": {"type": "billing_error", "message": "..."}}

There, 402 is billing_error, 403 is permission_error and 429 is rate_limit_error. The message carries the same explanation in both formats, so always log it.

402: your tokens are used up

A 402 means there are no tokens left for this request. The request is rejected before the model runs, and nothing is charged on top.

codeMeaningFix
tokens_exhaustedThe plan allowance is used upRenew or upgrade on pricing
prompt_exceeds_quotaThis prompt alone needs more tokens than you have leftSend a smaller prompt, or top up the plan
key_spend_limit_reached, key_token_limit_reachedA limit you set on this key is reachedRaise or remove the limit in API keys

prompt_exceeds_quota surprises people: the account still has tokens, but fewer than this one prompt needs. The check multiplies the estimated prompt size by the model's multiplier, so a long prompt on a 3× model such as claude-sonnet-5 needs three times its size in plan tokens. See estimating tokens before you send.

Do not retry a 402. It will not change until the plan or the limit changes.

403: this key may not do that

A 403 means the request is understood but not allowed for this account or key.

codeMeaningFix
upgrade_requiredA free account asked for a paid model (Claude models other than Haiku 5.5, GPT-6 Astra, Gemini and other premium models)Use a free model, or buy any paid plan — every paid plan reaches every model
insufficient_scopeThe key lacks a scope, for example models:readCreate a key with the needed scopes
key_pausedYou paused this keyResume it in the dashboard

The upgrade_required message lists the models your free tokens do work with. Free tokens work only on the 8 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.

429: you are sending too fast

A 429 is the only one of the three that fixes itself. It means the per-minute request limit is full.

codeMeaning
rate_limit_exceededThis key's requests-per-minute limit is reached
account_rate_limit_exceededThe account's plan limit is reached, counting all its keys together
upstream_capacity_exhaustedThe model is busy right now; comes with Retry-After: 5

Every 429 carries a Retry-After header in seconds. Wait that long, then send again. Successful responses also carry X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset (a Unix timestamp), so you can slow down before you hit the wall. Plan limits range from 30 requests per minute on Free to 1,500 on Ultra; the full table is in rate limits explained.

A reusable handler in Python

The openai package exposes the inner error object as err.body. This handler turns each case into an action: stop with a clear message, fall back to a free model, or wait.

import os
import time

import openai
from openai import OpenAI

client = OpenAI(api_key=os.environ["FREEMODEL_API_KEY"],
                base_url="https://freemodel.in/v1")
FREE_MODEL = "gpt-6-luna"


def ask(model, prompt, attempts=3):
    try:
        r = client.chat.completions.create(
            model=model, messages=[{"role": "user", "content": prompt}])
        return r.choices[0].message.content
    except openai.APIStatusError as err:
        info = err.body if isinstance(err.body, dict) else {}
        code, msg = info.get("code"), info.get("message", str(err))

        if err.status_code == 402:
            raise SystemExit(f"Out of tokens ({code}): {msg}")
        if err.status_code == 403 and code == "upgrade_required" and model != FREE_MODEL:
            return ask(FREE_MODEL, prompt, attempts)      # free account: use a free model
        if err.status_code == 403:
            raise SystemExit(f"Not allowed ({code}): {msg}")
        if err.status_code == 429 and attempts > 1:
            wait = err.response.headers.get("retry-after", "5")
            time.sleep(int(wait) if wait.isdigit() else 5)
            return ask(model, prompt, attempts - 1)
        raise


print(ask("claude-sonnet-5", "One sentence on what HTTP 402 means."))

With a free key, the Claude request returns 403 upgrade_required and the handler answers with gpt-6-luna instead. With a paid plan, Claude answers directly.

The same in Node

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.FREEMODEL_API_KEY,
  baseURL: "https://freemodel.in/v1",
});

export async function ask(model, prompt) {
  try {
    const r = await client.chat.completions.create({
      model,
      messages: [{ role: "user", content: prompt }],
    });
    return r.choices[0].message.content;
  } catch (err) {
    if (!(err instanceof OpenAI.APIError)) throw err;
    const message = err.error?.message ?? err.message;
    if (err.status === 402) throw new Error(`Out of tokens (${err.code}): ${message}`);
    if (err.status === 403 && err.code === "upgrade_required" && model !== "gpt-6-luna") {
      return ask("gpt-6-luna", prompt);
    }
    throw err; // 429s are retried by the SDK itself (maxRetries, default 2)
  }
}

What to show your users

Raw API errors are for logs. Users need one sentence and one action:

  • 402 — "This workspace has used its AI tokens. An admin can renew the plan." Link to your billing page.
  • 403 upgrade_required — "This model needs a paid plan." Offer the free model instead.
  • 429 — usually nothing: retry quietly. Show "Busy, retrying…" only if the wait is longer than a couple of seconds.

Other codes in brief

  • 401 invalid_api_key or key_expired — wrong, revoked or expired key. Check the fm_ key and the header (authentication docs).
  • 404 model_not_found — the id is not served. We do not map names like gpt-4o to other models; copy an id from GET /v1/models.
  • 503 — the model is temporarily unavailable. Retry with backoff, as in retries and backoff.

FAQ

I just bought a plan. Why do I still get 403 upgrade_required?

Check that the key you are using belongs to the account that has the plan. Keys from a second, free account still get 403 for paid models.

Is anything charged when I get a 402?

No. The request is rejected before the model runs and nothing is charged on top.

Does using several API keys raise my rate limit?

No. The plan limit counts all requests of the account together, across all its keys. Extra keys help you see usage per app, not send more requests.

Is there a daily limit on the free plan?

No. The free plan has no daily cap, and paid plans have no daily limit either. A free account has per-minute limits instead: 30 requests and 400K tokens per minute, 3 requests at once.

Ready to build?

Grab a free API key — 1M tokens on 8 free models after a one-time Telegram verification, no card. Every model from $1.20.