DeepSeek API Integration
DeepSeek is a Chinese LLM provider with models competing with GPT-4o at significantly lower cost. DeepSeek-R1 is a reasoning model with open weights comparable to OpenAI's o1. DeepSeek Coder V2 is a specialized code model. Important: data is processed in China, which is critical for compliance-sensitive tasks.
Basic Integration (OpenAI-Compatible API)
from openai import OpenAI
# DeepSeek is fully compatible with OpenAI SDK
client = OpenAI(
api_key="DEEPSEEK_API_KEY",
base_url="https://api.deepseek.com",
)
# Chat
response = client.chat.completions.create(
model="deepseek-chat", # DeepSeek-V3
messages=[
{"role": "system", "content": "You are an experienced Python developer"},
{"role": "user", "content": "Write an async function for batch API requests"},
],
temperature=0.1,
)
print(response.choices[0].message.content)
# Reasoning (deepseek-reasoner = R1)
response = client.chat.completions.create(
model="deepseek-reasoner",
messages=[{"role": "user", "content": "Prove that sqrt(2) is irrational"}],
)
# R1 returns reasoning_content (chain of thought) + content (answer)
print(response.choices[0].message.reasoning_content) # Reasoning
print(response.choices[0].message.content) # Final answer
Streaming
with client.chat.completions.stream(
model="deepseek-chat",
messages=[{"role": "user", "content": "Long answer..."}],
) as stream:
for chunk in stream.text_stream:
print(chunk, end="", flush=True)
Code Completion (FIM) — DeepSeek Coder
response = client.completions.create(
model="deepseek-chat",
prompt="<|fim▁begin|>def calculate_tax(income: float",
suffix="<|fim▁end|>",
max_tokens=128,
stop=["<|fim▁end|>"],
)
print(response.choices[0].text)
Cost of DeepSeek (2025)
| Model | Input (1M) | Output (1M) | Note |
|---|---|---|---|
| DeepSeek-V3 | $0.27 | $1.10 | Cached input $0.07 |
| DeepSeek-R1 | $0.55 | $2.19 | Reasoning model |
For comparison: GPT-4o $2.50/$10, making DeepSeek 5–10× cheaper with comparable quality.
When to Use
- Tasks requiring computation or deep analysis — R1
- Code, SQL, data analysis — DeepSeek-V3 or Coder V2
- High-load scenarios with price sensitivity — DeepSeek-V3
- Compliance requirements with data storage in RF/EU — not suitable
Local Deployment
ollama pull deepseek-r1:7b # 4.7 GB
ollama pull deepseek-r1:70b # 43 GB (requires GPU with 40GB VRAM)
Timeline
- Basic integration: 0.5 day (OpenAI-compatible API)
- Quality testing on specific tasks: 1–2 days







