Quick start
Supported regions: Singapore, China North 2 (Beijing), Germany (Frankfurt), Japan (Tokyo), and US (Virginia). Use an API key and endpoint from the region you call; see Regions and endpoints.
deepseek-v4-pro-0813 is the flagship model in the DeepSeek series with 1.6T total parameters and 49B activated parameters. It natively supports context windows of up to 1 million tokens and delivers top-tier performance across coding, math, and general tasks. You can use the enable_thinking parameter to switch between thinking and non-thinking modes. The following example calls deepseek-v4-pro-0813 in thinking mode.
The newest additions, deepseek-v4.1-flash-1017 and deepseek-v4.1-flash, are lightweight flagships with 552B total parameters and only 8B activated for input. They also accept image input. Calling them works the same way as the examples below, except that their DashScope endpoint differs — see Multimodal examples.
Before you begin, get an API key and set it as an environment variable. If you call the model through an SDK, install the OpenAI or DashScope SDK.
The enable_thinking parameter is not part of the standard OpenAI API. In the OpenAI Python SDK, pass it through extra_body. In the Node.js SDK, pass it as a top-level parameter. The reasoning_effort parameter is a standard OpenAI parameter that you can pass directly as a top-level parameter.
Example codefrom openai import OpenAI
import os
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"),
# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
base_url="https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1",
)
messages = [{"role": "user", "content": "Who are you?"}]
completion = client.chat.completions.create(
model="deepseek-v4-pro-0813",
messages=messages,
extra_body={"enable_thinking": True},
stream=True,
stream_options={"include_usage": True},
)
reasoning_content = ""
answer_content = ""
is_answering = False
print("\n" + "=" * 20 + "Thinking process" + "=" * 20 + "\n")
for chunk in completion:
if not chunk.choices:
print("\n" + "=" * 20 + "Token usage" + "=" * 20 + "\n")
print(chunk.usage)
continue
delta = chunk.choices[0].delta
if hasattr(delta, "reasoning_content") and delta.reasoning_content is not None:
if not is_answering:
print(delta.reasoning_content, end="", flush=True)
reasoning_content += delta.reasoning_content
if hasattr(delta, "content") and delta.content:
if not is_answering:
print("\n" + "=" * 20 + "Full response" + "=" * 20 + "\n")
is_answering = True
print(delta.content, end="", flush=True)
answer_content += delta.content
Example codeimport OpenAI from "openai";
import process from 'process';
const openai = new OpenAI({
apiKey: process.env.DASHSCOPE_API_KEY,
// Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
// API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
baseURL: 'https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1'
});
let reasoningContent = '';
let answerContent = '';
let isAnswering = false;
async function main() {
const messages = [{ role: 'user', content: 'Who are you?' }];
const stream = await openai.chat.completions.create({
model: 'deepseek-v4-pro-0813',
messages,
enable_thinking: true,
stream: true,
stream_options: { include_usage: true },
});
console.log('\n' + '='.repeat(20) + 'Thinking process' + '='.repeat(20) + '\n');
for await (const chunk of stream) {
if (!chunk.choices?.length) {
console.log('\n' + '='.repeat(20) + 'Token usage' + '='.repeat(20) + '\n');
console.log(chunk.usage);
continue;
}
const delta = chunk.choices[0].delta;
if (delta.reasoning_content !== undefined && delta.reasoning_content !== null) {
if (!isAnswering) {
process.stdout.write(delta.reasoning_content);
}
reasoningContent += delta.reasoning_content;
}
if (delta.content !== undefined && delta.content) {
if (!isAnswering) {
console.log('\n' + '='.repeat(20) + 'Full response' + '='.repeat(20) + '\n');
isAnswering = true;
}
process.stdout.write(delta.content);
answerContent += delta.content;
}
}
}
main();
Example code# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
curl -X POST https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-pro-0813",
"messages": [
{
"role": "user",
"content": "Who are you?"
}
],
"stream": true,
"stream_options": {
"include_usage": true
},
"enable_thinking": true
}'
Example codeimport anthropic
import os
client = anthropic.Anthropic(
api_key=os.getenv("DASHSCOPE_API_KEY"),
# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
base_url="https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
)
message = client.messages.create(
model="deepseek-v4-pro-0813",
max_tokens=1024,
messages=[
{"role": "user", "content": "Who are you?"}
],
stream=True,
)
for event in message:
if event.type == "content_block_delta":
if hasattr(event.delta, "thinking"):
print(event.delta.thinking, end="", flush=True)
if hasattr(event.delta, "text"):
print(event.delta.text, end="", flush=True)
Example code# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
curl -X POST https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic/v1/messages \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "deepseek-v4-pro-0813",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Who are you?"
}
]
}'
The DashScope examples below use the text-generation endpoint. deepseek-v4.1-flash and deepseek-v4.1-flash-1017 are multimodal models and are only available on the DashScope multimodal-generation endpoint, which requires MultiModalConversation — see Multimodal examples. Example codeimport os
import dashscope
# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
client = dashscope.Client(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://ap-southeast-1.maas.qwencloudapi.com/api/v1",
)
messages = [{"role": "user", "content": "Who are you?"}]
completion = client.chat.completions.create(
model="deepseek-v4-pro-0813",
messages=messages,
enable_thinking=True,
stream=True,
)
reasoning_content = ""
answer_content = ""
is_answering = False
print("\n" + "=" * 20 + "Thinking process" + "=" * 20 + "\n")
for chunk in completion:
message = chunk.choices[0].delta
if message.reasoning_content:
if not is_answering:
print(message.reasoning_content, end="", flush=True)
reasoning_content += message.reasoning_content
if message.content:
if not is_answering:
print("\n" + "=" * 20 + "Full response" + "=" * 20 + "\n")
is_answering = True
print(message.content, end="", flush=True)
answer_content += message.content
print("\n" + "=" * 20 + "Token usage" + "=" * 20 + "\n")
print(chunk.usage)
Example codeDashScope Java SDK version must be 2.19.4 or later.
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import io.reactivex.Flowable;
import java.lang.System;
import java.util.Arrays;
public class Main {
private static StringBuilder reasoningContent = new StringBuilder();
private static StringBuilder finalContent = new StringBuilder();
private static boolean isFirstPrint = true;
private static void handleGenerationResult(GenerationResult message) {
String reasoning = message.getOutput().getChoices().get(0).getMessage().getReasoningContent();
String content = message.getOutput().getChoices().get(0).getMessage().getContent();
if (reasoning != null && !reasoning.isEmpty()) {
reasoningContent.append(reasoning);
if (isFirstPrint) {
System.out.println("====================Thinking process====================");
isFirstPrint = false;
}
System.out.print(reasoning);
}
if (content != null && !content.isEmpty()) {
finalContent.append(content);
if (!isFirstPrint) {
System.out.println("\n====================Full response====================");
isFirstPrint = true;
}
System.out.print(content);
}
}
private static GenerationParam buildGenerationParam(Message userMsg) {
return GenerationParam.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model("deepseek-v4-pro-0813")
.enableThinking(true)
.incrementalOutput(true)
.resultFormat("message")
.messages(Arrays.asList(userMsg))
.build();
}
public static void streamCallWithMessage(Generation gen, Message userMsg)
throws NoApiKeyException, ApiException, InputRequiredException {
GenerationParam param = buildGenerationParam(userMsg);
Flowable<GenerationResult> result = gen.streamCall(param);
result.blockingForEach(message -> handleGenerationResult(message));
}
public static void main(String[] args) {
try {
Generation gen = new Generation();
Message userMsg = Message.builder().role(Role.USER.getValue()).content("Who are you?").build();
streamCallWithMessage(gen, userMsg);
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.err.println("An exception occurred: " + e.getMessage());
}
}
}
Example code# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
curl -X POST "https://ap-southeast-1.maas.qwencloudapi.com/api/v1/services/aigc/text-generation/generation" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-DashScope-SSE: enable" \
-d '{
"model": "deepseek-v4-pro-0813",
"input":{
"messages":[
{
"role": "user",
"content": "Who are you?"
}
]
},
"parameters":{
"enable_thinking": true,
"incremental_output": true,
"result_format": "message"
}
}'
Reasoning effort
deepseek-v4.1-flash, deepseek-v4-pro-0813, deepseek-v4-pro, and deepseek-v4-flash-0731 have thinking mode enabled by default. You can use the reasoning_effort parameter to control reasoning intensity. Valid values: low (supported only by deepseek-v4.1-flash, deepseek-v4-flash-0731, and deepseek-v4-pro-0813), high, and max. The default value is high.
For deepseek-v4-pro, low and medium produce the same behavior as high, and xhigh produces the same behavior as max. For deepseek-v4.1-flash, minimal is mapped to low, medium and xhigh are mapped to high, and ultra is mapped to max.
from openai import OpenAI
import os
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"),
# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
base_url="https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="deepseek-v4-pro-0813",
messages=[{"role": "user", "content": "Which is larger, 9.9 or 9.11?"}],
reasoning_effort="high",
)
print(completion.choices[0].message.content)
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: process.env.DASHSCOPE_API_KEY,
// Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
// API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
baseURL: "https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1",
});
const completion = await openai.chat.completions.create({
model: "deepseek-v4-pro-0813",
messages: [{ role: "user", content: "Which is larger, 9.9 or 9.11?" }],
reasoning_effort: "high",
});
console.log(completion.choices[0].message.content);
# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
curl -X POST https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-pro-0813",
"messages": [{"role": "user", "content": "Which is larger, 9.9 or 9.11?"}],
"reasoning_effort": "high"
}'
import os
import dashscope
# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
client = dashscope.Client(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://ap-southeast-1.maas.qwencloudapi.com/api/v1",
)
response = client.chat.completions.create(
model="deepseek-v4-pro-0813",
messages=[{"role": "user", "content": "Which is larger, 9.9 or 9.11?"}],
# reasoning_effort is not an SDK signature parameter; pass it through parameters
parameters={"reasoning_effort": "high"},
)
print(response.choices[0].message.content)
Responses API
deepseek-v4.1-flash, deepseek-v4.1-flash-1017, deepseek-v4-pro-0813, deepseek-v4-flash-0731, and deepseek-v4-pro support calls through the OpenAI-compatible Responses API.
For deepseek-v4.1-flash, deepseek-v4-flash-0731, deepseek-v4-pro, and deepseek-v4-pro-0813, the Responses API is available in Singapore and China North 2 (Beijing) only. deepseek-v4.1-flash-1017 supports the Responses API in all regions: Singapore, China North 2 (Beijing), Germany (Frankfurt), China (Hong Kong), Japan (Tokyo), and US (Virginia).
When calling the Responses API, you can add the web_search (Web search), web_extractor (Web extractor), and code_interpreter (Code Interpreter) tools to the tools parameter.
from openai import OpenAI
import os
client = OpenAI(
# If the environment variable is not configured, replace the following line with your API key: api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
base_url="https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1",
)
response = client.responses.create(
model="deepseek-v4-flash-0731",
input="Hello! Please introduce yourself in one sentence.",
# Optional: enable the web search, web extractor, and code interpreter tools
tools=[
{"type": "web_search"},
{"type": "web_extractor"},
{"type": "code_interpreter"},
],
)
# Get the model response
print(response.output_text)
import OpenAI from "openai";
const openai = new OpenAI({
// If the environment variable is not configured, replace the following line with your API key: apiKey: "sk-xxx"
apiKey: process.env.DASHSCOPE_API_KEY,
// Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
// API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
baseURL: "https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1"
});
const response = await openai.responses.create({
model: "deepseek-v4-flash-0731",
input: "Hello! Please introduce yourself in one sentence.",
// Optional: enable the web search, web extractor, and code interpreter tools
tools: [
{ type: "web_search" },
{ type: "web_extractor" },
{ type: "code_interpreter" },
],
});
// Get the model response
console.log(response.output_text);
# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
curl -X POST https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1/responses \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-flash-0731",
"input": "Hello! Please introduce yourself in one sentence.",
"tools": [
{"type": "web_search"},
{"type": "web_extractor"},
{"type": "code_interpreter"}
]
}'
Multimodal examples
deepseek-v4.1-flash and deepseek-v4.1-flash-1017 have native visual understanding and accept both text and image input, returning text. All other DeepSeek models accept text input only.
Through the OpenAI-compatible API, pass images as image_url content blocks. Through DashScope, use the multimodal-generation endpoint with MultiModalConversation and pass images in the image field.
from openai import OpenAI
import os
client = OpenAI(
# If the environment variable is not configured, replace with your API key: api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
base_url="https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1",
)
# Single image
completion = client.chat.completions.create(
model="deepseek-v4.1-flash",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{
"type": "image_url",
"image_url": {"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"}
}
]
}
],
)
print(completion.choices[0].message.content)
# Multiple images (uncomment to use)
# completion = client.chat.completions.create(
# model="deepseek-v4.1-flash",
# messages=[
# {
# "role": "user",
# "content": [
# {"type": "text", "text": "What is in these images?"},
# {
# "type": "image_url",
# "image_url": {"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"}
# },
# {
# "type": "image_url",
# "image_url": {"url": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/tiger.png"}
# }
# ]
# }
# ],
# )
# print(completion.choices[0].message.content)
import OpenAI from "openai";
import process from 'process';
const openai = new OpenAI({
// If the environment variable is not configured, replace with your API key: apiKey: "sk-xxx"
apiKey: process.env.DASHSCOPE_API_KEY,
// Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
// API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
baseURL: "https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1"
});
const completion = await openai.chat.completions.create({
model: "deepseek-v4.1-flash",
messages: [
{
role: "user",
content: [
{ type: "text", text: "What is in this image?" },
{
type: "image_url",
image_url: { url: "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg" }
}
]
}
]
});
console.log(completion.choices[0].message.content);
# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
curl -X POST https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{"type": "image_url", "image_url": {"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"}}
]
}
]
}'
import os
import dashscope
# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
client = dashscope.Client(
# If the environment variable is not configured, replace with your API key: api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://ap-southeast-1.maas.qwencloudapi.com/api/v1",
)
messages = [
{
"role": "user",
"content": [
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"},
{"text": "What is in this image?"}
]
}
]
response = client.multimodal.chat.create(
model="deepseek-v4.1-flash",
messages=messages,
)
print(response.output_text)
# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
curl -X POST "https://ap-southeast-1.maas.qwencloudapi.com/api/v1/services/aigc/multimodal-generation/generation" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash",
"input":{
"messages":[
{
"role": "user",
"content": [
{"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"},
{"text": "What is in this image?"}
]
}
]
}
}'
Other features
| Model | Multi-turn | Function calling | Web search | Context cache | Structured output |
|---|
| deepseek-v4.1-flash | ✓ | ✓ | ✓ | ✓ | ✓ |
| deepseek-v4.1-flash-1017 | ✓ | ✓ | ✓ | Implicit only | ✓ |
| deepseek-v4-pro-0813 | ✓ | ✓ | ✓ | ✓ | ✓ |
| deepseek-v4-pro | ✓ | ✓ | ✓ | ✓ | ✓ |
| deepseek-v4-flash-0731 | ✓ | ✓ | ✓ | ✓ | JSON Object only |
deepseek-v4.1-flash-1017 supports the OpenAI-compatible Chat Completions API, the Anthropic Messages API, thinking, and web search; it does not support batch calls or fine-tuning.
Parameter defaults
| Model | temperature | top_p | repetition_penalty | presence_penalty | max_tokens | thinking_budget |
|---|
| deepseek-v4.1-flash | 1.0 | 1.0 | - | - | 393,216 | - |
| deepseek-v4.1-flash-1017 | 1.0 | 1.0 | - | - | 393,216 | - |
| deepseek-v4-pro-0813 | 1.0 | 1.0 | - | - | 393,216 shared | 393,216 shared |
| deepseek-v4-pro | 1.0 | 1.0 | - | - | 393,216 shared | 393,216 shared |
| deepseek-v4-flash-0731 | 1.0 | 1.0 | - | - | 393,216 shared | 393,216 shared |