DeepSeek API
Beginner
Zero-Code Migration: Replacing Claude API with DeepSeek
2026-08
10 分钟阅读
#Anthropic API
#Claude迁移
#API兼容
#零代码
#降低成本
One-line Migration
DeepSeek provides an endpoint fully compatible with the Anthropic Messages API, requiring only two lines to change:
# Original code (using Claude)
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-xxx')
# Migrate to DeepSeek—only change two lines!
import anthropic
client = anthropic.Anthropic(
api_key='sk-your-deepseek-key',
base_url='https://api.deepseek.com/anthropic'
)
# The following code remains completely unchanged!
response = client.messages.create(
model='claude-sonnet-4-20250514',
max_tokens=1024,
system='You are a helpful assistant.',
messages=[{'role': 'user', 'content': 'Hello!'}]
)
print(response.content[0].text)
Compatibility Comparison Table
| Anthropic Parameter | DeepSeek Support | Description |
|---|
| messages.create() | ✅ Supported | Standard message creation |
| system prompt | ✅ Supported | System prompt |
| max_tokens | ✅ Supported | Maximum number of generated tokens |
| stop_sequences | ✅ Supported | Stop sequences |
| temperature / top_p / top_k | ✅ Supported | Sampling parameters |
| stream | ✅ Supported | Streaming output (SSE) |
| tool_use (Function Calling) | ✅ Supported | Tool calling |
Node.js Migration Example
// Migrate to DeepSeek—only change baseURL and apiKey
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
apiKey: process.env.DEEPSEEK_API_KEY,
baseURL: 'https://api.deepseek.com/anthropic'
});
const msg = await client.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Explain quantum computing' }]
});
console.log(msg.content[0].text);
Typical Cost Comparison
| Claude 4.5 Sonnet | DeepSeek V4 Flash |
|---|
| Input ($/M tokens) | $3.00 | $0.14 (save 95%) |
| Output ($/M tokens) | $15.00 | $0.28 (save 98%) |
| Total cost per million tokens | $18.00 | $0.42 (save 97.7%) |
Notes
- Model name retention: When using the Anthropic SDK, pass the Claude model name, and DeepSeek automatically maps it.
- max_tokens is required: Consistent with the Anthropic API, this parameter is mandatory.
- Response format consistency: The returned structure is exactly the same as the Anthropic API.
- Multimodal differences: DeepSeek does not support image input; ensure only text messages are sent.