How to Use DeepSeek in Claude Code With an API Key

Use DeepSeek V4.1 Flash in Claude Code with pay-as-you-go API billing. Configure the model, verify the connection, and switch back to Anthropic.

Claude Code can connect directly to DeepSeek through its Anthropic-compatible API. If you want Claude Code’s repository access, commands, subagents, and project controls with pay-as-you-go DeepSeek billing, point Claude Code to DeepSeek’s API endpoint and authenticate with a DeepSeek API key.

DeepSeek-V4.1-Flash-1017 is the latest Flash model available through the deepseek-flash API ID. Released on October 17, 2026, the update improves coding and agent performance while keeping the existing API configuration and token pricing unchanged.

Last updated: Oct 17, 2026.

Read More: How to Use DeepSeek in Codex and Cut API Costs

Can I Use Claude Code With Only a DeepSeek API Key?

Yes. You can run Claude Code with a DeepSeek API key. Claude Code sends model requests to DeepSeek’s Anthropic-compatible endpoint, and DeepSeek bills the token usage to your API balance. A paid Claude plan is not required for those requests.

How to Use DeepSeek in Claude Code

1. Install or Update Claude Code

If Claude Code is already installed, check that the command is available:

claude --version

macOS, Linux, or WSL

For a new native installation, run:

curl -fsSL https://claude.ai/install.sh | bash

Windows PowerShell

Run Anthropic’s Windows installer from PowerShell:

irm https://claude.ai/install.ps1 | iex

npm

Node.js 18 or newer can use the npm package:

npm install -g @anthropic-ai/claude-code

2. Create a DeepSeek API Key

Sign in to the DeepSeek Platform, create an API key, and add API credit before the first Claude Code request.

Store the key in your normal credential manager and keep it out of repositories, screenshots, issue trackers, and shared shell history.

3. Configure DeepSeek on macOS, Linux, or WSL

Claude Code reads these provider settings from environment variables when it starts. Run the following commands in the terminal you will use to launch Claude Code, replacing the placeholder with your DeepSeek API key.

The export values last for the current shell session. For repeated use, persist the non-secret values in your shell profile and inject the API key through your preferred credential or secret manager.

The configuration below uses deepseek-flash[1m] for Claude Code’s main model, Opus, and Sonnet slots. Haiku and subagents use deepseek-flash. Both model IDs access the current DeepSeek V4.1 Flash release.

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
export CLAUDE_CODE_EFFORT_LEVEL=max
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=786432

4. Configure DeepSeek on Windows

PowerShell uses the same environment-variable names with $env: syntax. Run the block in the PowerShell session that will launch Claude Code and replace the API-key placeholder with your own key.

These values last for the current PowerShell session unless you save them through your preferred environment or secret manager. The main, Opus, and Sonnet slots use deepseek-flash[1m], while Haiku and subagents use deepseek-flash.

$env:ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
$env:ANTHROPIC_AUTH_TOKEN="<your DeepSeek API Key>"
$env:ANTHROPIC_MODEL="deepseek-flash[1m]"
$env:ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-flash[1m]"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-flash[1m]"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-flash"
$env:CLAUDE_CODE_SUBAGENT_MODEL="deepseek-flash"
$env:CLAUDE_CODE_EFFORT_LEVEL="max"
$env:CLAUDE_CODE_AUTO_COMPACT_WINDOW="786432"

5. Start Claude Code in Your Project

Open the repository you want Claude Code to inspect, then start the agent from that directory:

cd /path/to/your-project
claude

6. Verify the DeepSeek Connection

Run /status inside Claude Code to inspect the active model and configuration. After the first completed request, check the DeepSeek Platform usage page for new token usage.

Read this repository. Identify the main entry point, the test command, and three maintenance risks. Do not edit any files.

7. How to Switch Claude Code Back to Anthropic

Remove the DeepSeek environment variables before starting a new Anthropic-backed session. If you saved these variables in ~/.zshrc, ~/.bashrc, a PowerShell profile, or another environment manager, remove the persistent entries there as well. Run /login after restarting Claude Code if the machine has no active Anthropic authentication.

macOS, Linux, or WSL

unset ANTHROPIC_BASE_URL
unset ANTHROPIC_AUTH_TOKEN
unset ANTHROPIC_MODEL
unset ANTHROPIC_DEFAULT_OPUS_MODEL
unset ANTHROPIC_DEFAULT_SONNET_MODEL
unset ANTHROPIC_DEFAULT_HAIKU_MODEL
unset CLAUDE_CODE_SUBAGENT_MODEL
unset CLAUDE_CODE_EFFORT_LEVEL
unset CLAUDE_CODE_AUTO_COMPACT_WINDOW

Windows PowerShell

Remove-Item Env:ANTHROPIC_BASE_URL -ErrorAction SilentlyContinue
Remove-Item Env:ANTHROPIC_AUTH_TOKEN -ErrorAction SilentlyContinue
Remove-Item Env:ANTHROPIC_MODEL -ErrorAction SilentlyContinue
Remove-Item Env:ANTHROPIC_DEFAULT_OPUS_MODEL -ErrorAction SilentlyContinue
Remove-Item Env:ANTHROPIC_DEFAULT_SONNET_MODEL -ErrorAction SilentlyContinue
Remove-Item Env:ANTHROPIC_DEFAULT_HAIKU_MODEL -ErrorAction SilentlyContinue
Remove-Item Env:CLAUDE_CODE_SUBAGENT_MODEL -ErrorAction SilentlyContinue
Remove-Item Env:CLAUDE_CODE_EFFORT_LEVEL -ErrorAction SilentlyContinue
Remove-Item Env:CLAUDE_CODE_AUTO_COMPACT_WINDOW -ErrorAction SilentlyContinue

Verify the Restored Account

Start Claude Code again and run /status to confirm the active account and model before continuing repository work.

What the DeepSeek Environment Variables Do

VariableDeepSeek configuration
ANTHROPIC_BASE_URLRoutes requests to DeepSeek’s Anthropic-compatible API.
ANTHROPIC_AUTH_TOKENUses your DeepSeek API key for authentication.
ANTHROPIC_MODELSets the main session model to deepseek-flash[1m].
ANTHROPIC_DEFAULT_OPUS_MODELUses deepseek-flash[1m] for the Opus slot.
ANTHROPIC_DEFAULT_SONNET_MODELUses deepseek-flash[1m] for the Sonnet slot.
ANTHROPIC_DEFAULT_HAIKU_MODELUses deepseek-flash for the Haiku slot.
CLAUDE_CODE_SUBAGENT_MODELRuns subagents with deepseek-flash.
CLAUDE_CODE_EFFORT_LEVELSets reasoning effort to max.
CLAUDE_CODE_AUTO_COMPACT_WINDOWSets automatic compaction to 786,432 tokens.

How Claude Model Names Map to DeepSeek

DeepSeek’s Anthropic-compatible API maps Claude Opus model names to deepseek-v4-pro, while Claude Sonnet and Haiku model names map to deepseek-flash. Requests mapped to V4 Pro use Pro pricing.

The configuration above explicitly assigns deepseek-flash[1m] to Claude Code’s main, Opus, and Sonnet slots, with deepseek-flash for Haiku and subagents. This keeps the configured sessions on Flash. V4 Pro remains available as a distinct API model.

DeepSeek V4.1 Flash in Claude Code

deepseek-flash now runs DeepSeek-V4.1-Flash-1017, the October 17 update to DeepSeek V4.1 Flash. The model supports a 1 million-token context window, up to 384,000 output tokens, image input, tool calls, and thinking modes. The account-level concurrency limit is 2,500 requests.

The update improves coding and agent benchmarks over the previous V4.1 Flash release. DeepSeek reports a Terminal-Bench 4.0 score of 42.3 using the Claude Code framework, compared with 31.2 for the previous model. The existing deepseek-flash API ID and token prices are unchanged.

DeepSeek V4 Pro is also available through deepseek-v4-pro and has its own pricing. The previous V4 Flash and V4 Flash Vision Experimental models have been retired, although their legacy API IDs currently direct requests to the latest V4.1 Flash model.

DeepSeek API Cost in Claude Code

DeepSeek charges API usage per million tokens, with different rates for Flash and V4 Pro. Peak hours are 01:00–04:00 UTC and 06:00–10:00 UTC on weekdays, excluding Chinese public holidays. The October 17 model update does not change Flash pricing, and V4 Pro continues to use its own rates.

Token typeV4.1 Flash off-peak / peakV4 Pro off-peak / peak
Cached input$0.003 / $0.006$0.022 / $0.044
Uncached input$0.15 / $0.30$0.66 / $1.32
Output$0.60 / $1.20$1.98 / $3.96

DeepSeek API Billing vs Claude Pro and Max

Claude Pro costs $20 per month with monthly billing, and Max has $100 and $200 monthly tiers. DeepSeek bills this Claude Code configuration by API token usage.

Compare your monthly DeepSeek API spend with the Claude plan price that matches your coding workload, then account for any Claude chat or other subscription features you also use.

Long repository sessions can process far more input than the text typed into the prompt. File contents, command output, project instructions, conversation history, and subagent work all contribute to token usage.

DeepSeek context caching can reduce the price of repeated input when the request reuses a cached prefix.

Web Search With DeepSeek in Claude Code

Claude Code’s built-in Web Search works with the DeepSeek API. When a coding task requires current information, Claude Code can invoke Web Search through DeepSeek’s search service. Processing the retrieved results also consumes model tokens.

DeepSeek introduced public Search and Fetch APIs on October 17, 2026. Each API costs $0.75 per 1,000 successful requests. Search and Fetch calls made through DeepSeek’s server-side integrations with Claude Code are free of request charges until November 1, 2026, at 00:00 Beijing time. Standard request billing begins after that date, in addition to any model token charges.

Troubleshooting

Claude Code Uses an Anthropic Model After Setup

Run /status and check the shell that launched Claude Code. The DeepSeek variables must exist in that shell before the claude process starts. Open a new terminal after changing a shell profile.

Confirm that ANTHROPIC_BASE_URL contains https://api.deepseek.com/anthropic. The Flash configuration should set ANTHROPIC_MODEL to deepseek-flash[1m].

Authentication or Balance Errors

Check that ANTHROPIC_AUTH_TOKEN contains an active DeepSeek API key and that the DeepSeek API account has available credit.

Claude Code Still Uses V4 Pro

If your Claude Code configuration contains deepseek-v4-pro[1m], it is configured to use V4 Pro, which is billed at Pro rates. To switch to the latest V4.1 Flash model, change ANTHROPIC_MODEL, ANTHROPIC_DEFAULT_OPUS_MODEL, and ANTHROPIC_DEFAULT_SONNET_MODEL to deepseek-flash[1m], then restart Claude Code.

API Spending Is Higher Than Expected

This configuration uses max reasoning effort for the main session and a 786,432-token automatic compaction threshold. Large repositories, long command output, repeated test logs, Web Search, and active subagents can increase token usage.

This Claude Code configuration sets CLAUDE_CODE_EFFORT_LEVEL=max. Test a lower Claude Code effort setting on representative tasks when you want to reduce token use, and review DeepSeek billing during the first week of regular use.

Claude Code Cannot Find the Command

Open a new terminal after installation and run claude --version. Native installations place the binary under ~/.local/bin/claude on macOS and Linux or %USERPROFILE%\.local\bin on Windows. Add that directory to PATH if the shell cannot find the command.

Security and Repository Data

Claude Code can send repository context, prompts, command output, and other task data to the configured model provider. In this setup, DeepSeek processes the model requests. Do not send credentials, customer records, regulated information, or confidential source code unless your data policy permits DeepSeek to process them.

DeepSeek can collect prompts, uploaded files, photos, feedback, chat history, and other submitted content. Personal data can be used to develop and train its technology, with an opt-out right for model training.

DeepSeek directly collects, processes, and stores personal data in the People’s Republic of China under its Privacy Policy.

Related Resources

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest & top AI tools sent directly to your email.

Subscribe now to explore the latest & top AI tools and resources, all in one convenient newsletter. No spam, we promise!