Skip to content

LearnTutorials

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.

By Recaply EditorsIntermediate16 min6 stepsUpdated

A hand drops a coin into a piggy bank that stands on an open laptop keyboard

What you need

  1. Step 1: Create a DeepSeek API key

    3 min

    Claude Code sends every request to DeepSeek with this key, and DeepSeek takes the cost from your balance.

    1. Go to platform.deepseek.com/api_keys and sign in.
    2. Create a new API key and copy it somewhere safe.
    3. 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.

  2. Step 2: Install Claude Code

    3 min

    Claude Code is the agent that reads and edits your files. DeepSeek only replaces the model it talks to.

    1. Run the command below in a terminal.
    2. Already installed? Run claude update instead.
    3. Open a new terminal window and run claude --version.
    Run this
    curl -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.

  3. Step 3: Point Claude Code at DeepSeek

    4 min

    These variables send Claude Code's requests to DeepSeek and pick a model for each kind of task.

    1. Open your shell config file: ~/.zshrc on a Mac, or ~/.bashrc on most Linux systems.
    2. Paste the lines below at the end, and put your key in place of [YOUR DEEPSEEK API KEY].
    3. Save the file, then run source ~/.zshrc or source ~/.bashrc.
    Your config
    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_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.

    source prints no 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.

  4. Step 4: Start Claude Code in your project

    2 min

    A quick check confirms that requests go to DeepSeek before you start real work.

    1. Open a new terminal, go to your project with cd, and run claude.
    2. Type /status and look at the model.
    3. 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.

    /status still shows a Claude model?

    A Claude Code settings file can override your shell. Check ~/.claude/settings.json for an env block with an old model or base URL, and remove it.

  5. Step 5: Switch to V4 Pro for hard tasks

    2 min

    Flash is the cheap default and can read images. V4 Pro costs over 3 times as much per token.

    1. Type /model opus to move the session to V4 Pro.
    2. Type /model sonnet to 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 sonnet for screenshots and diagrams.

    /effort has no effect with this setup, because CLAUDE_CODE_EFFORT_LEVEL overrides it. Delete that line to pick the effort per session.

  6. Step 6: Keep an eye on spending

    2 min

    DeepSeek charges per token, so a long session with a big context costs more than a short one.

    1. In the DeepSeek Platform, open the usage page to see tokens and cost by day.
    2. In Claude Code, run /compact when a session gets long, so each request sends less.
    3. Run /clear when 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

Did this guide work for you?

Sources