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:
- Install the Claude Code CLI.
- 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:
After installation, verify that the command is available:
If the installation is successful, you should see an output similar to:
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:
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:
- Persistent global configuration through
settings.json - 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:
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:
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.
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.
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
To test the reasoning model, change the model value:
macOS and Linux Bash/Zsh
To switch to the reasoning model:
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:
Inside the Claude Code workspace, run:
If the configuration is correct, the active model should show one of the following:
or:
If you still see Anthropic model names, the configuration has not been loaded correctly.
Check the following items:
settings.jsonfile path- JSON syntax
- API key value
- Base URL
- Terminal restart status
- Conflicting environment variables
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 Name | Core Use Cases | Input Cost per 1M Tokens | Output Cost per 1M Tokens | Cost Profile |
|---|---|---|---|---|
deepseek-chat | Daily coding, simple automation, document review | ¥2 | ¥8 | Low-cost daily model |
deepseek-reasoner | Algorithm reasoning, mathematics, complex system design | ¥4 | ¥16 | Higher-cost reasoning model |
For most frontend, backend, scripting, and documentation tasks, deepseek-chat is usually enough.
Use deepseek-reasoner for tasks such as:
- Complex algorithm design
- Mathematical derivation
- Architecture trade-off analysis
- Difficult debugging
- Multi-step logical reasoning
- Long-chain planning tasks
A simple cost strategy works well:
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:
- Which workflows consume the most tokens
- Whether usage is growing too quickly
- Which prompts need optimization
- Whether some tasks should use a cheaper model
For long-running development projects, regular usage review can prevent unexpected costs.
5.2 Billing and Recharge
The billing page shows:
- Remaining account balance
- Recharge records
- API consumption details
- Historical spending
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.
- Confirm that the API key is complete. It should not contain extra spaces, line breaks, or missing characters.
- Verify that the base URL exactly matches:
- 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:
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:
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:
- Close all terminal windows.
- Open a new terminal.
- Run
claude. - Run
/model.
Also check the JSON syntax in settings.json.
Common mistakes include:
- Missing commas
- Extra trailing commas
- Mismatched braces
- Incorrect quotation marks
- Invalid escape characters
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:
or:
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:
For Windows:
Make sure the file is named exactly:
not:
This mistake is common on Windows when file extensions are hidden.
7. Quick Deployment Cheat Sheet
Use this checklist for repeat setup.
- Install Claude Code:
- Confirm installation:
-
Create a DeepSeek API key from the official console.
-
Create or edit the settings file:
or:
-
Add the DeepSeek configuration template.
-
Restart the terminal.
-
Launch Claude Code:
- Verify the active model:
- 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:
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.




