Claude Code
Point the Claude Code CLI at Blackfuel's Anthropic-compatible endpoint and run it on an open-source model
Claude Code is Anthropic's CLI agent. It speaks the Anthropic Messages API, so it runs against any Anthropic-compatible gateway. Blackfuel exposes one at https://api.blackfuel.ai, which lets you drive Claude Code with open-source models served by Blackfuel — with transparent per-token pricing and no provider lock-in.
Prerequisites
- A Blackfuel API key (get one here) — it starts with
bf_. - The
claudeCLI installed:npm install -g @anthropic-ai/claude-code, or see the Claude Code install guide.
Configure
Claude Code is configured through environment variables. Set these before launching claude:
export BLACKFUEL_API_KEY=bf_mykey_xxxxxx
export ANTHROPIC_BASE_URL=https://api.blackfuel.ai
export ANTHROPIC_AUTH_TOKEN="$BLACKFUEL_API_KEY"
# Map each Claude Code model tier to a Blackfuel model ID
export ANTHROPIC_DEFAULT_FABLE_MODEL=moonshotai/Kimi-K3
export ANTHROPIC_DEFAULT_OPUS_MODEL=zai-org/GLM-5.2
export ANTHROPIC_DEFAULT_SONNET_MODEL=deepseek-ai/DeepSeek-V4-Flash-0731
export ANTHROPIC_DEFAULT_HAIKU_MODEL=google/gemma-4-31B-it
export CLAUDE_CODE_SUBAGENT_MODEL=deepseek-ai/DeepSeek-V4-Flash-0731
# Leaner prompts and higher prompt-cache hit rates
export ENABLE_TOOL_SEARCH=true
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=600000
export CLAUDE_CODE_ATTRIBUTION_HEADER=0What each variable does:
| Variable | Purpose |
|---|---|
ANTHROPIC_BASE_URL | Points Claude Code at Blackfuel's Anthropic-compatible endpoint. No /v1 suffix — the CLI appends the path. |
ANTHROPIC_AUTH_TOKEN | Your Blackfuel API key. Use this variable, not ANTHROPIC_API_KEY. |
ANTHROPIC_DEFAULT_FABLE_MODEL | The Blackfuel model ID the fable tier resolves to. |
ANTHROPIC_DEFAULT_OPUS_MODEL | The Blackfuel model ID the opus tier resolves to, and the one plan mode runs on. |
ANTHROPIC_DEFAULT_SONNET_MODEL | The Blackfuel model ID the sonnet tier resolves to — Claude Code's default for everyday work. |
ANTHROPIC_DEFAULT_HAIKU_MODEL | The Blackfuel model ID for the haiku tier, which Claude Code uses for background work such as conversation summarization. |
CLAUDE_CODE_SUBAGENT_MODEL | The Blackfuel model ID Claude Code runs subagents and agent teams on. |
ENABLE_TOOL_SEARCH | Set to true to keep MCP tool definitions deferred, which keeps the prompt lean on long agent sessions. Claude Code loads them upfront by default whenever ANTHROPIC_BASE_URL points somewhere other than Anthropic. |
CLAUDE_CODE_MAX_CONTEXT_TOKENS | Sets the context window Claude Code assumes for the routed model, which drives its context gauge and auto-compaction. Claude Code applies this itself; it is not discovered from the API. See the callout below for the value to use. |
CLAUDE_CODE_ATTRIBUTION_HEADER | Set to 0 to omit the attribution block from the system prompt, which raises prompt-cache hit rates — visible as cached input tokens on your requests. |
Set CLAUDE_CODE_MAX_CONTEXT_TOKENS to roughly 60% of the routed model's context window, never the full window — 600000 for a 1M-token model. Claude Code's client-side token estimate counts differently from the model's tokenizer, so a window matched 1:1 lets long sessions fail with 400 context-length errors before auto-compaction fires.
Claude Code routes different jobs to different model tiers, and this setup maps each tier to a Blackfuel model ID. Per-token pricing and each model's context window are in Available Models. Swap any tier for another model ID there; to run a single model everywhere instead, set ANTHROPIC_MODEL to one model ID and drop the per-tier variables.
Persist the configuration
The export approach applies only to the current shell. To make the configuration permanent, pick one of these three approaches.
Option 1: Shell profile
Add the export lines to your shell profile so they apply to every interactive session:
# ~/.bashrc or ~/.zshrc
export BLACKFUEL_API_KEY=bf_mykey_xxxxxx
export ANTHROPIC_BASE_URL=https://api.blackfuel.ai
export ANTHROPIC_AUTH_TOKEN="$BLACKFUEL_API_KEY"
export ANTHROPIC_DEFAULT_FABLE_MODEL=moonshotai/Kimi-K3
export ANTHROPIC_DEFAULT_OPUS_MODEL=zai-org/GLM-5.2
export ANTHROPIC_DEFAULT_SONNET_MODEL=deepseek-ai/DeepSeek-V4-Flash-0731
export ANTHROPIC_DEFAULT_HAIKU_MODEL=google/gemma-4-31B-it
export CLAUDE_CODE_SUBAGENT_MODEL=deepseek-ai/DeepSeek-V4-Flash-0731
export ENABLE_TOOL_SEARCH=true
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=600000
export CLAUDE_CODE_ATTRIBUTION_HEADER=0Reload it (source ~/.bashrc) or open a new terminal before launching claude.
Option 2: Claude Code settings file
Claude Code reads an env block from its settings file at startup, so you can persist the variables there instead of in your shell. Edit ~/.claude/settings.json, add the keys to the existing env object, and replace bf_mykey_xxxxxx with your own key — a JSON file cannot read BLACKFUEL_API_KEY from the shell:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.blackfuel.ai",
"ANTHROPIC_AUTH_TOKEN": "bf_mykey_xxxxxx",
"ANTHROPIC_DEFAULT_FABLE_MODEL": "moonshotai/Kimi-K3",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "zai-org/GLM-5.2",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-ai/DeepSeek-V4-Flash-0731",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "google/gemma-4-31B-it",
"CLAUDE_CODE_SUBAGENT_MODEL": "deepseek-ai/DeepSeek-V4-Flash-0731",
"ENABLE_TOOL_SEARCH": "true",
"CLAUDE_CODE_MAX_CONTEXT_TOKENS": "600000",
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0"
}
}Every Claude Code session on the machine then routes to Blackfuel automatically — no shell exports needed. The changes take effect on the next session start. This is the option to choose if you want all sessions to use Blackfuel regardless of which shell launched them.
Option 3: A bfclaude launcher function
If you also run Claude Code against your Anthropic account, wrap the Blackfuel configuration in a shell function instead of overriding it globally. bfclaude launches Claude Code on Blackfuel, while plain claude stays on Anthropic:
# ~/.bashrc or ~/.zshrc
export BLACKFUEL_API_KEY=bf_mykey_xxxxxx
bfclaude() {
ANTHROPIC_BASE_URL=https://api.blackfuel.ai \
ANTHROPIC_AUTH_TOKEN="$BLACKFUEL_API_KEY" \
ANTHROPIC_DEFAULT_FABLE_MODEL=moonshotai/Kimi-K3 \
ANTHROPIC_DEFAULT_OPUS_MODEL=zai-org/GLM-5.2 \
ANTHROPIC_DEFAULT_SONNET_MODEL=deepseek-ai/DeepSeek-V4-Flash-0731 \
ANTHROPIC_DEFAULT_HAIKU_MODEL=google/gemma-4-31B-it \
CLAUDE_CODE_SUBAGENT_MODEL=deepseek-ai/DeepSeek-V4-Flash-0731 \
ENABLE_TOOL_SEARCH=true \
CLAUDE_CODE_MAX_CONTEXT_TOKENS=600000 \
CLAUDE_CODE_ATTRIBUTION_HEADER=0 \
claude "$@"
}Run bfclaude to start a Blackfuel-backed session; the variables apply only to that process, so your default claude is untouched.
Your Blackfuel key is a secret. Avoid committing ~/.claude/settings.json or your shell profile to a shared dotfiles repo, and restrict the file to your own user; loading the key from a secrets manager keeps it off disk entirely.
Run
claudeYou're now in an interactive Claude Code session backed by Blackfuel, with the tier mapping above deciding which Blackfuel model ID answers each request.
Tips
- Switch models: change the
ANTHROPIC_DEFAULT_*_MODELvalues to any model ID from Available Models. For EU data residency, use the:eumodel ID listed under EU-Hosted Models. - Verify a model is live: call
GET /v1/modelsto confirm the model ID is served before pointing Claude Code at it.
Troubleshooting
| Symptom | Fix |
|---|---|
401 Unauthorized | ANTHROPIC_AUTH_TOKEN is missing, wrong, or revoked. Re-check the key in the console. |
| A Blackfuel model is missing from Claude Code's model picker | Claude Code lists a non-Anthropic model only when its anthropic_family_tier is set. Point an ANTHROPIC_DEFAULT_*_MODEL variable at the model ID to use it anyway. |
404 model not found | One of the model variables points at a model ID that isn't served. Confirm each value via GET /v1/models. |
404 on /v1/messages/count_tokens | Claude Code handles it by falling back to a character-based estimate of context usage. |
413 Payload Too Large | Run /compact; see Request Limits. |
429 with rate_limit_exceeded | The request exceeded your Serverless quota; Claude Code retries after the retry-after seconds, or shows the error when the wait is over a minute; see Rate Limits. |
429 with overloaded | Claude Code retries automatically with backoff; see Rate Limit Errors. |
| Requests still hitting Anthropic | ANTHROPIC_BASE_URL is unset or has a trailing /v1. Set it to exactly https://api.blackfuel.ai. |
Next steps
- Available Models — full catalog, pricing, and EU variants
- Migrate from OpenAI — point any OpenAI-compatible tool at Blackfuel