DeepSeek API guide
The DeepSeek API gives you DeepSeek's hosted models over plain HTTPS, in the same request format as the OpenAI and Anthropic SDKs. You change the base URL to https://api.deepseek.com, use a DeepSeek key, and pick one of two models: deepseek-flash or deepseek-v4-pro. Calls are billed per token, from $0.15 per 1M input tokens.
This page is written by an independent site, not by DeepSeek. Every model name, limit and price below is checked against the official API docs.
- Base URL (OpenAI format)
- https://api.deepseek.com
- Base URL (Anthropic format)
- https://api.deepseek.com/anthropic
- Models
- deepseek-flash · deepseek-v4-pro
- Context / max output
- 1M / 384K tokens
- Price from (off-peak)
- $0.15 in · $0.60 out per 1M
- Auth header
- Authorization: Bearer <key>
How to get a DeepSeek API key
You need a DeepSeek account and a positive balance — the API has no free tier. A key takes about two minutes.
- 1
Sign in to the DeepSeek platform
Go to platform.deepseek.com and sign in or create an account. Trouble signing in? See our DeepSeek login help.
- 2
Top up your balance
Open Top up and add credit. Without balance every call fails with HTTP 402. A promotional balance, if your account has one, is spent first.
- 3
Create the key
Open API keys, click Create new API key, name it (for example "production") and copy it immediately — it is shown only once.
- 4
Store it outside your code
Put it in an environment variable called DEEPSEEK_API_KEY. Never commit it to Git or ship it in browser or mobile code.
# macOS / Linux
export DEEPSEEK_API_KEY="sk-..."
# Windows PowerShell (current window)
$env:DEEPSEEK_API_KEY = "sk-..."
# Windows PowerShell (permanent, for new windows)
[Environment]::SetEnvironmentVariable("DEEPSEEK_API_KEY", "sk-...", "User")Your first DeepSeek API call
Install the official OpenAI SDK (pip install openai or npm install openai), point it at DeepSeek and send a chat completion. No DeepSeek-specific SDK is needed.
One thing catches most people out: thinking mode is on by default. For quick answers, switch it off as in the examples below; you get the reply faster and pay for fewer tokens.
# pip install openai
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["DEEPSEEK_API_KEY"],
base_url="https://api.deepseek.com",
)
response = client.chat.completions.create(
model="deepseek-flash",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain what an API is in one sentence."},
],
# Thinking is on by default. Turn it off for quick, cheap answers:
extra_body={"thinking": {"type": "disabled"}},
)
print(response.choices[0].message.content)// npm install openai
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.DEEPSEEK_API_KEY,
baseURL: "https://api.deepseek.com",
});
const res = await client.chat.completions.create({
model: "deepseek-flash",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Explain what an API is in one sentence." },
],
// DeepSeek-specific field; thinking is on by default
thinking: { type: "disabled" },
});
console.log(res.choices[0].message.content);curl https://api.deepseek.com/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DEEPSEEK_API_KEY" \
-d '{
"model": "deepseek-flash",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain what an API is in one sentence."}
],
"thinking": {"type": "disabled"}
}'# pip install anthropic
import os
import anthropic
client = anthropic.Anthropic(
api_key=os.environ["DEEPSEEK_API_KEY"],
base_url="https://api.deepseek.com/anthropic",
)
message = client.messages.create(
model="deepseek-flash",
max_tokens=1000,
messages=[{"role": "user", "content": "Explain what an API is in one sentence."}],
)
print(message.content)Keep the conversation yourself
The API is stateless: DeepSeek does not remember earlier messages. For a multi-turn chat, append each answer to your message list and send the whole list again.
messages = [{"role": "user", "content": "What's the highest mountain in the world?"}]
response = client.chat.completions.create(model="deepseek-flash", messages=messages)
messages.append(response.choices[0].message) # keep the answer
messages.append({"role": "user", "content": "And the second highest?"})
response = client.chat.completions.create(model="deepseek-flash", messages=messages)DeepSeek API models
There are two current model names. Each name always points at DeepSeek's latest release of that model, so results can shift slightly when DeepSeek ships an update.
| Model name | Serves | Context | Max output | Images | Off-peak price (in / out per 1M) | Use it for |
|---|---|---|---|---|---|---|
| deepseek-flash | DeepSeek-V4.1-Flash-1017 | 1M | 384K | Yes | $0.15 / $0.60 | Default for chat, agents, tool use, RAG and vision — fast and cheapest |
| deepseek-v4-pro | DeepSeek-V4-Pro-0813 | 1M | 384K | No | $0.66 / $1.98 | Hardest reasoning, long multi-step coding and math |
Both models support thinking and non-thinking mode, JSON output, tool calls, streaming, the OpenAI Responses API and the Anthropic API format. FIM (fill-in-the-middle) completion and chat prefix completion are in beta and FIM only works with thinking off.
Old model names: what still works
Still accepted, temporarily routed to DeepSeek-V4.1-Flash and billed at the Flash price (since 10 September 2026).
Use instead: deepseek-flash
Scheduled for discontinuation on 24 July 2026 and no longer in the official model list.
Use instead: deepseek-flash (thinking off for the old chat behaviour, on for reasoner)
Thinking mode
In thinking mode the model works through the problem before it answers. That makes it better at maths, code and multi-step tasks, and slower and more token-hungry on simple ones. It is on by default for both models.
- Switch it with
"thinking": {"type": "enabled"}or"disabled". In the OpenAI Python SDK this goes inextra_body. - Set the effort with
reasoning_effort:low,high(default) ormax. - The reasoning comes back in
reasoning_content, next to the normalcontent. Its size is reported inusage.completion_tokens_details.reasoning_tokens. - Default
max_tokens: 8K with thinking off, 64K with thinking on, 128K at effortmax. temperaturehas no effect in thinking mode, andtool_choice: "required"returns HTTP 400 — switch thinking off for those requests.- When you use tools in thinking mode, send
reasoning_contentback unchanged in later requests, or the API returns HTTP 400. Without tools it is ignored, so you can leave it out.
response = client.chat.completions.create(
model="deepseek-v4-pro",
messages=[{"role": "user", "content": "Is 1,001 a prime number? Explain."}],
reasoning_effort="high", # "low", "high" or "max"
extra_body={"thinking": {"type": "enabled"}}, # the default, shown for clarity
)
print(response.choices[0].message.reasoning_content) # the chain of thought
print(response.choices[0].message.content) # the final answerDeepSeek API pricing
You pay per 1M tokens, with a cheaper rate for input that hits DeepSeek's context cache. Rates double during peak hours: 01:00–04:00 and 06:00–10:00 UTC, Monday to Friday, excluding Chinese public holidays. Everything else, including weekends, is off-peak.
| Per 1M tokens | deepseek-flash off-peak | deepseek-flash peak | deepseek-v4-pro off-peak | deepseek-v4-pro peak |
|---|---|---|---|---|
| Input, cache hit | $0.003 | $0.006 | $0.022 | $0.044 |
| Input, cache miss | $0.15 | $0.30 | $0.66 | $1.32 |
| Output | $0.60 | $1.20 | $1.98 | $3.96 |
- A cache hit makes input about 98% cheaper on deepseek-flash and 97% on deepseek-v4-pro. Put the long, unchanging part of your prompt (system prompt, documents) first so repeated calls hit the cache;
usage.prompt_cache_hit_tokensshows how much did. - Search and Fetch (live web results for agents) cost $0.75 per 1,000 successful requests.
- Rates checked against the official rate card; full history and more examples on our DeepSeek pricing page.
Cache-miss input rates, no cache hits counted. DeepSeek rates verified 2026-09-18; competitor list prices verified 2026-07-25.
Rate limits and concurrency
- DeepSeek limits concurrent requests per account: 2,500 for deepseek-flash, 500 for deepseek-v4-pro. Extra API keys do not raise it. Above the limit you get HTTP 429.
- There is no published requests-per-minute or tokens-per-minute limit. You can request a higher concurrency limit from DeepSeek at no extra cost.
- Pass a
user_idper end user (letters, digits,_,-; no personal data) to keep their cache and scheduling separate. - Under load the server sends empty lines (or
: keep-alivecomments when streaming) while you wait. Official SDKs ignore them; a custom HTTP parser must too. If inference has not started after 10 minutes, the connection is closed.
DeepSeek API error codes and fixes
| Code | Meaning | Usual cause | Fix |
|---|---|---|---|
| 400 | Invalid Format | The request body is malformed. | Fix the body using the hint in the error message. |
| 401 | Authentication Fails | Wrong or revoked API key. | Check the key, or create a new one on the platform. |
| 402 | Insufficient Balance | The account has no balance left. | Top up on the platform, then retry. |
| 422 | Invalid Parameters | A parameter value is not allowed. | Correct the parameter named in the error message. |
| 429 | Rate Limit Reached | Too many requests at once (concurrency limit). | Back off and retry, queue requests, or ask for a higher limit. |
| 500 | Server Error | A problem on DeepSeek's side. | Retry after a short wait; contact DeepSeek if it persists. |
| 503 | Server Overloaded | High traffic on DeepSeek's side. | Retry after a short wait. |
Retry 429, 500 and 503 with exponential back-off. Do not retry 400, 401, 402 or 422 — they fail the same way until you fix the request or the account. Outages are posted on status.deepseek.com.
Use the DeepSeek API in Claude Code, Codex and other agents
Because DeepSeek also speaks the Anthropic and OpenAI Responses formats, coding agents can run on it with a few environment variables. For Claude Code, point the Anthropic base URL at DeepSeek and pick the model ([1m] selects the 1M-token context):
# macOS / Linux
export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
export ANTHROPIC_AUTH_TOKEN=$DEEPSEEK_API_KEY
export ANTHROPIC_MODEL="deepseek-flash[1m]"
export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-flash
# Windows PowerShell
$env:ANTHROPIC_BASE_URL = "https://api.deepseek.com/anthropic"
$env:ANTHROPIC_AUTH_TOKEN = $env:DEEPSEEK_API_KEY
$env:ANTHROPIC_MODEL = "deepseek-flash[1m]"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "deepseek-flash"Any request for a claude-opus* model runs on deepseek-v4-pro and is billed at the Pro rate; other claude* names run on deepseek-flash. Some Anthropic features, such as cache_control, citations and MCP servers inside the request, are ignored. DeepSeek's Claude Code guide also sets the sub-agent model and effort level, and there are guides for Codex, OpenCode and others; its own open-source agent is covered in our DeepSeek Harness review.
Moving from OpenAI or an older DeepSeek integration
- Set the base URL to
https://api.deepseek.comand use your DeepSeek key. - Change the model to
deepseek-flash. Replacedeepseek-chat,deepseek-reasoneranddeepseek-v4-flashwhile you are at it. - Decide on thinking per request: off for chat and extraction, on for reasoning-heavy work.
- Drop
frequency_penaltyandpresence_penalty— DeepSeek ignores them. - For JSON, set
response_format: {"type": "json_object"}and ask for JSON in the prompt; the API requires both. - Add back-off for HTTP 429, and alerts on HTTP 402 so an empty balance does not take your app down.
Sending user data to a hosted API? Read where DeepSeek processes API data first. If that is a blocker, the open weights can run on your own hardware — see running DeepSeek locally.
DeepSeek API: frequently asked questions
Sources
- Models & Pricing
- Your First API Call
- Chat Completions API reference
- Rate Limit & Isolation
- Error Codes
- Using the Anthropic API
- Thinking Mode
- Integrate with Claude Code
- Change Log
Official DeepSeek API documentation, checked 2026-11-03.