How to Use DeepSeek in Claude Code With an API Key

Use DeepSeek’s Anthropic-compatible API with V4 Pro for the main Claude Code session and V4 Flash for subagents and lighter coding tasks.

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.

This setup assigns DeepSeek V4 Pro to the main Claude Code session and V4 Flash to Haiku and subagents. After you set the environment variables and start Claude Code, /status shows the active model and the DeepSeek usage page records the API charges.

Last updated: September 9, 2026.

Can You 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.

export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
export ANTHROPIC_AUTH_TOKEN=<your DeepSeek API Key>
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-flash
export CLAUDE_CODE_SUBAGENT_MODEL=deepseek-v4-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:

$env:ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
$env:ANTHROPIC_AUTH_TOKEN="<your DeepSeek API Key>"
$env:ANTHROPIC_MODEL="deepseek-v4-pro[1m]"
$env:ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-v4-pro[1m]"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-v4-pro[1m]"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-v4-flash"
$env:CLAUDE_CODE_SUBAGENT_MODEL="deepseek-v4-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 to deepseek-v4-pro[1m].
ANTHROPIC_DEFAULT_OPUS_MODELUses V4 Pro with the 1M context configuration.
ANTHROPIC_DEFAULT_SONNET_MODELUses V4 Pro with the 1M context configuration.
ANTHROPIC_DEFAULT_HAIKU_MODELUses V4 Flash.
CLAUDE_CODE_SUBAGENT_MODELRuns subagents with V4 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

When Claude Code sends a Claude model ID to DeepSeek’s Anthropic-compatible endpoint, DeepSeek maps Opus names to V4 Pro and Sonnet or Haiku names to V4 Flash.

The configured ANTHROPIC_DEFAULT_SONNET_MODEL sets Claude Code’s default Sonnet slot directly to deepseek-v4-pro[1m]. That explicit assignment takes precedence over the generic Sonnet mapping.

  • claude-opus* maps to deepseek-v4-pro.
  • claude-sonnet* maps to deepseek-v4-flash.
  • claude-haiku* maps to deepseek-v4-flash.

DeepSeek V4 Pro vs V4 Flash in Claude Code

V4 Pro and V4 Flash both work through DeepSeek’s Anthropic-compatible API, provide a 1 million-token context window, allow up to 384,000 output tokens, and handle tool calls. This Claude Code setup uses V4 Pro for the main session and V4 Flash for Haiku and subagents.

ModelRole in this setupConcurrency
deepseek-v4-proMain session and quality-first coding work500
deepseek-v4-flashHaiku-level work, subagents, and high-volume tasks2,500

DeepSeek API Cost in Claude Code

DeepSeek bills V4 usage per 1 million tokens with peak and off-peak rates. Peak hours are 01:00–04:00 and 06:00–10:00 UTC from Monday through Friday. All other hours use the lower off-peak rate.

Token typeV4 Flash off-peak / peakV4 Pro off-peak / peak
Cached input$0.007 / $0.014$0.022 / $0.044
Uncached input$0.22 / $0.44$0.66 / $1.32
Output$0.66 / $1.32$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

Web Search works with this DeepSeek configuration. When Claude Code triggers a search, DeepSeek performs the search through its API and uses additional model requests to summarize the retrieved content.

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 and that ANTHROPIC_MODEL contains deepseek-v4-pro[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.

Sonnet or Haiku Requests Use V4 Flash

DeepSeek maps explicit Claude model names beginning with claude-sonnet or claude-haiku to V4 Flash. The environment variables used here set Claude Code’s default Sonnet slot directly to deepseek-v4-pro[1m] and the default Haiku slot to deepseek-v4-flash.

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.

DeepSeek V4 Pro and Flash accept low, high, and max reasoning effort. Use a lower effort setting for routine work after testing it on representative tasks, 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!