DeepSeek-Alibaba Cloud

Updated at:

This topic describes how to call DeepSeek series models on the Alibaba Cloud Model Studio platform using an OpenAI compatible interface or the DashScope SDK.

Service endpoints

The service endpoint is different for each region. Configure the Base URL based on your selected region (When you call the model, replace {WorkspaceId} with the actual Workspace ID. The available models and rate limits also vary by region. For more information, see the Rate limiting document.

The following DeepSeek models are available in China (Hong Kong): deepseek-v4.1-flash, deepseek-v4.1-flash-1017, deepseek-v4-pro-0813, and deepseek-v4-flash-0731. All four models support the Chat Completions, Responses, and Anthropic Messages APIs in China (Hong Kong).

OpenAI compatible

China (Beijing)

The base_url for SDK call configuration is https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1

The HTTP request address is POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions

US (Virginia)

The base_url for SDK call configuration is https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/compatible-mode/v1

The HTTP request address is POST https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions

Singapore

The base_url for SDK call configuration is https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1

The HTTP request address is POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions

Germany (Frankfurt)

The base_url for SDK call configuration is https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/compatible-mode/v1

The HTTP request address is POST https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions

Japan (Tokyo)

The base_url for SDK call configuration is https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/compatible-mode/v1

The HTTP request address is POST https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions

China (Hong Kong)

The base_url for SDK call configuration is https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1

The HTTP request address is POST https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1/chat/completions

OpenAI compatible - Responses API

NoteThe following DeepSeek models all support the Responses API: deepseek-v4.1-flash, deepseek-v4.1-flash-1017, deepseek-v4-pro, deepseek-v4-pro-0813, and deepseek-v4-flash-0731. The models available in each region depend on regional availability; see Rate limits.

deepseek-v4.1-flash-1017 supports the Responses API in six regions: China (Beijing), Singapore, US (Virginia), Germany (Frankfurt), Japan (Tokyo), and China (Hong Kong). It supports the three built-in tools web_search, web_extractor, and code_interpreter. For the SDK base_url and POST endpoints in all six regions, see Responses API endpoint configuration.

China (Beijing)

The base_url for SDK call configuration is https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1

HTTP endpoint: POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/responses

Singapore

The base_url for SDK call configuration is https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1

HTTP endpoint: POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/responses

China (Hong Kong)

All four models listed above support the Responses API in China (Hong Kong).

The base_url for SDK call configuration is https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1

HTTP endpoint: POST https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1/responses

DashScope

China (Beijing)

HTTP request address:

  • Plain text models, such as deepseek-v4-pro: POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation
  • Multimodal models, such as deepseek-v4.1-flash and deepseek-v4.1-flash-1017: POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation

The region for SDK call configuration is dashscope.Client(workspace="{WorkspaceId}", region="cn-beijing")

US (Virginia)

HTTP request address:

  • Plain text models, such as deepseek-v4-pro: POST https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation
  • Multimodal models, such as deepseek-v4.1-flash and deepseek-v4.1-flash-1017: POST https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation

The region for SDK call configuration is dashscope.Client(workspace="{WorkspaceId}", region="us-east-1")

Singapore

HTTP request address:

  • Plain text models, such as deepseek-v4-pro: POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation
  • Multimodal models, such as deepseek-v4.1-flash and deepseek-v4.1-flash-1017: POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation

The region for SDK call configuration is dashscope.Client(workspace="{WorkspaceId}", region="ap-southeast-1")

Germany (Frankfurt)

HTTP request address:

  • Plain text models, such as deepseek-v4-pro: POST https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation
  • Multimodal models, such as deepseek-v4.1-flash and deepseek-v4.1-flash-1017: POST https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation

The region for SDK call configuration is dashscope.Client(workspace="{WorkspaceId}", region="eu-central-1")

Japan (Tokyo)

HTTP request address:

  • Plain text models, such as deepseek-v4-pro: POST https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation
  • Multimodal models, such as deepseek-v4.1-flash and deepseek-v4.1-flash-1017: POST https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation

The region for SDK call configuration is dashscope.Client(workspace="{WorkspaceId}", region="ap-northeast-1")

China (Hong Kong)

HTTP request address:

  • Plain text models, such as deepseek-v4-pro: POST https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation
  • Multimodal models, such as deepseek-v4.1-flash and deepseek-v4.1-flash-1017: POST https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation

The region for SDK call configuration is dashscope.Client(workspace="{WorkspaceId}", region="cn-hongkong")

Getting started

deepseek-v4-pro-0813 is the flagship model in the DeepSeek series and excels at programming, math, and general tasks. deepseek-v4-flash-0731 is the latest version of the Flash series. You can use the enable_thinking parameter to switch between thinking and non-thinking modes. The following example shows how to call the deepseek-v4-pro model in thinking mode. You can replace the model parameter with other DeepSeek models.

You must obtain an API key and configure it as an environment variable. If you use an SDK, you must also install the OpenAI or DashScope SDK.

China (Beijing)

OpenAI compatible

NoteThe enable_thinking parameter is not a standard OpenAI parameter. The OpenAI Python SDK passes it through extra_body, while the Node.js SDK passes it as a top-level parameter. The reasoning_effort parameter is a standard OpenAI parameter and can be passed directly as a top-level parameter.

Python

Sample code

from openai import OpenAI
import os
# 初始化OpenAI客户端
client = OpenAI(
    # 如果没有配置环境变量,请用阿里云百炼API Key替换:api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 以下为华北2(北京)地域的URL。请将 {WorkspaceId} 替换为您的百炼业务空间ID,各地域的URL不同。
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
messages = [{"role": "user", "content": "你是谁"}]
completion = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=messages,
    # 通过 extra_body 设置 enable_thinking 开启思考模式
    extra_body={"enable_thinking": True},
    stream=True,
    stream_options={
        "include_usage": True
    },
)
reasoning_content = ""  # 完整思考过程
answer_content = ""  # 完整回复
is_answering = False  # 是否进入回复阶段
print("\n" + "=" * 20 + "思考过程" + "=" * 20 + "\n")
for chunk in completion:
    if not chunk.choices:
        print("\n" + "=" * 20 + "Token 消耗" + "=" * 20 + "\n")
        print(chunk.usage)
        print("Request ID:", chunk.id)
        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
    # 收到content,开始进行回复
    if hasattr(delta, "content") and delta.content:
        if not is_answering:
            print("\n" + "=" * 20 + "完整回复" + "=" * 20 + "\n")
            is_answering = True
        print(delta.content, end="", flush=True)
        answer_content += delta.content

Response

====================思考过程====================
嗯,用户问了一个非常简单的自我介绍问题:"你是谁"。
我需要明确自己的身份,用简洁友好的方式介绍我是DeepSeek,说明我的创造者、基本特性和可提供的帮助。
想到了可以这样组织回答:先直接表明身份,说明由深度求索公司创造,然后列出一些关键特点(免费、长上下文、文件上传等),最后以友好的邀请结束,询问是否需要帮助。
====================完整回复====================
你好!我是 DeepSeek,由深度求索公司创造的 AI 助手。
我可以帮你解答各种问题、进行文字创作、分析文档、编程辅助等等。我最大的特点是**免费使用**、**超长上下文**(能一次处理整本三体三部曲那么多内容)、支持**文件上传**和**联网搜索**(需手动开启)。
有什么我可以帮你的吗?不管是学习、工作还是日常闲聊,我都很乐意陪你聊聊!
====================Token 消耗====================
CompletionUsage(completion_tokens=238, prompt_tokens=5, total_tokens=243, completion_tokens_details=CompletionTokensDetails(accepted_prediction_tokens=None, audio_tokens=None, reasoning_tokens=93, rejected_prediction_tokens=None), prompt_tokens_details=None)
Request ID: chatcmpl-a1b2c3d4-e5f6-7890-abcd-ef1234567890

Node.js

Sample code

import OpenAI from "openai";
import process from 'process';
// 初始化OpenAI客户端
const openai = new OpenAI({
    // 如果没有配置环境变量,请用阿里云百炼API Key替换:apiKey: "sk-xxx"
    apiKey: process.env.DASHSCOPE_API_KEY,
    // 以下为华北2(北京)地域的URL。请将 {WorkspaceId} 替换为您的百炼业务空间ID,各地域的URL不同。
    baseURL: 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1'
});
let reasoningContent = ''; // 完整思考过程
let answerContent = ''; // 完整回复
let isAnswering = false; // 是否进入回复阶段
async function main() {
    try {
        const messages = [{ role: 'user', content: '你是谁' }];
        const stream = await openai.chat.completions.create({
            model: 'deepseek-v4-pro',
            messages,
            // 注意:在 Node.js SDK,enable_thinking 这样的非标准参数作为顶层属性传递,无需放在 extra_body 中
            enable_thinking: true,
            stream: true,
            stream_options: {
                include_usage: true
            },
        });
        console.log('\n' + '='.repeat(20) + '思考过程' + '='.repeat(20) + '\n');
        for await (const chunk of stream) {
            if (!chunk.choices?.length) {
                console.log('\n' + '='.repeat(20) + 'Token 消耗' + '='.repeat(20) + '\n');
                console.log(chunk.usage);
                console.log('Request ID:', chunk.id);
                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;
            }
            // 收到content,开始进行回复
            if (delta.content !== undefined && delta.content) {
                if (!isAnswering) {
                    console.log('\n' + '='.repeat(20) + '完整回复' + '='.repeat(20) + '\n');
                    isAnswering = true;
                }
                process.stdout.write(delta.content);
                answerContent += delta.content;
            }
        }
    } catch (error) {
        console.error('Error:', error);
    }
}
main();

Response

====================思考过程====================
嗯,用户问了一个非常简单的自我介绍问题:"你是谁"。
我需要明确自己的身份,用简洁友好的方式介绍我是DeepSeek,说明我的创造者、基本特性和可提供的帮助。
想到了可以这样组织回答:先直接表明身份,说明由深度求索公司创造,然后列出一些关键特点(免费、长上下文、文件上传等),最后以友好的邀请结束,询问是否需要帮助。
====================完整回复====================
你好!我是 DeepSeek,由深度求索公司创造的 AI 助手。
我可以帮你解答各种问题、进行文字创作、分析文档、编程辅助等等。我最大的特点是**免费使用**、**超长上下文**(能一次处理整本三体三部曲那么多内容)、支持**文件上传**和**联网搜索**(需手动开启)。
有什么我可以帮你的吗?不管是学习、工作还是日常闲聊,我都很乐意陪你聊聊!
====================Token 消耗====================
{
  prompt_tokens: 5,
  completion_tokens: 243,
  total_tokens: 248,
  completion_tokens_details: { reasoning_tokens: 83 }
}
Request ID: chatcmpl-a1b2c3d4-e5f6-7890-abcd-ef1234567890

HTTP

Sample code

curl

# 以下为华北2(北京)地域的URL。请将 {WorkspaceId} 替换为您的百炼业务空间ID,各地域的URL不同。
curl -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "deepseek-v4-pro",
    "messages": [
        {
            "role": "user",
            "content": "你是谁"
        }
    ],
    "stream": true,
    "stream_options": {
        "include_usage": true
    },
    "enable_thinking": true
}'

DashScope

Python

Sample code

import os
import dashscope
# 以下为华北2(北京)地域的配置,调用时请将 {WorkspaceId} 替换为真实的业务空间ID,各地域的region取值不同。
client = dashscope.Client(
    # 如果没有配置环境变量,请用阿里云百炼API Key替换:api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    workspace="{WorkspaceId}",
    region="cn-beijing",
)
# 初始化请求参数
messages = [{"role": "user", "content": "你是谁?"}]
completion = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=messages,
    enable_thinking=True,
    stream=True,              # 开启流式输出
)
reasoning_content = ""  # 完整思考过程
answer_content = ""     # 完整回复
is_answering = False    # 是否进入回复阶段
print("\n" + "=" * 20 + "思考过程" + "=" * 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
    # 收到 content,开始进行回复
    if message.content:
        if not is_answering:
            print("\n" + "=" * 20 + "完整回复" + "=" * 20 + "\n")
            is_answering = True
        print(message.content, end="", flush=True)
        answer_content += message.content
print("\n" + "=" * 20 + "Token 消耗" + "=" * 20 + "\n")
print(chunk.usage)
print("Request ID:", chunk.request_id)

Response

====================思考过程====================
嗯,用户问了一个非常简单的自我介绍问题:"你是谁"。
我需要明确自己的身份,用简洁友好的方式介绍我是DeepSeek,说明我的创造者、基本特性和可提供的帮助。
想到了可以这样组织回答:先直接表明身份,说明由深度求索公司创造,然后列出一些关键特点(免费、长上下文、文件上传等),最后以友好的邀请结束,询问是否需要帮助。
====================完整回复====================
你好!我是 DeepSeek,由深度求索公司创造的 AI 助手。
我可以帮你解答各种问题、进行文字创作、分析文档、编程辅助等等。我最大的特点是**免费使用**、**超长上下文**(能一次处理整本三体三部曲那么多内容)、支持**文件上传**和**联网搜索**(需手动开启)。
有什么我可以帮你的吗?不管是学习、工作还是日常闲聊,我都很乐意陪你聊聊!
====================Token 消耗====================
{"input_tokens": 6, "output_tokens": 240, "total_tokens": 246, "output_tokens_details": {"reasoning_tokens": 92}}
Request ID: 85735883-9062-9c33-a963-0bc12584ee68

Java

Sample code

ImportantThe DashScope Java SDK version must be 2.19.4 or later.

// dashscope SDK的版本 >= 2.19.4
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 com.alibaba.dashscope.utils.Constants;
import io.reactivex.Flowable;
import java.lang.System;
import java.util.Arrays;
public class Main {
    static {
        // 以下为华北2(北京)地域的配置,调用时请将 {WorkspaceId} 替换为真实的业务空间ID,各地域的配置不同。
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";
    }
    private static StringBuilder reasoningContent = new StringBuilder();
    private static StringBuilder finalContent = new StringBuilder();
    private static boolean isFirstPrint = true;
    private static String requestId = "";
    private static void handleGenerationResult(GenerationResult message) {
        requestId = message.getRequestId();
        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("====================思考过程====================");
                isFirstPrint = false;
            }
            System.out.print(reasoning);
        }
        if (content != null && !content.isEmpty()) {
            finalContent.append(content);
            if (!isFirstPrint) {
                System.out.println("\n====================完整回复====================");
                isFirstPrint = true;
            }
            System.out.print(content);
        }
    }
    private static GenerationParam buildGenerationParam(Message userMsg) {
        return GenerationParam.builder()
                // 若没有配置环境变量,请用阿里云百炼API Key将下行替换为:.apiKey("sk-xxx")
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .model("deepseek-v4-pro")
                .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("你是谁?").build();
            streamCallWithMessage(gen, userMsg);
            System.out.println("\nRequest ID: " + requestId);
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.err.println("An exception occurred: " + e.getMessage());
        }
    }
}

Response

====================思考过程====================
嗯,用户问了一个非常简单的自我介绍问题:"你是谁"。
我需要明确自己的身份,用简洁友好的方式介绍我是DeepSeek,说明我的创造者、基本特性和可提供的帮助。
想到了可以这样组织回答:先直接表明身份,说明由深度求索公司创造,然后列出一些关键特点(免费、长上下文、文件上传等),最后以友好的邀请结束,询问是否需要帮助。
====================完整回复====================
你好!我是 DeepSeek,由深度求索公司创造的 AI 助手。
我可以帮你解答各种问题、进行文字创作、分析文档、编程辅助等等。我最大的特点是**免费使用**、**超长上下文**(能一次处理整本三体三部曲那么多内容)、支持**文件上传**和**联网搜索**(需手动开启)。
有什么我可以帮你的吗?不管是学习、工作还是日常闲聊,我都很乐意陪你聊聊!

HTTP

Sample code

curl

# 以下为华北2(北京)地域的URL。请将 {WorkspaceId} 替换为您的百炼业务空间ID,各地域的URL不同。
curl -X POST "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.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",
    "input":{
        "messages":[
            {
                "role": "user",
                "content": "你是谁?"
            }
        ]
    },
    "parameters":{
        "enable_thinking": true,
        "incremental_output": true,
        "result_format": "message"
    }
}'

Anthropic compatible

Authentication: Pass your Model Studio API key in either the x-api-key header or the Authorization: Bearer header. For details about parameters such as thinking mode, see Anthropic-compatible Messages.

Python

Sample code

import anthropic
import os

client = anthropic.Anthropic(
    # 如果没有配置环境变量,请用阿里云百炼API Key替换:api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 以下为华北2(北京)地域的URL。请将 {WorkspaceId} 替换为您的百炼业务空间ID,各地域的URL不同。
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/apps/anthropic",
)

message = client.messages.create(
    model="deepseek-v4-pro",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "你是谁"}
    ],
    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)

HTTP

Sample code

curl

# 以下为华北2(北京)地域的URL。请将 {WorkspaceId} 替换为您的百炼业务空间ID,各地域的URL不同。
curl -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.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",
    "max_tokens": 1024,
    "messages": [
        {
            "role": "user",
            "content": "你是谁"
        }
    ]
}'

China (Hong Kong)

The following example calls deepseek-v4.1-flash-1017 in China (Hong Kong) through the OpenAI-compatible Chat Completions API. Use an API key for China (Hong Kong) and replace {WorkspaceId} with your workspace ID in that region. API keys and workspace-specific endpoints cannot be shared across regions.

from openai import OpenAI
import os

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1",
)

completion = client.chat.completions.create(
    model="deepseek-v4.1-flash-1017",
    messages=[{"role": "user", "content": "你是谁"}],
)

print(completion.choices[0].message.content)
curl -X POST "https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1/chat/completions" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
  "model": "deepseek-v4.1-flash-1017",
  "messages": [{"role": "user", "content": "你是谁"}]
}'

For the China (Hong Kong) endpoints for DashScope and the Responses API, see Service endpoints. For the Anthropic Messages API, set the SDK base_url to https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/apps/anthropic and use POST https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/apps/anthropic/v1/messages for HTTP requests.

Inference strength (reasoning_effort)

The deepseek-v4.1-flash, deepseek-v4-pro, deepseek-v4-flash-0731, and deepseek-v4-pro-0813 models have thinking mode enabled by default. You can adjust the inference strength using the reasoning_effort parameter. The valid values are 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.

OpenAI compatible

from openai import OpenAI
import os
client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 以下为华北2(北京)地域的URL。请将 {WorkspaceId} 替换为您的百炼业务空间ID,各地域的URL不同。
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[{"role": "user", "content": "9.9和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,
    // 以下为华北2(北京)地域的URL。请将 {WorkspaceId} 替换为您的百炼业务空间ID,各地域的URL不同。
    baseURL: "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
});
const completion = await openai.chat.completions.create({
    model: "deepseek-v4-pro",
    messages: [{ role: "user", content: "9.9和9.11哪个大" }],
    reasoning_effort: "high",
});
console.log(completion.choices[0].message.content);
# 以下为华北2(北京)地域的URL。请将 {WorkspaceId} 替换为您的百炼业务空间ID,各地域的URL不同。
curl -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "deepseek-v4-pro",
    "messages": [{"role": "user", "content": "9.9和9.11哪个大"}],
    "reasoning_effort": "high"
}'

DashScope

import os
import dashscope
# 以下为华北2(北京)地域的配置,调用时请将 {WorkspaceId} 替换为真实的业务空间ID,各地域的region取值不同。
client = dashscope.Client(
    # 如果没有配置环境变量,请用阿里云百炼API Key替换:api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    workspace="{WorkspaceId}",
    region="cn-beijing",
)
response = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[{"role": "user", "content": "9.9和9.11哪个大"}],
    parameters={"reasoning_effort": "high"},
)
print(response.choices[0].message.content)

Responses API

deepseek-v4.1-flash, deepseek-v4.1-flash-1017, deepseek-v4-pro, deepseek-v4-pro-0813, and deepseek-v4-flash-0731 all support calls through the OpenAI-compatible Responses API. The models available in each region depend on regional availability. For endpoints, see Service endpoints.

deepseek-v4.1-flash-1017 supports the Responses API in six regions: China (Beijing), Singapore, US (Virginia), Germany (Frankfurt), Japan (Tokyo), and China (Hong Kong). It supports the three built-in tools web_search, web_extractor, and code_interpreter. For the SDK base_url and POST endpoints in all six regions, see Responses API endpoint configuration.

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.

Other features

Model

Multi-turn conversation

Function Calling

Web search

Context cache

Structured output

Partial mode

deepseek-v4.1-flash-1017

Supported

Supported

Supported

Supported (implicit caching)

Supported

Not supported

deepseek-v4.1-flash

Supported

Supported

Supported

Supported

Supported

Not supported

deepseek-v4-pro

Supported

Supported

Supported

Supported

Supported

Not supported

deepseek-v4-flash-0731

Supported

Supported

Supported

Supported

JSON Object supported; JSON Schema not supported

Not supported

Distilled models

Supported

Not supported

Not supported

Not supported

Not supported

Not supported

deepseek-v4.1-flash-1017 supports the OpenAI-compatible Chat Completions API, the Anthropic Messages API, and thinking; it does not support batch calls or fine-tuning.

Default parameter values

Model

temperature

top_p

repetition_penalty

presence_penalty

max_tokens

thinking_budget

deepseek-v4.1-flash-1017

1.0

1.0

-

-

393,216

-

deepseek-v4.1-flash

1.0

1.0

-

-

393,216

-

deepseek-v4-pro

1.0

1.0

-

-

393,216 in total

deepseek-v4-flash-0731

1.0

1.0

-

-

393,216 in total

Distilled version

0.6

0.95

-

1

16,384

16,384

  • A hyphen (-) indicates that the parameter has no default value and cannot be set.
  • The distilled models do not support setting these parameter values.
  • "393,216 in total" indicates that for the models marked with this value, max_tokens and thinking_budget share the same limit, and their combined maximum is 393,216 tokens (the maximum output length of the model).
  • deepseek-v4.1-flash ignores the thinking_budget parameter (consistent with DeepSeek's official behavior), so setting it has no effect. The maximum number of output tokens (including the chain of thought) is limited by max_tokens or max_completion_tokens.
  • For parameter definitions, see OpenAI compatible - Chat.

Models and billing

  • Hybrid thinking models (use the enable_thinking parameter to control thinking mode): deepseek-v4.1-flash, deepseek-v4-pro, and deepseek-v4-flash-0731

deepseek-v4-pro excels at programming, math, and general tasks. deepseek-v4-flash-0731 is fast and cost-effective. We recommend that you prioritize using deepseek-v4-pro.

For information about model context length and pricing, see the Model Studio console.

Billing is based on the number of input and output tokens.

In thinking mode, the chain-of-thought is billed as output tokens.

FAQ

How do I purchase tokens after my free quota is used up?

You can go to the Expenses and Costs center to top up your account. To call DeepSeek models, ensure that your account has no overdue payments.

Calls to DeepSeek models are automatically charged. The billing cycle is minute-based. To view your consumption details, go to Bill Details.

How do I connect toChatbox,Cherry Studio, orDify?

This section uses common developer tools as examples. The connection method for other LLM tools is similar.

Chatbox

For more information, see Chatbox.

Cherry Studio

For more information, see Cherry Studio.

Can I upload images or documents to ask questions?

deepseek-v4.1-flash and deepseek-v4.1-flash-1017 support text and image input and text-only output. For other models, see the corresponding model information page for supported input modalities. For image input, you can also use the Qwen-VL model. For document input, use the Qwen-Long model.

How do I view token usage and the number of calls?

Model call metrics are visible in monitoring charts within minutes after the call. Log on to the Models page, select Operations management > Monitoring in the left-side navigation pane to go to the monitoring overview page, set query conditions (for example, time range and workspace), then locate the target model in the Models section and click View details to view the call statistics for the model. For more information, see the Models documentation.

Monitoring data is updated at the minute level and is for reference only. It is not used as a basis for billing.

What are the other ways to use DeepSeek?

You can use DeepSeek on the Model Studio platform in three ways:

  1. Online experience: Go to the Model Marketplace.
  2. API or client calls: Call the model using an API or a client such as Chatbox. For more information, see this topic.
  3. Zero-code application building: Build LLM applications with zero code. For more information, see Agent application or Workflow application.

To deploy DeepSeek on your own, see the technical solution.

Error codes

If an error occurs during execution, see Error codes for a solution.