Disclosure: I run UberLLM; the examples use its API, but the setup works the same with any compatible provider where noted.
Claude Code talks to the Anthropic Messages API. Any endpoint that speaks that API can serve it: a model maker's own Anthropic-compatible endpoint, a company gateway, or a marketplace. I wrote earlier about mapping Claude Code to DeepSeek, GLM or Kimi. This post is the plumbing underneath: where the address and key go, which setting wins when two disagree, how compaction behaves on a non-Claude model, and how to check and undo it.
1. A quick test in one terminal
Two environment variables are enough:
export ANTHROPIC_BASE_URL=https://api.uberllm.dev
export ANTHROPIC_AUTH_TOKEN=ull_your_key
claude
Windows PowerShell:
$env:ANTHROPIC_BASE_URL = "https://api.uberllm.dev"
$env:ANTHROPIC_AUTH_TOKEN = "ull_your_key"
claude
Note the address: the Anthropic-style base URL has no /v1 at the end (the OpenAI-style one, for other tools, is https://api.uberllm.dev/v1). Use your own provider's address and key here; nothing else changes.
This lasts only for the current terminal. For daily use, move it into a settings file.
2. Keep the key out of settings files with apiKeyHelper
Instead of pasting the key into JSON, save it to a file only you can read:
mkdir -p ~/.uberllm && chmod 700 ~/.uberllm
printf '%s\n' 'ull_your_key' > ~/.uberllm/key && chmod 600 ~/.uberllm/key
Then point Claude Code at it:
{
"apiKeyHelper": "cat ~/.uberllm/key",
"env": {
"ANTHROPIC_BASE_URL": "https://api.uberllm.dev"
}
}
Where that block goes decides its scope:
| Scope | File |
|---|---|
| Every project | ~/.claude/settings.json |
| One project | <project>/.claude/settings.local.json |
A one-project setup leaves your other projects on your normal Anthropic plan.
How the helper behaves:
- Claude Code runs
apiKeyHelperand sends what it prints as bothAuthorization: Bearerandx-api-key, which is why it works with gateways that read either header. - It keeps the answer for five minutes.
CLAUDE_CODE_API_KEY_HELPER_TTL_MSchanges that. - If requests fail with
Your apiKeyHelper script is failing, the key file is missing or unreadable.
The key never lands in a settings file, so it does not end up in a backup, a dotfiles repository or a screen share. The pattern is the same for any provider's key.
One more trap: Claude Code reads a project's own settings only after you trust that folder. On a computer where Claude Code was never set up, put the block in ~/.claude/settings.json first, or a brand-new install can still ask you to log in.
3. Which setting wins
Settings files are read in this order, first one wins:
- Managed settings (set by your company, if any)
claude --settings <file><project>/.claude/settings.local.json<project>/.claude/settings.json~/.claude/settings.json
A variable in a settings file's env block beats the same variable in your shell in most sessions. Two exceptions cause most "why is it still using my Anthropic login?" reports:
-
The key. Claude Code uses
ANTHROPIC_AUTH_TOKENfirst, thenANTHROPIC_API_KEY, thenapiKeyHelper. A token exported in your shell replaces the saved key. -
The model.
/modelin the session wins, thenclaude --model, thenANTHROPIC_MODEL, then themodelsetting. A shellANTHROPIC_MODELbeats themodelsetting.
The fix is boring: once the settings file is in place, remove every ANTHROPIC_* variable from your shell and your shell profile (~/.zshrc, ~/.bashrc).
4. Models: keep Claude, or map every slot
By default nothing is pinned. Claude Code asks for its own model names (opus, sonnet, haiku), and a gateway that serves Claude models answers them.
To run on other models, Claude Code has five slots, set in the env block:
| Variable | What it sets |
|---|---|
ANTHROPIC_MODEL |
The model the session starts on |
ANTHROPIC_DEFAULT_OPUS_MODEL |
What opus means |
ANTHROPIC_DEFAULT_SONNET_MODEL |
What sonnet means |
ANTHROPIC_DEFAULT_HAIKU_MODEL |
What haiku means; also used for background work such as titles and summaries |
CLAUDE_CODE_SUBAGENT_MODEL |
The model subagents run on |
Map every one. A slot left unset keeps asking for a Claude model; on a multi-model gateway that request is served and billed at Claude prices. The model must also support tool calls, since that is how Claude Code edits files and runs commands. On UberLLM a request with tools sent to a model that cannot call them is refused with 400 tools_not_supported; GET https://api.uberllm.dev/v1/models marks supports_tools on each chat model.
5. Context size and compaction
Claude Code knows the context size of Claude models only. For any other model it assumes 200,000 tokens and compacts the conversation before that.
- If the model has a 1-million-token context, add
[1m]to the end of its id, for example"ANTHROPIC_MODEL": "deepseek/deepseek-v4-pro[1m]". - For any other size, set
CLAUDE_CODE_MAX_CONTEXT_TOKENSto the model's real context, for example"400000". - To choose when it compacts:
autoCompactWindow(orCLAUDE_CODE_AUTO_COMPACT_WINDOW) takes a number of tokens from 100,000 to 1,000,000.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE(1 to 100) compacts earlier, at that share of the window.autoCompactEnabled: falseturns it off.
Do not round up. A context set larger than the model has makes requests fail once the conversation outgrows the model.
6. What changes when you leave Anthropic's endpoint
These apply to any third-party endpoint, not just mine:
-
Your claude.ai login is not used. Features that need it, such as claude.ai connectors,
/scheduleand Remote Control, are not available in that session. -
The cost Claude Code shows is not your bill. It is worked out on your computer from Anthropic's list prices, and shows nothing useful for other models. Read your provider's usage page instead. (On UberLLM, a status-line script can show your balance under the prompt; it reads
GET /v1/balanceat most once a minute.) - Your code goes to whoever serves the model. Everything the session reads is sent to the model. On a marketplace like UberLLM that means third-party providers, so do not use it in a repository that holds secrets, credentials or customer data.
7. Check it
Start Claude Code and run /status: the API address should be your provider's. Then call the Messages API directly with the same key:
curl https://api.uberllm.dev/v1/messages \
-H "Authorization: Bearer $(cat ~/.uberllm/key)" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model":"claude-haiku-4-5","max_tokens":16,"messages":[{"role":"user","content":"ping"}]}'
If that answers and Claude Code does not, the problem is in the settings order (section 3), not the endpoint.
8. Undo it
Remove apiKeyHelper and the ANTHROPIC_* entries from the settings file, and unset any you exported. Claude Code goes back to your Anthropic login on the next start.
If you used one of UberLLM's installers, each has its own undo:
# installed with: curl -fsSL https://uberllm.dev/install/claude-code.sh | sh
curl -fsSL https://uberllm.dev/install/claude-code.sh | sh -s -- --uninstall
# installed with: npx uberllm init
npx uberllm init --undo
Uninstalling stops using the key; it does not revoke it. Delete the key in your provider's dashboard for any computer you no longer trust.
UberLLM is prepaid credit with no free tier, so for a first test with one model family, a maker's own Anthropic-compatible endpoint is also a fine place to start. Sections 2 to 8 apply there too.
Sources
- UberLLM docs, Claude Code: https://uberllm.dev/docs/claude-code
- UberLLM docs, Errors (
tools_not_supported): https://uberllm.dev/docs/errors - UberLLM docs, Models and routing (
/v1/modelsfields): https://uberllm.dev/docs/models-and-routing - Live model list: https://api.uberllm.dev/v1/models
Top comments (0)