Claude Code with DeepSeek
VerifiedRoute Claude Code to DeepSeek's Anthropic-compatible endpoint. DeepSeek officially documents this integration; you only need to set environment variables.
Last verified 2026-07-30 against official provider documentation.
About Claude Code
Claude Code is an agentic coding tool that runs in your terminal. It can be pointed at any Anthropic-compatible API endpoint through environment variables.
About DeepSeek
DeepSeek is a Chinese AI lab offering a competitive, low-cost API platform. It serves both an Anthropic-compatible endpoint (for Claude Code) and a native OpenAI Responses-compatible endpoint (for Codex CLI).
Key points
- DeepSeek officially documents the Anthropic-compatible endpoint at https://api.deepseek.com/anthropic.
- Use ANTHROPIC_AUTH_TOKEN with your DeepSeek key. Leave ANTHROPIC_API_KEY unset so Claude Code never falls back to Anthropic.
- CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 works around a known 400 "invalid user_id" bug on DeepSeek's endpoint.
- DeepSeek models only support vision partially; deepseek-v4-pro[1m] and deepseek-v4-flash are the current model names.
Set up Claude Code with DeepSeek
Choose your operating system, shell and model. The steps below update instantly and are generated locally in your browser.
deepseek-v4-flash is cheaper and faster; deepseek-v4-pro[1m] gives the best quality with a 1M context window.
Get an API key
Create a DeepSeek API key. Claude Code authenticates with it — it never leaves your machine.
Get a DeepSeek API key- Install Claude Code: npm install -g @anthropic-ai/claude-code
- Sign in, open API Keys, and create a key that starts with sk-. Top up your account balance; the API is pay-as-you-go.
Configure the connection
Set these environment variables in your shell profile.
- 1Add these lines to ~/.zshrc
- 2Run: source ~/.zshrc
export ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
export ANTHROPIC_AUTH_TOKEN="sk-"
# Leave ANTHROPIC_API_KEY unset
export ANTHROPIC_MODEL="deepseek-v4-pro[1m]"
export ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-v4-pro[1m]"
export ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-v4-pro[1m]"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-v4-pro[1m]"
export CLAUDE_CODE_SUBAGENT_MODEL="deepseek-v4-flash"
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC="1"
# Workaround for the known 400 "invalid user_id" bugPaste your API key where the placeholder is. Then open a new terminal window.
Verify the configuration
Run this command in a new terminal. A successful response confirms that Claude Code is talking to the configured endpoint.
claudeAfter Claude Code opens, type `/status` inside the session. The exact labels vary by version; confirm the auth token and base URL shown there.
Start using it
Launch Claude Code and send your first message.
- Type: Hello. What can you help me with today?
claudeTroubleshooting
Most issues fall into one of these categories. Each entry lists the cause, the fix, and how to verify it.
401 Unauthorized
Troubleshooting guideThe API key is wrong, expired, or the provider account has no balance.
Create a fresh key on the provider dashboard, then regenerate the config with the new key. If the key is stored in a shell profile, open a new terminal so the export takes effect.
Verify: Run `echo $ANTHROPIC_AUTH_TOKEN` (or `echo $DEEPSEEK_API_KEY` / `$OPENROUTER_API_KEY` for Codex) and confirm the value looks like a valid key.
404 Not Found
Troubleshooting guideThe base URL is wrong (typo, extra path segment) or, on Codex, the wire protocol does not match what the provider serves.
Copy the exact base URL from this page. For Codex, keep `wire_api = "responses"` with OpenRouter; if DeepSeek returns 404 on /responses, try removing the wire_api line to match the endpoint your provider serves.
Verify: Re-run the verify command from step 3 and check the error path: it should end in /anthropic (Claude Code) or /responses (Codex).
Model Not Found
Troubleshooting guideThe model name does not exist on the provider, or the agent cached an old login that overrides the environment.
Pick a model from the provider list on this page. For Claude Code with OpenRouter, run `/logout` inside Claude Code, then relaunch — a cached Anthropic login overrides your environment variables.
Verify: Confirm ANTHROPIC_API_KEY is set to an empty string (OpenRouter) or unset (DeepSeek), then run `claude /status` again.
Rate Limit / Insufficient Quota
Troubleshooting guideThe provider limits requests per minute, or the account balance ran out.
Wait for the limit window, top up the account balance, or switch to a cheaper model. OpenRouter users can raise free-tier limits by adding credits.
Verify: Check the provider dashboard (balance and usage page) for the rejected request.
Network Error / Connection Failed
Troubleshooting guideThe machine cannot reach the provider endpoint, or an intercepting proxy rewrites the request.
Check DNS and connectivity to the base URL, review proxy and firewall settings, and retry. Use the exact endpoint from this page; third-party mirrors are not supported.
Verify: Run `curl -I <base url>` (e.g. `curl -I https://api.deepseek.com/anthropic`) and confirm a reachable response.
Timeout / Request Timed Out
Troubleshooting guideA slow model, a long prompt, or a restricted network to the provider region.
Retry the request, shorten the prompt, or switch to a faster model. Region-based connectivity issues may require a different network or a provider with closer servers.
Verify: Run the verify command again when the network is idle and confirm it completes.
Older Claude Code versions fail
Very old Claude Code versions do not read ANTHROPIC_BASE_URL.
Update with `npm install -g @anthropic-ai/claude-code` and relaunch.
Verify: `claude --version` should report a current release.
Frequently asked questions
Does my Claude Pro or Max subscription work with DeepSeek?
No. This setup authenticates with a DeepSeek API key and bills to your DeepSeek account. Anthropic subscriptions cannot be combined with a third-party endpoint.
Why do I see "400 Invalid user_id"?
A known DeepSeek endpoint bug affects some Claude Code versions. Setting CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 (included in the generated config) is the confirmed workaround.
Is my code sent to DeepSeek?
Yes — requests go to DeepSeek's API like any other backend. Review DeepSeek's data policy before sending sensitive code. This site never sees your key or your prompts.