Cut Claude Code costs with the DeepSeek API
Run Claude Code on DeepSeek V4.1 Flash and V4 Pro in about 15 minutes and pay per token, with the same terminal agent and a 1M-token window.

What you need
Step 1: Create a DeepSeek API key
3 minClaude Code sends every request to DeepSeek with this key, and DeepSeek takes the cost from your balance.
- Go to platform.deepseek.com/api_keys and sign in.
- Create a new API key and copy it somewhere safe.
- Add funds on the Top up page.
You should see your new key in the key list and a balance above zero.
Requests fail with
402 Insufficient Balance?Your balance has run out. Add funds on the Top up page, then try again.
Treat the key like a password. Keep it out of shared files, screenshots and git repos.
Step 2: Install Claude Code
3 minClaude Code is the agent that reads and edits your files. DeepSeek only replaces the model it talks to.
- Run the command below in a terminal.
- Already installed? Run
claude updateinstead. - Open a new terminal window and run
claude --version.
Run thiscurl -fsSL https://claude.ai/install.sh | bash
You should see a version number followed by
(Claude Code).The terminal says it can't find
claude?Open a new terminal window so it picks up the new install folder, then run the check again.
Step 3: Point Claude Code at DeepSeek
4 minThese variables send Claude Code's requests to DeepSeek and pick a model for each kind of task.
- Open your shell config file:
~/.zshrcon a Mac, or~/.bashrcon most Linux systems. - Paste the lines below at the end, and put your key in place of [YOUR DEEPSEEK API KEY].
- Save the file, then run
source ~/.zshrcorsource ~/.bashrc.
Your configexport 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_SONNET_MODEL="deepseek-flash[1m]" export ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-v4-pro[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"
You should see no output after
source, which means the file loaded without errors.sourceprintsno matches found?Zsh read the square brackets as a file pattern. Keep the quotes around every value that ends in
[1m].This is DeepSeek's own setup with one change: the Opus slot points at V4 Pro. The
[1m]tag tells Claude Code the model has a 1M-token window.- Open your shell config file:
Step 4: Start Claude Code in your project
2 minA quick check confirms that requests go to DeepSeek before you start real work.
- Open a new terminal, go to your project with
cd, and runclaude. - Type
/statusand look at the model. - Ask one short question about the project to test the connection.
You should see
deepseek-flash[1m]as the model in/status, and an answer about your code./statusstill shows a Claude model?A Claude Code settings file can override your shell. Check
~/.claude/settings.jsonfor anenvblock with an old model or base URL, and remove it.- Open a new terminal, go to your project with
Step 5: Switch to V4 Pro for hard tasks
2 minFlash is the cheap default and can read images. V4 Pro costs over 3 times as much per token.
- Type
/model opusto move the session to V4 Pro. - Type
/model sonnetto go back to Flash.
You should see
deepseek-v4-pro[1m]as the model in/status.A screenshot you pasted shows up as
[Unsupported Image]?V4 Pro can't read images. Switch back to Flash with
/model sonnetfor screenshots and diagrams./efforthas no effect with this setup, becauseCLAUDE_CODE_EFFORT_LEVELoverrides it. Delete that line to pick the effort per session.- Type
Step 6: Keep an eye on spending
2 minDeepSeek charges per token, so a long session with a big context costs more than a short one.
- In the DeepSeek Platform, open the usage page to see tokens and cost by day.
- In Claude Code, run
/compactwhen a session gets long, so each request sends less. - Run
/clearwhen you move to an unrelated task.
You should see your token use and cost so far on the usage page.
Costs jumped after Claude Code searched the web?
DeepSeek runs those searches and bills them: $0.75 per 1,000 since October 31, 2026, plus the tokens to read the results.
You get
Claude Code running on DeepSeek V4.1 Flash, with V4 Pro one command away and a per-token bill you can track
Try next
Did this guide work for you?
Thanks. It helps us fix the steps.


