Last updated: November 27, 2026
TL;DR
Claude Code talks to whatever answers at ANTHROPIC_BASE_URL, so you can point it at an LLM gateway, at OpenRouter, or at Ollama. Two variables do the work: the base URL, and a credential in ANTHROPIC_AUTH_TOKEN. Know the limits before you start. Anthropic's own docs say it "doesn't support routing Claude Code to non-Claude models through any gateway", OpenRouter says it is "only guaranteed to work with the Anthropic first-party provider", and Ollama says hosted web search and advanced tool controls "are not fully supported". So the dependable use is Claude models through a gateway or OpenRouter, and open models through Ollama are an experiment you run on your own terms. Everything below comes from Anthropic's LLM gateway docs, OpenRouter's Claude Code guide and Ollama's Claude Code page.
Which route fits
| Route | What it is | Models | Supported by Anthropic |
|---|---|---|---|
| Your organization's gateway | A proxy your company runs between Claude Code and the provider | Claude, through Anthropic or a cloud provider | Yes, for Claude models |
| OpenRouter | A hosted router with an Anthropic-compatible endpoint | Claude, plus other providers in its picker | Claude through the Anthropic provider is the guaranteed path |
| Ollama | Local or Ollama-hosted open models | Open models such as Qwen, GLM and Gemma | No: non-Claude models aren't supported |
Set the two variables
Every route uses the same pair. Anthropic's connect page puts it this way:
ANTHROPIC_BASE_URLpoints Claude Code at the gateway.- The credential goes in
ANTHROPIC_AUTH_TOKENwhen the service wants a bearer token, orANTHROPIC_API_KEYwhen it wants anx-api-keyheader. If you weren't told which, useANTHROPIC_AUTH_TOKEN.
Set them in your shell first, check they work, then move them into a settings file's env block so they reach every session, background agents included. Use ~/.claude/settings.json for all projects or .claude/settings.local.json for one. Never put a credential in a project's .claude/settings.json: the docs warn "that file is committed and shared with everyone who clones the repository". When both a shell export and a settings file set the same variable, the settings file wins. Our settings guide covers the file scopes.
Then start claude, send a message and run /status. The Anthropic base URL line should show your endpoint, and an Auth token or API key line should name the variable you set. If a Login method line names a claude.ai account instead, your credential didn't take.
OpenRouter
- Set the base URL to
https://openrouter.ai/api. OpenRouter warns that it is "nothttps://openrouter.ai/api/v1", because the path would double. - Put your OpenRouter key in
ANTHROPIC_AUTH_TOKEN. - Blank out
ANTHROPIC_API_KEY. Set it to an empty string: OpenRouter says this "keeps Claude Code from falling back to authenticating against Anthropic directly." - Pick models with the override variables if you want to. OpenRouter's example sets
ANTHROPIC_DEFAULT_SONNET_MODEL, and the same pattern works for the Opus, Haiku and Fable defaults andCLAUDE_CODE_SUBAGENT_MODEL. To list OpenRouter's models in/model, setCLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1.
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="your-openrouter-key"
export ANTHROPIC_API_KEY=""
If you were logged in to Anthropic before, run /logout. OpenRouter notes that "Claude Code is optimized for Anthropic models and may not work correctly with other providers", and that some picker entries route to non-Anthropic providers.
Ollama
Ollama's quick start is one command:
ollama launch claude
To set it up by hand, Ollama's guide sets ANTHROPIC_AUTH_TOKEN to ollama, ANTHROPIC_API_KEY to an empty string, and ANTHROPIC_BASE_URL to your local Ollama server on port 11434, then starts claude with a model name passed as a flag. Without a local install, Ollama's cloud works the same way: the base URL becomes https://ollama.com and the token is your OLLAMA_API_KEY.
Two settings decide whether it holds up:
- Context. For local models, Ollama says to "choose a model and set a 64k+ context window", and "for larger repositories, set the context length to 64k or higher."
- Tools. Claude Code works through tool calls, so Ollama says to choose a model that supports tools. Hosted web search and advanced tool controls aren't fully supported.
Ollama also notes that "Claude settings can override shell variables": if a settings file already sets a base URL, update it there and check with /status.
What changes when you route around Anthropic
- Your subscription stops applying. While a gateway credential is active, Anthropic's docs say requests carry it "in place of a developer's claude.ai subscription login, and the subscription's usage limits don't apply to them." You pay whoever owns that credential, per token. Setting only
ANTHROPIC_BASE_URLwithout a credential keeps your claude.ai login, and its limits, active. Our token usage guide covers how usage is counted. - Some features turn off. Remote Control and voice dictation are unavailable while
ANTHROPIC_AUTH_TOKEN,ANTHROPIC_API_KEYor anapiKeyHelperis active, and Remote Control is also off while the base URL points at a non-Anthropic host. - New features can break first. Claude Code adds capabilities with each release, and "a gateway that doesn't forward them breaks the corresponding features." If you see
400errors naming fields such ascontext_management, the docs suggestCLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1.
If your goal is Claude on your company's cloud account rather than another model, use the provider route instead: our Bedrock guide walks through it. For the rest of the command line, start at the Claude Code CLI guide.
Frequently asked questions
Can Claude Code use models other than Claude?
It can be pointed at them, through Ollama or a router such as OpenRouter, by setting ANTHROPIC_BASE_URL and a credential. Anthropic doesn't support routing Claude Code to non-Claude models through any gateway, and OpenRouter guarantees only its Anthropic provider, so expect gaps with other models.
How do I use Claude Code with Ollama?
Run ollama launch claude, or set ANTHROPIC_AUTH_TOKEN to ollama, ANTHROPIC_API_KEY to empty and ANTHROPIC_BASE_URL to your local Ollama server, then start claude with a model. Pick a model that supports tools and give it a 64k or larger context window.
What base URL does OpenRouter need for Claude Code?
https://openrouter.ai/api, not the /api/v1 path, which would double. Put your OpenRouter key in ANTHROPIC_AUTH_TOKEN and set ANTHROPIC_API_KEY to an empty string so Claude Code doesn't fall back to Anthropic.
Does my Claude subscription work through a gateway?
Not while a gateway credential is active. Requests then carry that credential instead of your claude.ai login, the subscription's limits don't apply, and usage is billed per token to whoever owns the credential.
How do I check which endpoint Claude Code is using?
Run /status. The Anthropic base URL line shows the endpoint, and the Auth token or API key line names the credential in use. A Login method line naming a claude.ai account means your gateway credential isn't active.
Stop guessing. Score your first workflow.
Score one workflow in about five minutes. Nine questions, a grade, and the specific gap holding it back - no call required.
Related Posts

Claude Code on Windows: native or WSL, and what to check
How to run Claude Code on Windows: native Windows, WSL 2 or WSL 1, what Git for Windows changes about the shell, the PowerShell tool and its limits, why sandboxing needs WSL 2, and the install errors to check first.

Claude Code output styles: change how it answers you
What Claude Code's output styles do: the four built-in styles (Proactive, Concise, Explanatory and Learning), how to switch with /output-style or a settings file, how to write a custom style with keep-coding-instructions, and when a hook, skill or CLAUDE.md fits better.

Claude Code and git: what it commits, and how to keep it in check
How Claude Code works with git: the git context it gets, the Co-Authored-By trailer and PR line it adds and how to change them, permission rules for commit and push and where they stop, and why git, not checkpoints, is your real undo.
