Claude Code with OpenRouter and DeepSeek: Setup, Routes, and First-Error Fixes
To use DeepSeek in Claude Code, choose OpenRouter's gateway or DeepSeek's Anthropic-compatible endpoint. Each needs its own key and model names; a successful reply alone does not confirm the model or coding-tool compatibility.
On this page

You can use DeepSeek in Claude Code through OpenRouter or DeepSeek's direct Anthropic-compatible API. OpenRouter uses https://openrouter.ai/api, an OpenRouter key, and a namespaced model such as deepseek/deepseek-v4.1-flash. DeepSeek direct uses https://api.deepseek.com/anthropic, a DeepSeek key, and the current deepseek-flash model name. A local Claude Code Router (CCR) or other proxy is optional for these documented connections.
Choose one connection below, launch a fresh terminal session with its configuration, and check a small request before giving the agent a repository task. The examples reflect the providers' documentation checked on October 6, 2026; they are configuration templates, not reports of live account, billing, or tool tests.
| Connection | Endpoint and key | Current Flash selection | Choose it when |
|---|---|---|---|
| DeepSeek through OpenRouter | OpenRouter endpoint and OpenRouter key | deepseek/deepseek-v4.1-flash | You want OpenRouter's model catalog, provider routing, and usage records |
| DeepSeek direct | DeepSeek Anthropic-compatible endpoint and DeepSeek key | deepseek-flash[1m] for the main model in DeepSeek's CLI recipe | You want to use DeepSeek's own API and account balance |
| Local router or proxy | The adapter's documented endpoint and authentication | Whatever its configuration maps upstream | You need additional routing or protocol conversion that the direct connection does not provide |
The first two rows follow OpenRouter's Claude Code guide, its current model catalog, and DeepSeek's Claude Code guide. Do not interchange the two keys or copy a model name from one service into the other.
Check Your Existing Claude Code Configuration First
These steps assume the terminal CLI is already installed and you are allowed to use the selected service. For installation, use the current Claude Code setup documentation. You do not need to install a local router merely to follow either provider's direct recipe.
Before changing anything, note the current authentication, model, and configuration sources shown by /status in your existing session. Keep that information so you can return to the previous setup. Do not record keys in screenshots or notes.
A few configuration conflicts can survive a new shell:
- A loaded settings file's
envvalue can override the same inherited shell variable. An oldANTHROPIC_BASE_URLor token in settings can therefore defeat an otherwise correct export. - Bedrock, Google Cloud, or Foundry selectors choose their own authentication paths. A signed-in Claude apps gateway and organization-managed restrictions have additional precedence rules.
- A saved model selection may belong to the previous service. Changing the endpoint does not automatically choose a compatible model.
Check the applicable settings source if the resulting session is unexpected; /status lists loaded sources but does not identify the winning value of every setting. The broader Claude Code API configuration guide explains these scope and authentication branches. The current authentication and gateway connection references describe the policy exceptions.
The Bash examples below use a subshell, so their exports disappear when that subshell finishes. They do not edit settings, revoke keys, or delete a saved login. Run them in Bash, including on macOS if your usual shell is Zsh. They accept a key without writing its literal value into the command you paste; the input still becomes a credential in the launched process's environment.
OpenRouter Setup For Claude Code
Use an API key from your OpenRouter account, with the credits and model access needed for your test. Claude subscription usage does not supply OpenRouter credits. OpenRouter's integration accepts Claude Code's Anthropic Messages requests directly, so this example needs no local conversion proxy.
This Bash template pins DeepSeek V4.1 Flash for the main session and maps the Opus, Sonnet, Haiku, and subagent choices to the same OpenRouter model:
(
unset CLAUDE_CODE_USE_BEDROCK CLAUDE_CODE_USE_VERTEX CLAUDE_CODE_USE_FOUNDRY
read -r -s -p "OpenRouter API key: " OPENROUTER_API_KEY
printf '\n'
test -n "$OPENROUTER_API_KEY" || exit 1
export ANTHROPIC_BASE_URL="https://openrouter.ai/api"
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
export ANTHROPIC_API_KEY=""
export ANTHROPIC_MODEL="deepseek/deepseek-v4.1-flash[1m]"
export ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek/deepseek-v4.1-flash[1m]"
export ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek/deepseek-v4.1-flash[1m]"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek/deepseek-v4.1-flash"
export CLAUDE_CODE_SUBAGENT_MODEL="deepseek/deepseek-v4.1-flash"
claude --model "$ANTHROPIC_MODEL"
)The empty ANTHROPIC_API_KEY follows OpenRouter's documented bearer-token setup. OPENROUTER_API_KEY is defined before Bash expands it into ANTHROPIC_AUTH_TOKEN; installing Claude Code does not automatically load an arbitrary .env file.
OpenRouter strips [1m] before routing. The suffix tells Claude Code to use a larger context assumption; it is not part of the catalog ID and does not grant extra capacity. In the October 6 catalog snapshot, deepseek/deepseek-v4.1-flash advertises a 1,048,576-token context and tools/tool_choice parameters. That metadata does not establish your account's provider access or the quality of a real Claude Code tool session. OpenRouter integration and context handling.
Inside the new Claude Code session, enter:
/statusConfirm that the expected OpenRouter base URL and token authentication are active. If an old Anthropic login is still causing a conflict, OpenRouter documents /logout as a recovery option. Use it only when you intend to remove that cached login: it is not a required first step for every user, and it does not clear a real shell API key. Resolve settings or policy conflicts at their source rather than deleting credential stores.
Next, send a tiny prompt such as “Reply with OK only; do not use tools.” It makes a real model request and can consume credits. Match its time and model against OpenRouter's activity, including the provider information available for that request. Then follow the tool check below before using it for code changes.
Why DeepSeek Is Missing From /model
You can pin the full model name as above without relying on the picker. To enable OpenRouter's gateway model discovery for later launches, add this to the same Bash configuration before claude:
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1Restart Claude Code after enabling discovery. OpenRouter supplies a curated subset, not its entire catalog, so a missing picker entry does not prove that a model cannot be requested. If discovery is unavailable or disabled, Claude Code also supports ANTHROPIC_CUSTOM_MODEL_OPTION for a single custom picker entry. Neither discovery nor a custom entry bypasses availableModels restrictions or validates upstream model access. OpenRouter discovery and Claude Code model options.
When changing models interactively, remember that entering /model <name> or confirming with Enter saves the user default. The picker's s action selects for the current session only. For a temporary connection test, the explicit launch flag is easier to keep separate from a saved default.
DeepSeek Direct Setup For Claude Code
Use a key from your DeepSeek API account. The endpoint below is the Anthropic-compatible API; do not replace it with an OpenAI chat-completions URL. The CLI recipe sends the key as ANTHROPIC_AUTH_TOKEN, while DeepSeek's separate Anthropic SDK example uses API-key authentication. Follow the recipe for the client you are configuring.
This Bash template follows the current DeepSeek Claude Code configuration, including its model roles, effort level, and compaction window:
(
unset ANTHROPIC_API_KEY
unset CLAUDE_CODE_USE_BEDROCK CLAUDE_CODE_USE_VERTEX CLAUDE_CODE_USE_FOUNDRY
read -r -s -p "DeepSeek API key: " DEEPSEEK_API_KEY
printf '\n'
test -n "$DEEPSEEK_API_KEY" || exit 1
export ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
export ANTHROPIC_AUTH_TOKEN="$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"
export CLAUDE_CODE_EFFORT_LEVEL="max"
export CLAUDE_CODE_AUTO_COMPACT_WINDOW="786432"
claude --model "$ANTHROPIC_MODEL"
)The effort and compaction values are DeepSeek's provider-specific recipe, not universal defaults for every gateway. Keep bracketed model names quoted in the shell. These overrides cover the roles the provider documents; changing the main model alone does not control every background or future client feature.
Check /status, make the same small text request, and correlate it with DeepSeek-side usage information. OpenRouter activity is not the verification source for this direct connection. A settings override can still change the effective endpoint or token despite these shell exports.
Which Direct DeepSeek Model Does The Name Select?
As of October 6, DeepSeek's model and pricing documentation maps deepseek-flash to DeepSeek V4.1 Flash, while deepseek-v4-pro selects V4-Pro-0813. The legacy direct names deepseek-v4-flash and deepseek-v4-flash-vision-exp remain accepted, but their retired models' requests are served by V4.1 Flash and billed at Flash rates.
There is another reason to use an explicit supported name: DeepSeek's Anthropic compatibility documentation says unsupported model names automatically map to Flash. Claude Opus names map to Pro, while Sonnet and Haiku names map to Flash. A request can therefore succeed even when the model name you supplied did not select the model you intended. Pro mapping also means Pro billing.
For a deliberate Pro test, use the documented direct Pro identifier and align the intended role overrides; do not assume that selecting opus through a gateway preserves Anthropic's model. Likewise, an old OpenRouter slug is not evidence of DeepSeek direct's current alias mapping.
Keep Credentials Out Of Shared Settings
Once the temporary connection works, decide how future sessions will receive it: an approved secret launcher or helper, a private user configuration, or a local project configuration. Avoid keeping competing configurations active in several places.
For example, this is the shape of a private DeepSeek settings file, not a ready-to-use credential:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic",
"ANTHROPIC_AUTH_TOKEN": "<replace with your private DeepSeek API key>",
"ANTHROPIC_MODEL": "deepseek-flash[1m]",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-flash[1m]",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-flash[1m]",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "deepseek-flash",
"CLAUDE_CODE_SUBAGENT_MODEL": "deepseek-flash",
"CLAUDE_CODE_EFFORT_LEVEL": "max",
"CLAUDE_CODE_AUTO_COMPACT_WINDOW": "786432"
}
}JSON is not a shell script. Writing "$DEEPSEEK_API_KEY" as a JSON value does not establish that the application will expand it into a key. Use the actual private value only if you accept storing it as text, or use a documented secret-input method. The placeholder above must be replaced before use.
Do not put credentials into the shared .claude/settings.json. If you manually create .claude/settings.local.json, confirm it is excluded from version control; an ignored file is still readable locally and can appear in backups. Review any competing credential and endpoint settings as well as the new file. Claude Code settings and gateway credential storage.
These instructions apply to the terminal CLI. A GUI-launched editor may not inherit the terminal's exports. VS Code's credential precheck and Claude Desktop's dedicated third-party inference configuration have their own inputs, and normal cloud sessions do not switch providers through these terminal variables. Use the broader configuration guide for those cases.
Verify Before Real Work

A successful connection has several checks, each answering a different question:
| Check | What it can establish | What remains to check |
|---|---|---|
/status | The client's reported authentication, endpoint, and session context | What the upstream service actually processed |
| Small text request | One request completed | Actual backend selection, billing, and tools |
| Matching provider activity or response metadata | Which recorded request, model, and provider served the test, where exposed | Repository-tool reliability and any hidden mapping |
| Small read-only tool task | The tested file-read or command flow works in that session | Larger edits, parallel tools, and other capabilities |
Use a disposable folder containing a small README with a distinctive sentence. Ask Claude Code to read the file with its file tool and quote that sentence without editing anything. Inspect the tool call and result, not just the final answer. Then try one harmless command in that folder under your usual permission controls. This separates plain text generation from the agent behavior you need for coding.
An answer to “What model are you?” is not backend verification. Neither is an HTTP success by itself, especially when DeepSeek can map unsupported names to Flash. If provider activity appears quiet, check the date range, account, display delay, and endpoint before concluding that the service never received a request. If the available records do not expose the served model, keep that part unconfirmed.
Anthropic Compatibility Has Specific Limits
DeepSeek's direct endpoint documents streaming, tool definitions, tool-use results, and several image inputs. It also lists ignored fields, including cache_control, mcp_servers, service_tier, and top_k; thinking budgets and disable_parallel_tool_use are not applied as they would be in Anthropic's API. Some content blocks, such as document and MCP result blocks, are unsupported. See the compatibility table for the exact formats and conditions.
Those details can explain why a text request works while a more involved tool or attachment workflow fails. DeepSeek also documents WebSearch support for Claude Code, with extra model-token requests for summarizing results; include that usage when evaluating cost. These direct-API behaviors should not be assumed for every OpenRouter provider route.
Anthropic does not guarantee non-Claude model compatibility merely because the client can connect to a gateway. Test the specific tools your workflow needs, and avoid sending private repository material until you accept the selected service's data handling. Claude Code gateway requirements.
Fix The First Failed Run

Start with the error actually returned. Do not repeatedly swap model names and credentials together, because that makes it harder to identify which change helped.
| Symptom | First action | What the next result tells you |
|---|---|---|
401 or 403 | Confirm the key belongs to the endpoint, the key is active, and /status reports the intended authentication; check settings and managed restrictions | A corrected request can establish authentication for that request; 403 may also require account or policy changes |
404 or “model not found” | On OpenRouter, use the full catalog slug and check provider availability; on direct DeepSeek, use its supported name | A model error alone does not prove valid credentials or a working inference path |
| Reply succeeds but the model seems wrong | Inspect the explicit model, family overrides, saved default, and provider records | Direct DeepSeek's fallback mapping may explain success with an unintended name |
DeepSeek absent from /model | Pin the full model explicitly, or enable discovery and restart within the allowed model list | A missing curated picker entry is different from upstream rejection |
| Text works but tools fail or the session stalls | Reduce the test to one file-read tool; check the relevant protocol feature and any adapter logs | A plain text success does not establish tool compatibility |
429 or usage/credit error | Read the provider's returned message and check that account's balance, limits, and selected provider | Switching endpoints changes the account being checked; it does not grant quota |
| Dashboard shows no matching request | Check account, time filters, display lag, and effective endpoint | Missing activity alone is inconclusive |
If you use claude-code-router, its local endpoint adds another configuration to inspect: incoming authentication, model mapping, upstream key, and protocol conversion. Compare the minimal documented direct connection with the adapter path to locate the failing part. Neither current provider recipe requires CCR, and an old community installation command is not sufficient authority for the adapter's current configuration.
Return To Your Previous Connection
For the subshell examples, exit Claude Code and let the subshell end. The parent shell keeps the environment it had before the test. This does not undo a model default saved with /model, changes you made to settings files, or an intentional /logout.
If you exported values directly into your ordinary shell instead, remove only the test values you added, restoring previous values where appropriate. This cleanup applies to variables introduced by these recipes:
unset ANTHROPIC_BASE_URL ANTHROPIC_AUTH_TOKEN ANTHROPIC_API_KEY ANTHROPIC_MODEL
unset ANTHROPIC_DEFAULT_OPUS_MODEL ANTHROPIC_DEFAULT_SONNET_MODEL
unset ANTHROPIC_DEFAULT_HAIKU_MODEL CLAUDE_CODE_SUBAGENT_MODEL
unset CLAUDE_CODE_EFFORT_LEVEL CLAUDE_CODE_AUTO_COMPACT_WINDOW
unset CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERYRestore any changed private settings and saved model choice, then launch a fresh session and check /status against the information you recorded beforehand. Removing an export does not revoke its key or clear a settings-file value. Do not delete credentials or history as a general rollback step. If you intentionally signed out, use the appropriate documented login path for the account you want to restore.
FAQ
Is DeepSeek Through OpenRouter Cheaper Than DeepSeek Direct?
There is no universal saving from changing the endpoint. Compare the same model, provider, input and output tokens, cache treatment, and applicable time-based pricing. DeepSeek's direct charges come from its topped-up or granted balance, and WebSearch can add model usage. Check the current DeepSeek pricing and OpenRouter model listing before making a cost comparison.
Can I Use DeepSeek In Claude Code For Free Or Without Limits?
The connection settings do not grant free or unlimited usage. Your service account's model access, credits, and limits still apply. The October 6 public OpenRouter catalog snapshot contained no DeepSeek :free entry; that is a dated observation, not a permanent availability claim. Check the current catalog and your account rather than relying on a “free forever” setup video's title.
Do I Need To Log Out Of Claude Before Using OpenRouter?
Not as an unconditional prerequisite. The documented bearer-token connection supplies a different credential for its requests, while settings, selected cloud providers, apps gateways, and managed policy can change the effective path. OpenRouter suggests /logout when a cached Anthropic login is interfering. Use it only when you intend to remove that login, and check the current authentication rules.
Does Changing ANTHROPIC_MODEL Change Every Model Claude Code Uses?
No. It selects the main model, subject to higher-priority session or launch choices. Family defaults and the subagent override are separate controls, which is why the examples set them explicitly. A saved /model choice also persists beyond a temporary export. See Claude Code model configuration before adding other role overrides.
Sources11
External pages this guide links to, in the order they appear. Last updated Oct 7, 2026.
Sources11
External pages this guide links to, in the order they appear. Last updated Oct 7, 2026.
- 1.OpenRouter's Claude Code guideopenrouter.ai/docs/cookbook/coding-agents/claude-code-integration
- 2.current model catalogopenrouter.ai/api/v1/models
- 3.DeepSeek's Claude Code guideapi-docs.deepseek.com/quick_start/agent_integrations/claude_code
- 4.Claude Code setup documentationcode.claude.com/docs/en/setup
- 5.authenticationcode.claude.com/docs/en/authentication
- 6.gateway connectioncode.claude.com/docs/en/llm-gateway-connect
- 7.Claude Code model optionscode.claude.com/docs/en/model-config
- 8.model and pricing documentationapi-docs.deepseek.com/quick_start/pricing
- 9.Anthropic compatibility documentationapi-docs.deepseek.com/guides/anthropic_api
- 10.Claude Code gateway requirementscode.claude.com/docs/en/llm-gateway
- 11.OpenRouter model listingopenrouter.ai/models





