Back to Blog

Claude Code with other models: Ollama, OpenRouter and LLM gateways

Alex Kim
6 min read
Claude Code with other models: Ollama, OpenRouter and LLM gateways

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

RouteWhat it isModelsSupported by Anthropic
Your organization's gatewayA proxy your company runs between Claude Code and the providerClaude, through Anthropic or a cloud providerYes, for Claude models
OpenRouterA hosted router with an Anthropic-compatible endpointClaude, plus other providers in its pickerClaude through the Anthropic provider is the guaranteed path
OllamaLocal or Ollama-hosted open modelsOpen models such as Qwen, GLM and GemmaNo: 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_URL points Claude Code at the gateway.
  • The credential goes in ANTHROPIC_AUTH_TOKEN when the service wants a bearer token, or ANTHROPIC_API_KEY when it wants an x-api-key header. If you weren't told which, use ANTHROPIC_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

  1. Set the base URL to https://openrouter.ai/api. OpenRouter warns that it is "not https://openrouter.ai/api/v1", because the path would double.
  2. Put your OpenRouter key in ANTHROPIC_AUTH_TOKEN.
  3. 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."
  4. 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 and CLAUDE_CODE_SUBAGENT_MODEL. To list OpenRouter's models in /model, set CLAUDE_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_URL without 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_KEY or an apiKeyHelper is 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 400 errors naming fields such as context_management, the docs suggest CLAUDE_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.

#claude-code#Ollama#OpenRouter#LLM Gateway#Models
Free assessment

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.