Use Claude Code with DeepSeek, Ollama or other models
Point Claude Code at a vendor's Anthropic-compatible endpoint with ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN, and name the vendor's models in ANTHROPIC_MODEL and the ANTHROPIC_DEFAULT_*_MODEL variables. It works, but Anthropic does not support it, one session talks to one vendor, and features such as prompt caching can be silently ignored.
Updated
Den här sidan är skriven på engelska. Termerna den förklarar är de som söks på engelska, och en översatt fackterm är en annan term.
How it works
Claude Code sends every request in Anthropic's Messages format to whatever ANTHROPIC_BASE_URL names. A vendor that serves that format can stand in for Anthropic, and Claude Code cannot tell the difference until a request uses something the vendor has not implemented. Anthropic's gateway documentation is explicit that this is unsupported: it "doesn't support routing Claude Code to non-Claude models through any gateway."
Endpoints that work with it
| Vendor | ANTHROPIC_BASE_URL | Notes |
|---|---|---|
| DeepSeek | https://api.deepseek.com/anthropic | Official guide. claude-opus* names map to V4 Pro, everything else to V4 Flash |
| Ollama (local) | http://localhost:11434 | Official integration from Ollama 0.14; ollama launch claude sets it up |
| Kimi (Moonshot) | https://api.moonshot.ai/anthropic | Official guide; kimi-k2.7-code needs thinking switched on |
| Z.ai GLM | https://api.z.ai/api/anthropic | Official guide |
| Alibaba Coding Plan | https://coding-intl.dashscope.aliyuncs.com/apps/anthropic | Official guide; pay-as-you-go endpoints are per region |
| OpenRouter | https://openrouter.ai/api | Only guaranteed with Anthropic as the upstream provider; set ANTHROPIC_API_KEY to an empty string |
| LM Studio (local) | http://localhost:1234 | Official integration page |
Example: DeepSeek
export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
export ANTHROPIC_AUTH_TOKEN=<your DeepSeek API key>
export ANTHROPIC_MODEL=deepseek-flash[1m]
export ANTHROPIC_DEFAULT_OPUS_MODEL=deepseek-flash[1m]
export ANTHROPIC_DEFAULT_SONNET_MODEL=deepseek-flash[1m]
export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-flash
export CLAUDE_CODE_SUBAGENT_MODEL=deepseek-flash
claudeThese are the values from DeepSeek's own Claude Code page. Set every tier, not just ANTHROPIC_MODEL: a tier left unset still sends a Claude model name, which the endpoint does not know, and the background tasks and subagents that use it fail.
Example: a local model with Ollama
ollama launch claudeThat configures Claude Code for you. By hand, it is three variables and a model that supports tool calling:
export ANTHROPIC_BASE_URL=http://localhost:11434
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
claude --model qwen3.5Ollama recommends a context window of 64K tokens or more for larger repositories; a coding agent re-sends the conversation on every turn and a small window fills fast.
What breaks
- Prompt caching markers. DeepSeek and Ollama ignore Anthropic's
cache_control, and Kimi honours it only at the top level. Nothing errors; whether you still get cache pricing depends on the vendor's own caching. - Switching vendors. Claude Code reads one
ANTHROPIC_BASE_URL, so moving from DeepSeek to Claude means restarting with different settings, not a/modelcommand. - Web search. Claude Code's WebSearch tool runs on Anthropic's servers. DeepSeek says its endpoint supports it; Ollama says hosted web search is not fully supported.
- Unknown request fields. Claude Code treats an unrecognised model name as a current Claude model and sends thinking and effort fields that some endpoints reject with a 400.
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1strips beta fields, at the cost of MCP tool search. - Account features. Remote Control and voice dictation are unavailable while a gateway credential is set.
- Stale credentials. A leftover
ANTHROPIC_API_KEY, a saved login or oldenvvalues insettings.jsoncan override the setup;/statusshows which one is in use.
When a model-agnostic agent fits better
If you want one vendor at a time and already work in Claude Code, the settings above are enough. If you want Claude, DeepSeek and a local model inside the same task, OHarness does that natively: each provider is built in, the conversation is stored in a vendor-neutral format, and /model switches across vendors without a restart. OHarness vs Claude Code compares the two directly.
npm install -g oharnessoharness -m deepseek/deepseek-v4-flashThen, mid-session, /model anthropic/claude-sonnet-5 for the step that needs it, and back again.
Sources
- Anthropic: LLM gateways and environment variables
- DeepSeek: Claude Code and Anthropic API compatibility
- Ollama: Claude Code and Anthropic compatibility
- Kimi: Claude Code, Z.ai: Claude Code, Alibaba Model Studio: Claude Code
- OpenRouter: Claude Code, LM Studio: Claude Code
- Checked 2026-09-25. Vendors change these endpoints; their pages are the authority.
Common questions
Can Claude Code use DeepSeek models?
Yes, unofficially. DeepSeek serves an Anthropic-compatible endpoint at https://api.deepseek.com/anthropic: set ANTHROPIC_BASE_URL to it, ANTHROPIC_AUTH_TOKEN to a DeepSeek API key, and the model variables to DeepSeek's model names. Anthropic does not support non-Claude models in Claude Code.
Can Claude Code run a local model with Ollama?
Yes. Ollama 0.14 and later serve the Anthropic Messages format, and `ollama launch claude` configures Claude Code to use it. Pick a model that supports tool calling and give it a context window of 64K tokens or more.
Can Claude Code switch between Claude and DeepSeek in one session?
No. Claude Code reads a single ANTHROPIC_BASE_URL, so one Claude Code session talks to one vendor. OHarness switches between Anthropic, DeepSeek, OpenAI, Gemini and local models mid-session with /model.
Why does Claude Code return 400 errors with another vendor's endpoint?
Claude Code assumes an unrecognised model is a current Claude model and sends fields such as adaptive thinking and effort that some endpoints reject. Setting every ANTHROPIC_DEFAULT_*_MODEL variable to the vendor's names, and CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1, removes most of them.