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.
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.
| Setting | Value |
|---|---|
ANTHROPIC_BASE_URL | https://api.thefreebrain.com (the host only, without /v1) |
ANTHROPIC_AUTH_TOKEN | Your FreeBrain API key |
| Opus, Sonnet and Haiku | claude-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 claudeAsk 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"
claudeSave 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,
/modelswitches 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
| Symptom | What to check |
|---|---|
401 or an authentication error | ANTHROPIC_AUTH_TOKEN holds a FreeBrain key that is enabled, not expired and has quota left. |
404 | ANTHROPIC_BASE_URL is https://api.thefreebrain.com, without /v1 or any other path. |
| Model not found or not available | Use the exact model ID from the catalog, and check the key's model restrictions. |
| Insufficient balance or quota | Top up in the wallet. The account balance and the key's quota must both allow the request. |
For other errors, see troubleshooting.
FreeBrain API Quickstart
Make your first FreeBrain chat request with cURL or Python. Configure your API key and base URL, choose an available model, and check the response.
Use Codex with FreeBrain
Add FreeBrain as a model provider in the Codex CLI config.toml, keep the key in an environment variable, and run Codex on GPT models through the Responses API.