DeepSeek API
V4-Flash and V4-Pro โ DeepSeek's frontier models with 1M token context, native thinking mode, and full OpenAI / Anthropic API compatibility. Drop-in replacement for your existing stack.
deepseek-chat and deepseek-reasoner model names will be deprecated on 2026/07/24 โ migrate to deepseek-v4-flash now.Pricing
Billed per 1M tokens in USD. Cost = tokens ร price, deducted from topped-up balance first, then granted balance. Cache-hit input tokens are 50ร cheaper than cache-miss โ use context caching to cut costs dramatically.
DeepSeek-V4-Flash
default ยท fast & affordable| Input (cache hit) | $0.0028/1M |
| Input (cache miss) | $0.14/1M |
| Output | $0.28/1M |
DeepSeek-V4-Pro
maximum reasoning quality| Input (cache hit) | $0.003625/1M |
| Input (cache miss) | $0.435/1M |
| Output | $0.87/1M |
deepseek_tokenizer.zip) to estimate costs before sending requests. Actual token counts come from the usage field in API responses.
Model Comparison
| Capability | V4-Flash | V4-Pro |
|---|---|---|
| Context Window | 1M tokens | 1M tokens |
| Max Output | โ | 384K tokens |
| Thinking Mode | โ | โ |
| JSON Output | โ | โ |
| Tool Calls | โ | โ |
| Chat Prefix Completion (Beta) | โ | โ |
| FIM Completion (Beta) | โ | โ |
| OpenAI Format | โ | โ |
| Anthropic Format | โ | โ |
| Context Caching | โ | โ |
| Concurrency Limit | 2,500 | 500 |
Key Features
Thinking Mode
Configurable via reasoning_effort
1M Context
Million-token window
Context Caching
50ร cheaper on cache hits
OpenAI Compatible
Drop-in with official SDKs
Anthropic Compatible
Works with Claude SDK
Tool Calls
Agentic function calling
JSON Output
Structured responses
Streaming
SSE for real-time apps
Thinking Mode
Both V4-Flash and V4-Pro support native thinking/reasoning. Enable it via the thinking parameter and control effort with reasoning_effort:
{
"model": "deepseek-v4-flash",
"thinking": { "type": "enabled" },
"reasoning_effort": "medium",
"messages": [{"role": "user", "content": "Explain quantum entanglement simply"}]
}
reasoning_effort values yield deeper reasoning at higher token cost.
API Endpoints
DeepSeek supports both OpenAI and Anthropic API formats โ same API key works for both.
| Method | Endpoint | Description |
|---|---|---|
| POST | /chat/completions | Chat completions (OpenAI) |
| POST | /anthropic/v1/messages | Messages (Anthropic) |
| GET | /models | List available models |
| GET | /models/{model} | Model details |
Base URLs
| Format | Base URL |
|---|---|
| OpenAI | https://api.deepseek.com |
| Anthropic | https://api.deepseek.com/anthropic |
Code Examples
Authentication
Get your API key from platform.deepseek.com. All requests require a Bearer token:
Authorization: Bearer <DEEPSEEK_API_KEY>
Chat Completion
curl https://api.deepseek.com/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DEEPSEEK_API_KEY" \
-d '{
"model": "deepseek-v4-flash",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"stream": false
}'
from openai import OpenAI
client = OpenAI(
api_key="YOUR_DEEPSEEK_API_KEY",
base_url="https://api.deepseek.com"
)
response = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
stream=False
)
print(response.choices[0].message.content)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.DEEPSEEK_API_KEY,
baseURL: "https://api.deepseek.com"
});
const response = await client.chat.completions.create({
model: "deepseek-v4-flash",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Hello!" }
],
stream: false
});
console.log(response.choices[0].message.content);
Streaming
curl https://api.deepseek.com/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DEEPSEEK_API_KEY" \
-d '{
"model": "deepseek-v4-flash",
"messages": [{"role": "user", "content": "Tell me a story"}],
"stream": true
}'
Responses return as Server-Sent Events (SSE) with data: {...} lines and a final [DONE] sentinel.
Context Caching
Repeat the same prefix across requests to trigger automatic caching. Cache-hit tokens billed at the discounted rate โ no code changes required beyond reusing the prefix.
# First request โ full price (cache miss)
curl https://api.deepseek.com/chat/completions \
-H "Authorization: Bearer $DEEPSEEK_API_KEY" \
-d '{
"model": "deepseek-v4-flash",
"messages": [
{"role": "system", "content": "You are a coding assistant. Here is the project context: [long docs]..."},
{"role": "user", "content": "Now help me with this specific question..."}
]
}'
# Subsequent requests โ prefix cached at $0.0028/1M
curl https://api.deepseek.com/chat/completions \
-H "Authorization: Bearer $DEEPSEEK_API_KEY" \
-d '{
"model": "deepseek-v4-flash",
"messages": [
{"role": "system", "content": "You are a coding assistant. Here is the project context: [long docs]..."},
{"role": "user", "content": "A different question with same prefix..."}
]
}'
Token Usage
Tokens are the basic billing units โ roughly 1 English character โ 0.3 tokens, 1 Chinese character โ 0.6 tokens. Actual counts vary by model; the definitive count comes from the usage field in the API response.
Token Cost Estimator
Rough estimate based on average token ratios. Actual counts come from the model's usage field.
Rate Limits
Concurrency limits are enforced at the account level regardless of which API key is used. A request counts as concurrent from send until response completes.
| Model | Concurrency Limit |
|---|---|
deepseek-v4-flash | 2,500 concurrent |
deepseek-v4-pro | 500 concurrent |
Error Codes
| Code | Meaning | Troubleshooting |
|---|---|---|
400 | Invalid Format | Fix request body per error message |
401 | Authentication Fails | Verify API key; create one at platform.deepseek.com |
402 | Insufficient Balance | Check account balance; top up |
422 | Invalid Parameters | Adjust parameters per error message |
429 | Rate Limit Reached | Slow down; consider exponential backoff |
500 | Server Error | Retry after brief wait |
503 | Server Overloaded | Retry after brief wait |
Agent Integrations
DeepSeek integrates directly with popular coding agents. Configure via OpenAI-compatible or Anthropic-compatible format depending on your tool.
Configure ~/.claude/settings.json:
ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropicANTHROPIC_AUTH_TOKEN= your DeepSeek API keyANTHROPIC_MODEL=deepseek-v4-flash
Use DeepSeek as a Copilot provider. Set the API base URL and model in your Copilot configuration to route through DeepSeek.
CLI tool. Configure ~/.config/opencode/opencode.json:
- Provider:
DeepSeek(OpenAI-compatible) - Base URL:
https://api.deepseek.com - Model:
deepseek-v4-flash
FAQ
Visit platform.deepseek.com/api-docs/api-key and create a new key. Store it securely โ it's shown only once.
V4-Flash is the default โ fast, affordable, 2,500 concurrency. V4-Pro offers maximum reasoning quality at higher cost with 500 concurrency and 384K max output. Both support thinking mode and all API features.
Yes. For OpenAI: set base_url="https://api.deepseek.com". For Anthropic: client = anthropic.Anthropic(base_url="https://api.deepseek.com/anthropic"). Minimal code changes needed.
Cache entries expire after 1 hour of inactivity. The next request pays full price (cache miss) and re-establishes the cache. Design your workloads to reuse prefixes within the 1-hour window.
New accounts receive a small granted balance. Check the platform dashboard for current offers. Otherwise, usage is billed from your topped-up balance at the rates shown above.
Getting Started
Browse the rest of the Dump collection.