Skip to main content

DeepSeek-Alibaba Cloud

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.
  • 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"),
    # 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",
)
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.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.
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.
  • 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.1-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.

Other features

ModelMulti-turn conversationFunction CallingWeb searchContext cacheStructured outputPartial mode
deepseek-v4.1-flashSupportedSupportedSupportedSupportedSupportedNot supported
deepseek-v4-proSupportedSupportedSupportedSupportedSupportedNot supported
deepseek-v4-flash-0731SupportedSupportedSupportedSupportedSupportedNot supported
Distilled modelsSupportedNot supportedNot supportedNot supportedNot supportedNot supported

Default parameter values

Model

temperature

top_p

repetition_penalty

presence_penalty

max_tokens

thinking_budget

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 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.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
  • Cherry Studio
  • Dify
For more information, see Chatbox.

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?

You can view the call results in the monitoring chart at the minute level after a model call occurs. Log in to the Model Monitoring page, select O&M Management > Model Monitoring in the left-side navigation pane to enter the monitoring overview page, and set the query conditions (for example, select the time range and workspace). Then, in the Models area, find the target model and click View Details to view the call statistics for the model. For more information, see the Monitoring & Alerts document.
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.
Token Plan
Model Playground
Fine-tuning
Model Compression
Statistics and Monitoring
Support