Call DeepSeek through its OpenAI-compatible API
Point the OpenAI SDK at https://api.deepseek.com, set DEEPSEEK_API_KEY and call deepseek-flash or deepseek-v4-pro, with thinking mode enabled as in DeepSeek's official Your First API Call page.
Verification
Editorial reviewRead and checked against the listed sources. The commands were not run.
- Test environment
- Unknown
- Tested on
- Unknown
- Last updated
- 2026-11-11
Related models: DeepSeek-V4-Pro-0813, DeepSeek-V4.1-Flash-1017
DeepSeek's API is compatible with both the OpenAI and the Anthropic API formats, so you can reuse an SDK you already know. This guide follows DeepSeek's official Your First API Call page; the code is copied from it and we have not run it ourselves.
1. Settings
| Setting | Value |
|---|---|
base_url (OpenAI format) | https://api.deepseek.com |
base_url (Anthropic format) | https://api.deepseek.com/anthropic |
| API key | create one on the DeepSeek Platform |
model | deepseek-flash or deepseek-v4-pro |
Set the key in your terminal as DEEPSEEK_API_KEY before running the examples.
2. Model names
deepseek-flashis now served by DeepSeek-V4.1-Flash-1017.deepseek-v4-prois DeepSeek-V4-Pro-0813.- The legacy names
deepseek-v4-flashanddeepseek-v4-flash-vision-expare still accepted, but DeepSeek says those models are retired: requests go to DeepSeek-V4.1-Flash-1017 and are billed at the Flash price. Usedeepseek-flashin new code.
3. Python (OpenAI SDK)
Install the SDK with pip3 install openai, then:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get('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": "Hello"},
],
stream=False,
reasoning_effort="high",
extra_body={"thinking": {"type": "enabled"}},
)
print(response.choices[0].message.content)
4. Node.js (OpenAI SDK)
Install the SDK with npm install openai, then:
import OpenAI from "openai";
const openai = new OpenAI({
baseURL: 'https://api.deepseek.com',
apiKey: process.env.DEEPSEEK_API_KEY,
});
async function main() {
const completion = await openai.chat.completions.create({
messages: [{ role: "system", content: "You are a helpful assistant." }],
model: "deepseek-flash",
thinking: {"type": "enabled"},
reasoning_effort: "high",
stream: false,
});
console.log(completion.choices[0].message.content);
}
main();
5. Notes
- DeepSeek uses the Chat Completions shape (
client.chat.completions.create), not OpenAI's Responses API. thinkingis a DeepSeek-specific field: the Python sample passes it throughextra_body, while the Node sample puts it directly in the request.- These samples are non-streaming. Set
streamtotrueto get a streamed response. - DeepSeek's docs also list agent integrations (DeepSeek Harness, Claude Code, Codex, OpenCode and others) if you want DeepSeek behind a coding tool without writing code.
Compare the two DeepSeek endpoints with other models on the Pricing page.
Further reading
- Lan-chan: A Desktop Pet for DeepSeek Harness: a desktop-pet plugin for DeepSeek Harness by the site owner.
Sources
- Your First API Call (DeepSeek API Docs)api-docs
.deepseek .com (opens in a new tab) · checked 2026-11-11 - Lan-chan: A Desktop Pet for DeepSeek Harness (XMLans blog)en
.xmlans .com (opens in a new tab) · checked 2026-11-11 - 在DeepSeek Harness上让可爱的兰酱和你一起写代码(星梦博客)www
.xmlans .com (opens in a new tab) · checked 2026-11-11