How to Connect Claude Code to DeepSeek: Cloud API and Local Deployment Guide
This guide explains how to connect Claude Code to DeepSeek through either a cloud API or a local private deployment. It covers preparation and secure download checks, the client-server architecture, step-by-step configuration for both paths, a JSON configuration example, a verification checklist, parameter tuning, reusable prompt templates, risks, and FAQs. It is intended for developers who already have a basic programming environment and want to use a code model with Claude Code.
1. Introduction: Who Should Read This Guide
AI coding assistants have become a major productivity tool, but many developers get blocked during initial setup by tedious environment configuration and complex parameters. This guide provides a verifiable walkthrough for connecting Claude Code to DeepSeek, covering both the cloud API path and local private deployment.
Intended readers: Developers who already have a basic programming environment, can run simple commands in a terminal, and want to connect a code model.
Prerequisites: A working Claude Code client, a stable network connection (cloud path) or a dedicated GPU (local path), and clear permission to send data externally.
Not suitable for: Users with no programming background who cannot use a command line, users on networks that block external API access, or enterprises that require fully offline operation without local GPU resources.
2. Preparation: Secure Downloads and Path Management
2.1 Obtaining the Integration Package
Get the Claude Code installer and configuration tools from official or trusted release channels. After downloading, you must verify the files. Do not skip this step:
- SHA256 verification: Compare against the hash published on the official site, for example
shasum -a 256 claude-code-package.zip(macOS/Linux) orcertutil -hashfile claude-code-package.zip SHA256(Windows). - Digital signature: On Windows, check the digital signature in the file properties; on macOS, run
codesign -dv --verbose=4 /path/to/app. - Version record: Note the download source URL, version number, and download time for later traceability.
2.2 Extraction Rules and Safety Checklist
After extraction, do not double-click to run anything yet. Complete these checks first:
- Path naming: The extraction path must not contain non-ASCII characters, spaces, or special symbols. Python interpreters and command-line scripts parse non-ASCII characters strictly, which easily leads to “file not found” or encoding errors.
- Write permission: Make sure the directory is writable by the current user so configuration files can be saved. On Linux/macOS, use
chmod u+wto adjust permissions. - Antivirus scan: Run a local antivirus scan after extraction, especially when using a package from a less certain source.
- Directory allowlist: Add the extraction directory to your antivirus allowlist to prevent the inference service process from being blocked at runtime.
3. Architecture: How Local Models and Cloud Services Work Together
AI coding clients and code models follow the classic client-server architecture:
- Client (Claude Code): Handles code editing, syntax highlighting, context collection, and displaying completion suggestions.
- Code model (DeepSeek): Handles semantic understanding, logical inference, and code generation. It can be a cloud API or an inference service running on a local GPU.
The two communicate over standard network requests. This “model decoupling” design lets users swap the underlying model flexibly without rewriting editor code. Compare the options below when choosing:
| Dimension | Cloud API | Local Private Deployment |
|---|---|---|
| VRAM/compute | No local GPU required | 7B needs about 16GB VRAM; 33B needs about 40GB |
| Latency | Affected by network fluctuation | Usually lower on a LAN |
| Data compliance | Code must be sent externally | Data stays within the intranet |
| Cost model | Billed per token | One-time hardware investment + electricity |
4. Configuration: Two Paths, Step by Step
Path A: Connecting DeepSeek via Cloud API
- Get credentials: Create an API key in the DeepSeek open platform console. The key is shown only once, so store it in a password manager or environment variable immediately.
- Set the Base URL: Specify
https://api.deepseek.com/v1in the Claude Code configuration. The/v1suffix is required, and the protocol must be HTTPS. - Set the model name: Use
deepseek-chatfor general conversation, anddeepseek-coderfor code completion. - Save and test: Send a minimal generation request to verify connectivity.
Path B: Local Private Deployment
Local deployment requires these additional steps, which cannot be skipped:
- Model selection and VRAM estimation: For a quantized model (such as 4-bit), VRAM needs are roughly parameters × 0.5GB. A 7B model needs about 4-8GB VRAM, and 33B needs about 20-24GB. Use
nvidia-smito check current VRAM. - Download model files: Pull GGUF or AWQ format files from Hugging Face or ModelScope. Large model files are big, so use
git lfsorwgetwith resumable downloads. - Start the inference service: Use an inference framework compatible with the OpenAI interface (such as vLLM, Ollama, or LM Studio) to load the model. With Ollama, for example, run
ollama serveand thenollama run deepseek-coder:6.7b. It listens on127.0.0.1:11434by default. - Listen address and port: Confirm the inference service listens on
127.0.0.1or a LAN IP, and avoid exposing it to the public internet. Set the Claude Code Base URL tohttp://127.0.0.1:11434/v1(the Ollama-compatible path). - Health check: Run
curl http://127.0.0.1:11434/v1/modelsto confirm the model list is returned. If it returns 200 and the JSON contains the target model name, the service is working.
Configuration File Example (JSON)
The following configuration applies to clients that support editing the configuration file directly. For other clients, fill in each field in the corresponding GUI input boxes:
{"api_provider": "openai_compatible","base_url": "https://api.deepseek.com/v1","api_key": "${DEEPSEEK_API_KEY}","model": "deepseek-coder","temperature": 0.2,"max_tokens": 4096}
Security notes:
- The
api_keyin the example uses an environment variable placeholder. Do not hardcode a real key in the configuration file, and never commit it to a Git repository. - Keys should follow the principle of least privilege, with only the necessary model invocation permissions enabled.
- If you suspect a key has been leaked, rotate it in the console immediately.
- For local deployment,
api_keycan be any placeholder value, but some clients still require a non-empty field.
5. Starting the Service and Verification Checklist
After saving the configuration, do not just look for a “green light.” Confirm each item below:
| Check | Action | Expected Result |
|---|---|---|
| Health check | curl http://127.0.0.1:11434/v1/models |
Returns 200, JSON contains the model name |
| Minimal generation | Send “write a Python quicksort function” | Non-empty code returned within 5 seconds |
| Log keywords | Check the client log | No 401/404/429 errors |
| Timeout setting | Set the client timeout to 30-60 seconds | Complex requests are not easily interrupted |
| Retry policy | Enable automatic retry (up to 2 times) | Recovers automatically during network jitter |
Common error meanings: 401 means the key is wrong or expired; 404 means the Base URL path is wrong (check whether /v1 is missing); 429 means the request rate limit is exceeded.
6. Advanced Optimization: Parameter Tuning and Context Management
| Scenario | Parameter | Recommended Value | Reason | Fallback |
|---|---|---|---|---|
| Code completion | temperature | 0.1-0.3 | Reduces randomness and improves determinism | Raise to 0.5 if completions are too rigid |
| Code explanation | temperature | 0.3-0.7 | Balances accuracy and natural expression | Lower to 0.2 |
| Context window | Smart trimming | Send only the code block around the cursor | Saves tokens and avoids exceeding limits | Manually select key files |
| Client timeout | Timeout | 30-60 seconds | Balances complex reasoning and waiting cost | Retry once after a timeout |
| Model-side timeout | Inference service configuration | Adjust based on hardware | Local models have higher first-token latency | Reduce max_tokens |
Distinguish “client timeout,” “model-side timeout,” and “gateway timeout”: a client timeout occurs when the request has not been sent; a model-side timeout means inference takes too long; a gateway timeout is usually caused by a reverse proxy (such as Nginx) with a default 60-second limit.
7. Scenario Templates You Can Copy
7.1 Unit Test Generation
Generate unit tests for the following function that cover boundary conditions:[paste function code]Requirements: include empty input, extreme values, and exception branches; use [pytest/JUnit].
Failure handling: if the output is truncated, increase max_tokens; if it times out, reduce the number of functions generated per request.
7.2 Legacy Code Analysis
Explain the business logic, inputs and outputs, and potential defects of the following code:[paste code]Requirements: summarize in no more than 200 words, then list 3 risk points.
7.3 Cross-Language Migration
Rewrite the following [source language] code in [target language], keeping the business logic identical:[paste code]Requirements: use idiomatic style of the target language and explain key differences.
8. Risks and Alternatives
- Cost: Cloud APIs are billed per token, so high-frequency use requires monitoring the bill; local deployment requires evaluating electricity and hardware depreciation.
- Latency: The cloud path is affected by the network; for critical scenarios, switch to local inference or deploy closer to users.
- License: DeepSeek models have specific open-source terms; confirm them before commercial use.
- Data compliance: Enterprise code must be approved by the security team before being sent externally; sensitive projects are better suited to local deployment.
- Failure fallback: If the local inference service crashes, temporarily switch to the cloud API as a backup.
9. FAQ
Q: How should I write the Claude Code Base URL?
A: Use https://api.deepseek.com/v1 for the cloud and http://127.0.0.1:11434/v1 for local Ollama. The /v1 suffix is required, and the protocol and port cannot be omitted.
Q: What if I get a 401?
A: Check whether the API key was copied completely, whether it has expired, and whether a local placeholder was mistaken for a real key.
Q: What if the local model fails to load?
A: First run nvidia-smi to confirm there is enough VRAM; then check whether the model file is complete (compare SHA256); finally, check the inference service log to locate the error.
Q: What if completion is slow?
A: Lower max_tokens, enable context trimming, or switch to a smaller quantized model.
