freebrainGet API Key
freebrainDOCS
FREEBRAIN / API REFERENCE

Use Claude Code with FreeBrain

Point Claude Code at the FreeBrain API with one command or your settings file, map Opus, Sonnet and Haiku to FreeBrain models, and check every call in the usage logs.

Claude Code talks to the Anthropic Messages API, so it works with FreeBrain once two settings change: the API address and the key. Your Claude Code installation, projects and commands stay as they are; requests go to FreeBrain and are charged per token from your FreeBrain balance.

From the 96-second quick start video, 0:38–0:48. Watch the whole video in the quickstart

Before you start

  • Claude Code installed and starting from your terminal (claude --version).
  • A FreeBrain API key from API keys and balance in your wallet.
  • The Claude model IDs you want. Claude models in the model catalog list the Anthropic Messages endpoint.
SettingValue
ANTHROPIC_BASE_URLhttps://api.thefreebrain.com (the host only, without /v1)
ANTHROPIC_AUTH_TOKENYour FreeBrain API key
Opus, Sonnet and Haikuclaude-opus-5-5, claude-sonnet-5-5 and claude-haiku-4-5-20251001

Try it with one command

Set both variables for a single run. Nothing is written to disk, which makes this a good first test:

ANTHROPIC_BASE_URL=https://api.thefreebrain.com ANTHROPIC_AUTH_TOKEN=YOUR_API_KEY claude

Ask Claude Code something short. If it answers, the key and the address are right.

On Windows PowerShell, set the variables first, then start Claude Code:

$env:ANTHROPIC_BASE_URL="https://api.thefreebrain.com"
$env:ANTHROPIC_AUTH_TOKEN="YOUR_API_KEY"
claude

Save it in your settings

To use FreeBrain every time, merge this env block into ~/.claude/settings.json (create the file if it does not exist), then start Claude Code with plain claude:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.thefreebrain.com",
    "ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5-5",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5-5",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-4-5-20251001"
  }
}

The three ANTHROPIC_DEFAULT_*_MODEL entries map Claude Code's Opus, Sonnet and Haiku choices to FreeBrain model IDs, so switching models inside Claude Code keeps working. The file holds your key in plain text: keep it out of shared folders and repositories.

If you would rather not edit files, CC Switch adds the same provider and model mapping in one click.

Choose a model

  • For one run, add the model ID to the command, for example ANTHROPIC_MODEL=claude-opus-5-5.
  • Inside Claude Code, /model switches between Opus, Sonnet and Haiku. With the settings above they resolve to the FreeBrain model IDs.

Every model has its own page in the catalog with its price per 1M input and output tokens, for example Claude Opus 5.5 and Claude Sonnet 5.5.

Check usage and cost

Every request Claude Code makes appears in the console's usage logs with its model, tokens, cost and timing. A single task can take several requests, so look at the logs after a session to see what it used.

If it does not work

SymptomWhat to check
401 or an authentication errorANTHROPIC_AUTH_TOKEN holds a FreeBrain key that is enabled, not expired and has quota left.
404ANTHROPIC_BASE_URL is https://api.thefreebrain.com, without /v1 or any other path.
Model not found or not availableUse the exact model ID from the catalog, and check the key's model restrictions.
Insufficient balance or quotaTop up in the wallet. The account balance and the key's quota must both allow the request.

For other errors, see troubleshooting.

On this page