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 ParameterDeepSeek SupportDescription
messages.create()✅ SupportedStandard message creation
system prompt✅ SupportedSystem prompt
max_tokens✅ SupportedMaximum number of generated tokens
stop_sequences✅ SupportedStop sequences
temperature / top_p / top_k✅ SupportedSampling parameters
stream✅ SupportedStreaming output (SSE)
tool_use (Function Calling)✅ SupportedTool 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 SonnetDeepSeek 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.