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

Claude Code

Run Claude Code against FreeModel's Anthropic-compatible API with four environment variables.

⏱ 5 min read

Overview

Claude Code is Anthropic's terminal coding agent. It talks the Anthropic Messages format, not the OpenAI format, so it uses FreeModel's Anthropic-compatible endpoint: POST /v1/messages (plus /v1/messages/count_tokens). You point it at FreeModel with environment variables; nothing else needs to be installed or proxied.

This page goes deeper than the short Claude Code section in Using Coding Agents.

Prerequisites

  • Claude Code installed and starting normally (claude --version prints a version).
  • A FreeModel API key from Dashboard → API Keys. Keys start with fm_ and are shown once.
  • A plan that covers your model. Claude Haiku 5.5 is on the free plan, so Claude Code works on a free key with ANTHROPIC_MODEL=claude-haiku-5.5 (and the same model as the background model). The other Claude models, such as Opus and Sonnet, need a paid plan; a free account that asks for them gets 403 upgrade_required. Plans start at $1.20 for 30 days, see Pricing.

Configuration

VariableValueWhy
ANTHROPIC_BASE_URLhttps://freemodel.inClaude Code adds /v1/messages itself. The https://freemodel.in/v1 form shown on older pages also works.
ANTHROPIC_AUTH_TOKENyour fm_… keySent as Authorization: Bearer …, which FreeModel accepts.
ANTHROPIC_MODELe.g. claude-opus-5-5The main model for the session.
ANTHROPIC_DEFAULT_HAIKU_MODELclaude-haiku-5-5Claude Code also sends background requests to a small "Haiku" model. That model must be one FreeModel lists, or those requests fail with 404.

macOS and Linux

export ANTHROPIC_BASE_URL=https://freemodel.in
export ANTHROPIC_AUTH_TOKEN=fm_your_key_here
export ANTHROPIC_MODEL=claude-opus-5-5
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-5-5

claude

Add the four export lines to ~/.bashrc or ~/.zshrc to keep them across terminals.

Windows (PowerShell)

$env:ANTHROPIC_BASE_URL = "https://freemodel.in"
$env:ANTHROPIC_AUTH_TOKEN = "fm_your_key_here"
$env:ANTHROPIC_MODEL = "claude-opus-5-5"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "claude-haiku-5-5"

claude

These last for the current window. Put them in your PowerShell profile to make them permanent.

On a free key, set ANTHROPIC_MODEL to claude-haiku-5.5 instead of claude-opus-5-5; Opus and Sonnet need a paid plan.

settings.json instead of shell variables

Claude Code also reads environment variables from the env block of its settings file, ~/.claude/settings.json (all projects) or .claude/settings.json inside a project:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://freemodel.in",
    "ANTHROPIC_AUTH_TOKEN": "fm_your_key_here",
    "ANTHROPIC_MODEL": "claude-opus-5-5",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-5-5"
  }
}

Do not commit a project settings file that contains your key. Use the user-level file, or keep the key in a shell variable and only the other three values in the project file.

The opus and sonnet aliases

If you switch models inside Claude Code with the opus or sonnet aliases, Claude Code sends whatever model those aliases point to. Point them at listed models too:

export ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-5-5
export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-5

You can also start a session on a specific model with claude --model claude-sonnet-5.

Test the connection

First check the key and URL without Claude Code. This works on any account:

curl https://freemodel.in/v1/models \
  -H "x-api-key: fm_your_key_here"

Then send one Messages request in the format Claude Code uses (this model also works on a free key):

curl https://freemodel.in/v1/messages \
  -H "x-api-key: fm_your_key_here" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-haiku-5-5",
    "max_tokens": 64,
    "messages": [{"role": "user", "content": "Reply with the word ok."}]
  }'

Finally, a one-shot run of Claude Code itself in print mode:

claude -p "Reply with the word ok."

If all three answer, interactive sessions will work too.

Which model ids to use

UseModel idPlan
Main model, hard tasksclaude-opus-5-5Paid, 3× multiplier
Main model, everyday workclaude-sonnet-5Paid, 3× multiplier
Background (Haiku) model, or the main model on a free keyclaude-haiku-5-5Free plan at 1×; paid plans at 1.5× multiplier

The multiplier is how many plan tokens one model token uses: one token on a 3× model counts as three plan tokens. Input and output tokens both count. Ids are matched with dots or dashes, so claude-haiku-5.5 and claude-haiku-5-5 are the same model. Names of models FreeModel does not list (for example older Anthropic ids) are not mapped to another model; they return 404. The full list is on Models.

Agent sessions send large contexts on every turn, so token use adds up quickly. Watch it on the dashboard during your first long session.

Common errors and fixes

StatusWhat it meansFix
401Key missing, mistyped or revoked.Check ANTHROPIC_AUTH_TOKEN holds the full fm_… key. If ANTHROPIC_API_KEY is also set in your shell, remove it so only one key is sent.
403 upgrade_requiredA free account asked for a paid model. Only Claude Haiku 5.5 is on the free plan; the other Claude models are paid.Set ANTHROPIC_MODEL=claude-haiku-5.5, or buy a plan on Pricing.
404 model_not_foundThe model id is not one FreeModel lists. Often it is the background model.Set ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-5-5 and check ANTHROPIC_MODEL against Models.
402Plan tokens used up (tokens_exhausted). On the free plan this means the monthly free tokens are used up.Renew or upgrade. A failed or refused request is not charged.
429Requests per minute above your plan's limit (per key, per plan). A free account has 30 requests per minute, 400K tokens per minute (free_tpm_limit) and 3 requests at once, for the whole account.Wait for the time in the Retry-After header and retry, or move to a larger plan.
503The model is temporarily unavailable.Retry later or switch model; see Status.

If Claude Code still talks to Anthropic directly, the variables are not reaching it. Open a new terminal after editing your profile, and check that no other settings file overrides ANTHROPIC_BASE_URL.

Was this page helpful?
Still stuck?
Open a support ticket from your dashboard or message our support bot on Telegram.
Telegram supportGet help