Skip to main content
Third-party model integration tutorial

DeepSeek

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.

The deepseek-v3, deepseek-v3.1, deepseek-v3.2, deepseek-v3.2-exp, deepseek-r1, deepseek-r1-0528, and deepseek-r1-distill-qwen-7b/14b/32b models will be delisted on October 10, 2026. We recommend that you use the following models instead: qwen3.7-plus, qwen3.7-max, and qwen3.6-flash.

Service endpoints

The service endpoint is different for each region. Configure the Base URL based on your selected region (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.
  • OpenAI compatible
  • OpenAI compatible - Responses API
  • DashScope
  • China (Beijing)
  • US (Virginia)
  • Singapore
  • Germany (Frankfurt)
  • Japan (Tokyo)
The base_url for SDK call configuration is https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1The HTTP request address is POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions

Getting started

deepseek-v4-pro is the flagship model in the DeepSeek series and excels at programming, math, and general tasks. deepseek-v4-flash-0731 is the latest released version. 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 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.
  • OpenAI compatible
  • DashScope
  • Anthropic compatible
The 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
  • Node.js
  • HTTP

Sample code

from openai import OpenAI
import os

# Initialize the OpenAI client
client = OpenAI(
    # If the environment variable is not configured, replace it with your Alibaba Cloud Model Studio API key: api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # Singapore region. Replace {WorkspaceId} with your Bailian workspace ID. URLs vary by region.
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)

messages = [{"role": "user", "content": "Who are you?"}]
completion = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=messages,
    # Use extra_body to set enable_thinking and enable thinking mode
    extra_body={"enable_thinking": True},
    stream=True,
    stream_options={
        "include_usage": True
    },
)

reasoning_content = ""  # Complete thinking process
answer_content = ""  # Complete response
is_answering = False  # Indicates whether the response phase has started
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)
        print("Request ID:", chunk.id)
        continue

    delta = chunk.choices[0].delta

    # Collect only the thinking content
    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

    # After receiving content, start generating the response
    if hasattr(delta, "content") and delta.content:
        if not is_answering:
            print("\n" + "=" * 20 + "Complete Response" + "=" * 20 + "\n")
            is_answering = True
        print(delta.content, end="", flush=True)
        answer_content += delta.content

Response

====================Thinking Process====================
Okay, the user asked a very simple self-introduction question: "Who are you?".
I need to clarify my identity, introduce myself as DeepSeek in a concise and friendly way, mention my creator, basic features, and the help I can provide.
I can organize the answer like this: first, state my identity directly, mention I was created by the DeepSeek company, then list some key features (free, long context, file upload, etc.), and finally end with a friendly invitation, asking if I can help.
====================Complete Response====================
Hello! I am DeepSeek, an AI assistant created by the DeepSeek company.
I can help you answer various questions, create text, analyze documents, assist with programming, and more. My main features are that I am **free to use**, have a **super long context** (I can process the entire 'The Three-Body Problem' trilogy at once), and support **file uploads** and **web search** (must be enabled manually).
Is there anything I can help you with? Whether it's for study, work, or just a casual chat, I'm happy to talk with you!
====================Token Usage====================
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

Inference strength (reasoning_effort)

The deepseek-v4-pro, deepseek-v4-flash, and deepseek-v4-flash-0731 models have thinking mode enabled by default. You can adjust the inference strength using the reasoning_effort parameter. The valid values are low, medium, high, xhigh, and max. The default value is high.
low and medium produce the same behavior as high. xhigh produces the same behavior as max.
  • OpenAI compatible
  • DashScope
Python
from openai import OpenAI
import os
client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # China (Beijing) region. Replace {WorkspaceId} with your Bailian workspace ID. URLs vary by region.
    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": "Which is greater, 9.9 or 9.11?"}],
    reasoning_effort="high",
)
print(completion.choices[0].message.content)

Responses API

deepseek-v4-flash, deepseek-v4-flash-0731, deepseek-v4-pro, and deepseek-v4-pro-0813 support calls through the OpenAI-compatible Responses API. Only the China (Beijing) and Singapore regions are supported. For endpoints, see Service endpoints. 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.
Python
from openai import OpenAI
import os

client = OpenAI(
    # If the environment variable is not configured, replace the following line with your Model Studio API key: api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # The following URL is for the Singapore region. For the other region, use https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)

response = client.responses.create(
    model="deepseek-v4-flash",
    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)

Other features

ModelMulti-turn conversationFunction CallingContext cacheStructured outputPrefix Completion
deepseek-v4-proSupportedSupportedSupportedSupportedNot supported
deepseek-v4-pro-usSupportedSupportedSupportedSupportedNot supported
deepseek-v4-flash-0731SupportedSupportedSupportedSupportedNot supported
deepseek-v4-flashSupportedSupportedSupportedSupportedNot supported
deepseek-v4-flash-usSupportedSupportedSupportedSupportedNot supported
deepseek-v3.2SupportedSupportedSupportedNot supportedNot supported
deepseek-v3.2-expSupportedSupported
Only non-thinking mode is supported.
Not supportedNot supportedNot supported
deepseek-v3.1SupportedSupported
Only non-thinking mode is supported.
SupportedNot supportedNot supported
deepseek-r1SupportedSupportedSupportedNot supportedNot supported
deepseek-r1-0528SupportedSupportedNot supportedNot supportedNot supported
deepseek-v3SupportedSupportedSupportedNot supportedNot supported
Distilled modelsSupportedNot supportedNot supportedNot supportedNot supported

Default parameter values

Model

temperature

top_p

repetition_penalty

presence_penalty

max_tokens

thinking_budget

deepseek-v4-pro

1.0

1.0

-

-

393,216 in total

deepseek-v4-pro-us

1.0

1.0

-

-

393,216 in total

deepseek-v4-flash-0731

1.0

1.0

-

-

393,216 in total

deepseek-v4-flash

1.0

1.0

-

-

393,216 in total

deepseek-v4-flash-us

1.0

1.0

-

-

393,216 in total

deepseek-v3.2

1.0

0.95

-

-

65,536

32,768

deepseek-v3.2-exp

0.6

0.95

1.0

-

65,536

32,768

deepseek-v3.1

0.6

0.95

1.0

-

65,536

32,768

deepseek-r1

0.6

0.95

-

1

16,384

32,768

deepseek-r1-0528

0.6

0.95

-

1

16,384

32,768

Distilled version

0.6

0.95

-

1

16,384

16,384

deepseek-v3

0.7

0.6

-

-

16,384

-

  • A hyphen (-) indicates that the parameter has no default value and cannot be set.
  • The deepseek-r1, deepseek-r1-0528, and distilled models do not support setting these parameter values.
  • "393,216 in total" indicates that for deepseek-v4 series models, max_tokens and thinking_budget share the same limit, and their combined maximum is 393,216 tokens (the maximum output length of the model).
  • For parameter definitions, see OpenAI compatible - Chat.

Models and billing

  • Hybrid thinking models (use the enable_thinking parameter to control thinking mode): deepseek-v4-pro, deepseek-v4-flash, deepseek-v4-flash-0731, deepseek-v3.2, deepseek-v3.2-exp, and deepseek-v3.1
  • Thinking-only models (always think before responding): deepseek-r1 and deepseek-r1-0528
  • Non-thinking models: deepseek-v3
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

Can I upload images or documents to ask questions?

DeepSeek models support only text input, not image or document input. For image input, use the Qwen-VL model. For document input, use the Qwen-Long model.

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

One hour after a model call is complete, you can go to the Model Monitoring page and set the query conditions, such as the time range and workspace. Then, in the Models area, find the target model and click Monitor in the Actions column to view the call statistics for the model. For more information, see the Model monitoring document.
Data is updated hourly. During peak hours, data updates may be delayed by up to one hour.

Error codes

If an error occurs during execution, see Error codes for a solution.
Token Plan
Model Playground
  • Music generation
Statistics and Monitoring
Support