Back to Blog

Claude Code with DeepSeek: Setup, Pricing & Fixes

Tutorials and Guides2173
Claude Code with DeepSeek: Setup, Pricing & Fixes

Claude Code is Anthropic’s terminal-native AI coding agent. It is commonly used for code generation, debugging, refactoring, repository analysis, and automated development workflows.

For many developers, direct access to official Anthropic APIs may involve unstable network connections or high usage costs. DeepSeek provides an Anthropic-compatible API endpoint, which allows developers to replace the backend model while keeping the Claude Code workflow mostly unchanged.

This guide explains how to integrate DeepSeek models into Claude Code. It covers credential preparation, persistent and temporary configuration methods, model selection, token pricing, usage tracking, and common troubleshooting steps.

All configuration examples can be used on Windows, macOS, and Linux. For teams managing multiple LLM backends at the same time, 4sapi as an API gateway. It helps centralize credentials, endpoint configuration, and model switching rules, reducing repeated setup work across different environments.

1. Pre-Installation and Credential Preparation

Before connecting DeepSeek to Claude Code, two prerequisites are required:

  1. Install the Claude Code CLI.
  2. Generate a valid DeepSeek API key.

These steps ensure that the local client and backend authentication are both ready.

1.1 Install Claude Code CLI

Claude Code is distributed as a global NPM package. It requires Node.js 18 LTS or newer.

Open a terminal and run:

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

After installation, verify that the command is available:

bash
claude --version

If the installation is successful, you should see an output similar to:

text
2.1.140 (Claude Code)

This confirms that the claude command is available system-wide.

It is better not to launch Claude Code immediately after installation. An unmodified client may still connect to Anthropic’s default endpoint. Complete the DeepSeek routing configuration first.

1.2 Generate a DeepSeek API Key

Log in to the DeepSeek Open Platform through the official website. Then open the API Keys management panel in the account console.

Click Create New Key to generate a new credential. The key usually starts with:

text
sk-

Copy the full key immediately after creation. The complete value is usually shown only once. Store it in a password manager or an encrypted secrets manager.

Do not hardcode the key into source code, public repositories, shared documents, screenshots, or frontend projects.

This API key will be used as the authentication token for Claude Code requests routed to DeepSeek’s Anthropic-compatible endpoint.

If a team uses multiple model services at the same time, 4sapi can help manage keys and endpoints in one place. This avoids scattered credential management across different vendor dashboards.

2. Two Configuration Methods

There are two common ways to configure Claude Code for DeepSeek:

  1. Persistent global configuration through settings.json
  2. Temporary configuration through shell environment variables

For daily development, the persistent configuration is recommended. For quick testing or temporary model switching, environment variables are more convenient.

DeepSeek’s Anthropic-compatible base URL is:

text
https://api.deepseek.com/anthropic

2.1 Persistent Global Configuration

Claude Code can read runtime parameters from a settings.json file in the user’s Claude configuration directory.

Common file paths are:

text
Windows:
C:\Users\[YourUsername]\.claude\settings.json

macOS / Linux:
~/.claude/settings.json

Create the .claude directory if it does not already exist.

The following two templates map Claude Code’s model-related environment variables to DeepSeek models.

Template 1: deepseek-chat

deepseek-chat is suitable for daily coding, scripting, frontend development, backend development, simple automation, and routine document summarization.

It is the recommended default option when cost control matters.

json
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "PASTE_YOUR_DEEPSEEK_SK_KEY_HERE",
    "ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic",
    "ANTHROPIC_MODEL": "deepseek-chat",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-chat",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-chat",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "deepseek-chat",
    "CLAUDE_CODE_SUBAGENT_MODEL": "deepseek-chat",
    "API_TIMEOUT_MS": "600000"
  },
  "permissions": {
    "allow": [],
    "deny": []
  },
  "alwaysThinkingEnabled": false
}

The API_TIMEOUT_MS value is set to 600000, which equals 10 minutes.

This longer timeout is useful for large repository analysis, long code reviews, and requests that may generate large token outputs.

Template 2: deepseek-reasoner

deepseek-reasoner is designed for more complex reasoning tasks. It is better suited for algorithm design, mathematical derivation, system architecture analysis, and multi-step logical planning.

Its token cost is higher than deepseek-chat, so it is best used only when the task clearly requires deeper reasoning.

json
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "PASTE_YOUR_DEEPSEEK_SK_KEY_HERE",
    "ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic",
    "ANTHROPIC_MODEL": "deepseek-reasoner",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-reasoner",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-reasoner",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "deepseek-reasoner",
    "CLAUDE_CODE_SUBAGENT_MODEL": "deepseek-reasoner",
    "API_TIMEOUT_MS": "600000"
  },
  "permissions": {
    "allow": [],
    "deny": []
  },
  "alwaysThinkingEnabled": false
}

A practical strategy is to use deepseek-chat by default and switch to deepseek-reasoner only for difficult reasoning tasks.

2.2 Temporary Shell Environment Variables

Temporary environment variables apply only to the current terminal session. Once the terminal window is closed, the configuration is cleared.

This method is useful when you want to test DeepSeek without changing the global settings.json file.

Windows PowerShell

powershell
$env:ANTHROPIC_AUTH_TOKEN="YOUR_DEEPSEEK_SK_KEY"
$env:ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
$env:ANTHROPIC_MODEL="deepseek-chat"

To test the reasoning model, change the model value:

powershell
$env:ANTHROPIC_MODEL="deepseek-reasoner"

macOS and Linux Bash/Zsh

bash
export ANTHROPIC_AUTH_TOKEN=YOUR_DEEPSEEK_SK_KEY
export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
export ANTHROPIC_MODEL=deepseek-chat

To switch to the reasoning model:

bash
export ANTHROPIC_MODEL=deepseek-reasoner

This approach is convenient for short-term testing. For long-term use, settings.json is easier to maintain.

3. Launch Claude Code and Verify the Backend Model

Configuration changes usually take effect only after the terminal process is restarted.

Use the following validation workflow.

First, close all existing terminal windows. Then open a new terminal session.

Start Claude Code:

bash
claude

Inside the Claude Code workspace, run:

bash
/model

If the configuration is correct, the active model should show one of the following:

text
deepseek-chat

or:

text
deepseek-reasoner

If you still see Anthropic model names, the configuration has not been loaded correctly.

Check the following items:

A missing comma, wrong path, or small endpoint typo can prevent the configuration from working.

4. DeepSeek Model Comparison and Token Pricing

DeepSeek provides two main models for this Claude Code workflow: deepseek-chat and deepseek-reasoner.

They differ in capability positioning and pricing.

Model NameCore Use CasesInput Cost per 1M TokensOutput Cost per 1M TokensCost Profile
deepseek-chatDaily coding, simple automation, document review¥2¥8Low-cost daily model
deepseek-reasonerAlgorithm reasoning, mathematics, complex system design¥4¥16Higher-cost reasoning model

For most frontend, backend, scripting, and documentation tasks, deepseek-chat is usually enough.

Use deepseek-reasoner for tasks such as:

A simple cost strategy works well:

text
Use deepseek-chat by default.
Use deepseek-reasoner only when stronger reasoning is needed.

This keeps daily development costs under control while preserving access to a stronger model when required.

5. Track Token Usage and Account Balance

DeepSeek’s official console provides usage and billing information. Developers can use it to monitor token consumption and control costs.

Two modules are especially important.

5.1 Usage Statistics

The usage panel shows input and output token consumption by day and month.

It helps teams understand:

For long-running development projects, regular usage review can prevent unexpected costs.

5.2 Billing and Recharge

The billing page shows:

For teams, this data can support internal cost allocation and project-level budgeting.

If multiple developers share one DeepSeek account, define clear usage rules. For example, use deepseek-chat for routine work and reserve deepseek-reasoner for approved high-complexity tasks.

6. Common Integration Issues and Fixes

Most integration problems come from configuration mistakes. The following issues are common during first-time setup.

Issue 1: Persistent Connection Failures

If Claude Code cannot connect to DeepSeek, check three items first.

  1. Confirm that the API key is complete. It should not contain extra spaces, line breaks, or missing characters.
  2. Verify that the base URL exactly matches:
text
https://api.deepseek.com/anthropic
  1. Check whether your network blocks outbound HTTPS requests to DeepSeek’s API domain.

Corporate networks, school networks, and strict proxy environments may block external API calls. If needed, test the same configuration from another network.

Issue 2: Request Timeout Errors

Large repository analysis can create long requests and long responses. Timeout errors are common if the timeout value is too low.

The recommended configuration includes:

json
"API_TIMEOUT_MS": "600000"

This sets the timeout to 10 minutes.

If timeouts still occur, increase this value temporarily for heavy tasks. You can also split large repository analysis into smaller steps.

For example:

text
Analyze the authentication module first.
Then analyze the billing module.
Finally summarize cross-module dependencies.

This is usually more stable than asking the model to inspect a large repository in one request.

Issue 3: Model Parameter Changes Do Not Apply

If you change settings.json or environment variables but Claude Code still uses the old model, the terminal session probably has not been restarted.

Use this process:

  1. Close all terminal windows.
  2. Open a new terminal.
  3. Run claude.
  4. Run /model.

Also check the JSON syntax in settings.json.

Common mistakes include:

Use a JSON linter before saving the file.

Issue 4: Wrong Model Name

If requests fail after changing the model, confirm that the model name is valid.

Use:

text
deepseek-chat

or:

text
deepseek-reasoner

Do not use Anthropic model names such as claude-opus, claude-sonnet, or claude-haiku as DeepSeek model IDs.

The compatibility endpoint maps the request format, not the model names.

Issue 5: Configuration File Not Found

If Claude Code does not read the configuration, confirm the file path.

For macOS and Linux:

text
~/.claude/settings.json

For Windows:

text
C:\Users\[YourUsername]\.claude\settings.json

Make sure the file is named exactly:

text
settings.json

not:

text
settings.json.txt

This mistake is common on Windows when file extensions are hidden.

7. Quick Deployment Cheat Sheet

Use this checklist for repeat setup.

  1. Install Claude Code:
bash
npm install -g @anthropic-ai/claude-code
  1. Confirm installation:
bash
claude --version
  1. Create a DeepSeek API key from the official console.

  2. Create or edit the settings file:

text
~/.claude/settings.json

or:

text
C:\Users\[YourUsername]\.claude\settings.json
  1. Add the DeepSeek configuration template.

  2. Restart the terminal.

  3. Launch Claude Code:

bash
claude
  1. Verify the active model:
bash
/model
  1. Track token usage in the DeepSeek billing dashboard.

8. Best Practices for Daily Use

A stable Claude Code and DeepSeek setup should follow a few practical rules.

First, keep deepseek-chat as the default model. It is cost-efficient and works well for most daily development tasks.

Second, switch to deepseek-reasoner only when deeper reasoning is needed. This avoids unnecessary spending.

Third, avoid analyzing a huge repository in one prompt. Split the work by module, folder, or task objective.

Fourth, never store API keys in public repositories. Use local configuration files, environment variables, or secret managers.

Fifth, monitor token usage regularly. Long codebase analysis can consume tokens quickly.

Sixth, keep backup templates for both models if you switch between them often.

For teams managing multiple LLM providers, a gateway such as 4sapi can centralize endpoint management and credential configuration. This helps reduce repeated setup work across developer machines and makes cross-model scheduling easier.

9. Conclusion

Integrating DeepSeek’s Anthropic-compatible API into Claude Code gives developers a practical alternative backend for terminal-based AI coding workflows.

The setup is straightforward once the key variables are clear:

text
ANTHROPIC_AUTH_TOKEN
ANTHROPIC_BASE_URL
ANTHROPIC_MODEL

For daily development, the persistent settings.json method is the most convenient. For quick tests and short-term model switching, shell environment variables are more flexible.

deepseek-chat is the recommended default for routine coding, scripting, and documentation work. deepseek-reasoner is better for algorithms, complex debugging, mathematical reasoning, and system design.

With proper timeout settings, secure key management, model selection rules, and a clear troubleshooting workflow, developers can build a stable and cost-controlled Claude Code environment powered by DeepSeek models.

For individual developers, this setup improves access flexibility and reduces daily costs. For small engineering teams, it provides a practical way to standardize terminal AI coding workflows without changing the familiar Claude Code interaction model.

Tags:Claude CodeDeepSeekAI CodingLLM APIAPI Setup

Recommended reading

Explore more frontier insights and industry know-how.