Skip to main content
Text generation

Deep thinking

Deep thinking models reason before responding, improving accuracy on complex tasks like logical reasoning and math.

This article describes how to call the Deep Think model via the OpenAI-compatible Chat Completion interface or the DashScope interface. For Responses API usage, see: Deep Think.

Demo

The following is a conversation example of the Deep Think model, showing how the model first performs reasoning and then gives an answer.

User Question

9.9 and 9.11, which is larger

Thinking Process(reasoning_content field)

First, the user's question is: "9.9 and 9.11, which is larger", which appears to be comparing two numbers: 9.9 and 9.11.

I need to understand the meaning of these numbers. In mathematics, 9.9 is equivalent to 9.90, and 9.11 is 9.11.

To compare them, I should treat them as decimals. 9.9 is 9 + 9/10 = 9.9, while 9.11 is 9 + 11/100 = 9.11.

Now, compare 9.9 and 9.11: 9.9 is equal to 9.90 (because 9.9 = 9.90), 9.11 is 9.11. Now, compare 9.90 with 9.11: 9.90 is greater than 9.11, because 90/100 > 11/100.

More precisely: 9.9 = 99/10 = 990/100, 9.11 = 911/100, compare 990/100 with 911/100, obviously 990 > 911, so 990/100 > 911/100, therefore 9.9 > 9.11.

I can also directly look at the decimal part: the decimal part of 9.9 is 0.9, the decimal part of 9.11 is 0.11. 0.9 is greater than 0.11, because 0.9 = 0.90 > 0.11.

So, 9.9 is greater than 9.11.

Model answer(content field)

Conclusion: 9.9 is greater than 9.11.

Usage

Bailian Deep Think Model is divided into two modes:
  • Hybrid thinking mode: You can Enable or Disable thinking per request; the control Parameter varies by Model. The following example uses enable_thinking, with the following values:
    • set totrue: the Model thinks first and then replies;
    • set tofalse: the Model replies directly;
    • OpenAI Compatible
    • DashScope
    # 导入依赖与创建客户端...
    completion = client.chat.completions.create(
        model="qwen3.8-max", # 选择模型
        messages=[{"role": "user", "content": "你是谁"}],
        # 由于 enable_thinking 非 OpenAI 标准参数,需要通过 extra_body 传入
        extra_body={"enable_thinking":True},
        # 流式输出方式调用
        stream=True,
        # 使流式返回的最后一个数据包包含Token消耗信息
        stream_options={
            "include_usage": True
        }
    )
    
  • Only Think Mode: The Model always thinks before replying and cannot be disabled. Except that no need to set the enable_thinking Parameter, the request format is consistent with the Hybrid Think Mode.
The thinking content is returned through thereasoning_content Field, and the reply content is returned through thecontent Field. Deep Think requires additional reasoning time. The examples in this article use stream calling by default (Recommend, you can view the Thinking Process in real time and avoid long waits). The commercial version Deep Think Model also supports non-stream (synchronous) Output. For the usage and precautions, see the FAQ below; some Models (such as qwen3.5-122b-a10b, qwen3.5-27b and other open-source versions) only support Stream, and non-stream calling will report an Error.

Supported Models

  • Qwen3.8
  • Qwen3.7
  • Qwen3.6
  • Qwen3.5
  • Kimi
  • Qwen3
  • DeepSeek
  • GLM
  • MiniMax
  • Stepfun
Qwen3.8 Max Series (Hybrid thinking mode, Default Enable thinking mode): qwen3.8-max, qwen3.8-max-0902Qwen3.8 Flash series (Hybrid thinking mode, Default Enable thinking mode): qwen3.8-flashQwen3.8 open source series (Hybrid thinking mode, Default Enable thinking mode): qwen3.8-27bQwen3.8 open source series (Only supports thinking mode): qwen3.8-2.4t-a95bQwen3.8 Omni series (Hybrid thinking mode, Default Enable thinking mode): qwen3.8-omni-flash. Pass reasoning_effort to adjust thinking intensity. For more information, see thinking mode configuration.

Quick Start

API Use prerequisite: alreadyObtain and Configure API Keyand completeConfigure API Key to environment variables. If Pass SDK Calling, needInstall OpenAI Or DashScope SDK(DashScope Java SDK requires no lower than 2.19.4 Version). The following code takes stream Calling qwen3.8-max Enable thinking mode as an example.
  • OpenAI Compatible
  • DashScope
  • Python
  • Node.js
  • HTTP

Sample Code

from openai import OpenAI
import os

# 初始化OpenAI客户端
client = OpenAI(
    # 如果没有配置环境变量,请用阿里云百炼API Key替换:api_key="sk-xxx"
    # 各地域的API Key不同。获取API Key:https://help.aliyun.com/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 以下为华北2(北京)地域的配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)

messages = [{"role": "user", "content": "你是谁"}]

completion = client.chat.completions.create(
    model="qwen3.8-max",  # 您可以按需更换为其它深度思考模型
    messages=messages,
    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("\nUsage:")
        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

    # 收到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

====================思考过程====================

好的,用户问“你是谁”,我需要给出一个准确且友好的回答。首先,我要确认自己的身份,即千问,由阿里巴巴集团旗下的通义实验室研发。接下来,应该说明我的主要功能,比如回答问题、创作文字、逻辑推理等。同时,要保持语气亲切,避免过于技术化,让用户感觉轻松。还要注意不要使用复杂术语,确保回答简洁明了。另外,可能需要加入一些互动元素,邀请用户提问,促进进一步交流。最后,检查是否有遗漏的重要信息,比如我的中文名称“千问”和英文名称“Qwen”,以及所属公司和实验室。确保回答全面且符合用户期望。
====================完整回复====================

你好!我是千问,是阿里巴巴集团旗下的通义实验室自主研发的超大规模语言模型。我可以回答问题、创作文字、进行逻辑推理、编程等,旨在为用户提供高质量的信息和服务。你可以叫我Qwen,或者直接叫我千问。有什么我可以帮你的吗?

Core Capabilities

Switch Thinking/Non-Thinking Mode

Enabling thinking mode improves response quality, but increases response latency and Token consumption. When using a model with hybrid thinking mode, you can dynamically switch based on question complexity without changing the model:
  • Simple tasks (daily chat, simple Q&A): Set enable_thinkingto falseDisable thinking;
  • Complex tasks (logical reasoning, code generation, math problem solving): Set enable_thinkingSet totrueEnable thinking.
  • OpenAI Compatible
  • DashScope
enable_thinkingNon-OpenAI standard parameter. If using the OpenAI Python SDK, pass it via extra_body. In the Node.js SDK, pass it as a top-level parameter.
  • Python
  • Node.js
  • HTTP

Sample Code

from openai import OpenAI
import os

# 初始化OpenAI客户端
client = OpenAI(
    # 如果没有配置环境变量,请用阿里云百炼API Key替换:api_key="sk-xxx"
    # 各地域的API Key不同。获取API Key:https://help.aliyun.com/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 以下为华北2(北京)地域的配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)

messages = [{"role": "user", "content": "你是谁"}]
completion = client.chat.completions.create(
    model="qwen3.8-max",
    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)
        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

====================思考过程====================

嗯,用户问“你是谁”,我需要先确定他们想知道什么。可能他们第一次接触我,或者想确认我的身份。我应该先介绍自己是千问,由通义实验室研发。然后要说明我的功能,比如回答问题、创作文字、编程等,这样用户了解我能提供什么帮助。还要提到我支持多种语言,这样国际用户也会知道他们可以用不同语言交流。最后保持友好,邀请他们提问,这样可以促进进一步互动。要注意简洁明了,避免技术术语太多,让用户容易理解。可能用户需要的是快速了解我的能力,所以重点放在功能和用途上。还要检查有没有遗漏的信息,比如是否要提到阿里巴巴集团,或者更多技术细节。不过用户可能只需要基本的信息,不需要太深入。确保回答友好且专业,同时鼓励用户继续提问。
====================完整回复====================

我是千问,由通义实验室研发的超大规模语言模型。我可以帮助你回答问题、创作文字、编程、表达观点等,支持多语言交流。有什么需要我帮忙的吗?
====================Token 消耗====================

CompletionUsage(completion_tokens=221, prompt_tokens=10, total_tokens=231, completion_tokens_details=CompletionTokensDetails(accepted_prediction_tokens=None, audio_tokens=None, reasoning_tokens=172, rejected_prediction_tokens=None), prompt_tokens_details=PromptTokensDetails(audio_tokens=None, cached_tokens=0))
Additionally, Qwen3 open-source hybrid thinking model and the qwen-plus-2025-04-28 modelSupports dynamically controlling the thinking mode through prompts.enable_thinkingWhen true, add the following to the prompt: /no_think to disable thinking; to re-enable it in multi-turn conversations, add to the latest prompt: /think . The Model always follows the latest /think or /no_think instruction.

Limit Thinking Length

Deep Think Model s may sometimes generate lengthy reasoning processes, increasing wait time and consuming more Token s. Through the thinking_budget Parameter , you can set the maximum Token count for the reasoning process; once the limit is exceeded, the Model immediately outputs the Response.
thinking_budget The default value is the maximum chain-of-thought length of the model. Please see the model card in the Bailian console.
thinking_budgetThe parameter is used to set the maximum number of Tokens in the Thinking Process. It applies to Qwen3.8, Qwen3.7, Qwen3.6, Qwen3.5, Qwen3-VL, Qwen3, GLM (Alibaba Cloud direct supply), and Kimi (Alibaba Cloud direct supply) series models. Among them, kimi-k3 does not support this parameter.

Experience Deep Think in the console

  1. Log in to the Bailian console on the large model service platform.
  2. In the left navigation pane, selectExperience Center > Text.
  3. The page displays the Qwen3.7-Max model by default. You can also click the model name and select other Qwen3 series models from the drop-down list.
  4. Click at the bottom of the input boxDeep Think, enable reasoning mode to view the Thinking Process of the Model.
  5. Click the top-right Debugging, in the opened Settings panel configure the thinking_budgetParameter, control the maximum number of Tokens in the Chain of Thought Output, value range 1-32768, Default Value 4000. For more information, see Bailian Models.
  • OpenAI Compatible
  • DashScope
  • Python
  • Node.js
  • HTTP

Sample Code

from openai import OpenAI
import os

# 初始化OpenAI客户端
client = OpenAI(
    # 如果没有配置环境变量,请用阿里云百炼API Key替换:api_key="sk-xxx"
    # 各地域的API Key不同。获取API Key:https://help.aliyun.com/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 以下为华北2(北京)地域的配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)

messages = [{"role": "user", "content": "你是谁"}]

completion = client.chat.completions.create(
    model="qwen3.8-max",
    messages=messages,
    # enable_thinking 参数开启思考过程,thinking_budget 参数设置最大推理过程 Token 数
    extra_body={
        "enable_thinking": True,
        "thinking_budget": 50
        },
    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("\nUsage:")
        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

    # 收到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

====================思考过程====================

好的,用户问“你是谁”,我需要给出一个清晰且友好的回答。首先,应该明确自己的身份,即千问,由阿里巴巴集团旗下的通义实验室研发。接下来,要说明自己的主要功能,比如回答
====================完整回复====================

我是千问,是阿里巴巴集团旗下的通义实验室研发的超大规模语言模型。我能够回答问题、创作文字、逻辑推理、编程等,旨在为用户提供帮助和便利。有什么我可以帮您的吗?

Pass Thinking Process

In multi-turn conversations, preserve_thinking controls whether the model reads from historical assistant messages reasoning_content. When set to true, these thinking contents will be appended to the next round's input. The client needs to, in the request's messages, provide historical assistant messages and their reasoning_content. The default value of each model is subject to Chat Completions Parameter Description.
preserve_thinkingThe Parameter supports only qwen3.8-max, qwen3.8-max-0902, qwen3.8-omni-flash (Enable by default), qwen3.7-max, qwen3.7-max-2026-05-20, qwen3.7-max-2026-06-08, qwen3.7-max-preview, qwen3.7-max-2026-05-17, qwen3.7-plus, qwen3.7-plus-2026-05-26, qwen3.6-plus, qwen3.6-plus-2026-04-02, qwen3.7-flash, qwen3.7-flash-2026-07-15, kimi-k2.7-code (Alibaba Cloud ModelStudio deployment), kimi-k2.6 (Alibaba Cloud ModelStudio deployment), kimi/kimi-k3 (Moonshot deployment), kimi/kimi-k2.7-code-highspeed (Moonshot deployment), kimi/kimi-k2.7-code (Moonshot deployment), and kimi/kimi-k2.6 (Moonshot deployment).
For the above models that support this parameter—Qwen3.8 Max, Qwen3.7, Qwen3.6 and Kimi—if the history messages do not contain reasoning_content, enabling this parameter will not cause an error.
After enabling it, the reasoning_content in the history messages will be counted toward the input Token quantity and billing.
  • OpenAI Compatible
  • DashScope
preserve_thinkingNon-OpenAI standard parameter. When using the Python SDK, you must pass it in viaextra_body.
  • Python
  • Node.js
  • HTTP

Sample Code

from openai import OpenAI
import os

client = OpenAI(
    # 如果没有配置环境变量,请用阿里云百炼API Key替换:api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)

# 第一轮对话
messages = [
    {"role": "user", "content": "我需要为一个日均千万消息的电商系统选择消息队列,请推荐"}
]

first_reasoning = ""
first_content = ""
is_answering = False

completion = client.chat.completions.create(
    model="qwen3.8-max",
    messages=messages,
    extra_body={"enable_thinking": True},
    stream=True,
    stream_options={"include_usage": True},
)

print("=" * 20 + "第一轮思考过程" + "=" * 20)

for chunk in completion:
    if not chunk.choices:
        continue
    delta = chunk.choices[0].delta
    if hasattr(delta, "reasoning_content") and delta.reasoning_content is not None:
        first_reasoning += delta.reasoning_content
        if not is_answering:
            print(delta.reasoning_content, end="", flush=True)
    if hasattr(delta, "content") and delta.content:
        if not is_answering:
            print("\n" + "=" * 20 + "第一轮回复" + "=" * 20)
            is_answering = True
        print(delta.content, end="", flush=True)
        first_content += delta.content

# 第二轮对话:传递思考过程,追问模型为什么排除了Kafka
messages = [
    {"role": "user", "content": "我需要为一个日均千万消息的电商系统选择消息队列,请推荐"},
    {
        "role": "assistant",
        "content": first_content,
        "reasoning_content": first_reasoning,
    },
    {"role": "user", "content": "你在对比时为什么排除了Kafka?"},
]

reasoning_content = ""
answer_content = ""
is_answering = False

# preserve_thinking 通过 extra_body 传入
completion = client.chat.completions.create(
    model="qwen3.8-max",
    messages=messages,
    extra_body={
        "enable_thinking": True,
        "preserve_thinking": True,
    },
    stream=True,
    stream_options={"include_usage": True},
)

print("\n" + "=" * 20 + "第二轮思考过程" + "=" * 20)

for chunk in completion:
    if not chunk.choices:
        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 + "第二轮回复" + "=" * 20)
            is_answering = True
        print(delta.content, end="", flush=True)
        answer_content += delta.content

Response

====================第一轮思考过程====================
用户需要为日均千万消息的电商系统选择消息队列。让我从吞吐量、可靠性、延迟消息、事务支持等维度对比主流方案...

RocketMQ:阿里电商场景验证,原生支持事务消息和延迟消息,分区级严格有序...
Kafka:极高吞吐量,但无原生事务消息和延迟消息支持,需自研补偿机制...
RabbitMQ:延迟低,但集群扩展能力有限,峰值万级TPS...
====================第一轮回复====================
综合电商场景的核心需求(事务消息、延迟消息、顺序性、峰值应对),推荐 Apache RocketMQ。如果团队已有 Kafka 生态或需强实时分析能力,Kafka 也是可行方案。
====================第二轮思考过程====================
用户在追问为什么排除了Kafka。回顾我的历史思考过程,我并没有排除Kafka,而是给了它4星评分。让我参考之前的详细对比分析来解释...

在上一轮思考中,我对比了RocketMQ和Kafka在事务消息、延迟消息、顺序性方面的差异。Kafka的劣势主要在于需要额外架构设计来补齐电商特有语义...
====================第二轮回复====================
我并没有排除Kafka。Kafka在吞吐量和生态方面表现优秀,之所以RocketMQ评分略高,是因为电商核心链路的"开箱即用"特性匹配度:RocketMQ原生支持事务消息和延迟消息,而Kafka需要通过Outbox Pattern等架构模式自行实现。如果团队已有Kafka生态,它完全能胜任千万级消息场景。

Other Features

Billing Details

  • Thinking content is billed by Output Token.
  • Some hybrid thinking models have different prices in thinking and non-thinking modes. When the model outputs Thinking Process, all Output Tokens (including thinking Tokens and reply Tokens) are billed at the Output price of thinking mode.
    If the model does not output Thinking Process in thinking mode, it is billed at the non-thinking mode price.

FAQ

Whether thinking mode can be Disabled depends on the model used:
  • Hybrid thinking mode models (such as qwen3.6-plus, deepseek-v4-pro): Set enable_thinking to false to Disable;
  • Thinking-only mode models (such as glm-5.3, kimi-k3): cannot be disabled.
enable_thinking is an extended Parameter of Bailian and does not belong to the OpenAI standard Field. When Using the OpenAI Java SDK, ChatCompletionCreateParams does not natively support this Field, and it needs to be passed through extraBody method:
// enable_thinking 非 OpenAI 标准参数,Java SDK 需通过 extra_body 传递
ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
    .model("qwen3.6-plus")
    .messages(List.of(
        ChatCompletionMessageParam.builder()
            .role(ChatCompletionMessageParamRole.USER)
            .content("你好")
            .build()
    ))
    .extraBody(Map.of("enable_thinking", false))
    .build();

client.chat().completions().create(params);
If the Calling latency difference between thinking mode and non-thinking mode is minimal, it indicates that the thinking mode may not be actually Enabled. Troubleshoot with the following steps:
  1. Check whether the enable_thinking=true Parameter is correctly passed in the API request. When Using the OpenAI Java SDK, this Parameter needs to be passed through extraBody Pass in (see the previous example).
  2. Check whether the response contains reasoning_content Field, and confirm that in usage reasoning_tokens is Greater than 0. If it does not contain this Field Or reasoning_tokens=0 indicates that thinking mode is not enabled.
  3. Compare the response time and completion_tokens. After enabling thinking mode, the response will contain reasoning_content Field, and the total time increases significantly (measured about 3 Times of non-thinking mode); if the time difference between the two is minimal, it indicates that thinking mode is not actually effective, please check whether the Parameter is passed in correctly and retry.
qwen3.7-plus belongs to the hybrid thinking mode Model, and thinking mode is enabled by Default. The Thinking Process generates a large number of reasoning Tokens (measured at over 60% of the total Output Tokens), so the total time of a single Calling is significantly longer than that of the non-thinking mode. At this time, the Token generation speed itself is not abnormal (measured at about 52-54 Tokens/s); the total time difference mainly comes from the number of Tokens generated by the Thinking Process, rather than the Model Or network slowing down.Troubleshooting steps:
  1. Confirm whether thinking mode is enabled. qwen3.7-plus is enabled by default, and you can determine this based on whether the response returns reasoning_content field.
  2. View the response usage for completion_tokens and reasoning_tokens. If reasoning_tokens is high, then the long total time is an expected performance of the thinking mode.
  3. If the Thinking Process is not needed, set enable_thinking to false to Disable the thinking mode. After disabling, Output Token is significantly reduced, and measured total time can be reduced by 60%-75%.
  4. If you need to retain the thinking capability, you can switch toStream, to Obtain the first Token faster and view the Thinking Process in real time, avoiding long waits for the complete response.
The usage statistics display the overall time of a single Calling (including the generation time of Thinking Tokens), not the generation latency of a single Token.
The examples in this article Default to using Stream (Recommend, can view the Thinking Process in real time and avoid long waits). The commercial version Deep Think Model (such as qwen-plus, qwen-flash, etc.) also supports non-stream (synchronous) Output, returning the complete Thinking Process and reply at once.
When changing the stream example to non-stream, please synchronously modify the response parsing code: the non-stream Calling returns the complete Response object (completion), cannot iterate like the stream example via for chunk in completion iterate (otherwise it will report Error 'tuple' object has no attribute 'choices'), but should directly read completion.choices[0].message.reasoning_content(Thinking Process) and completion.choices[0].message.content(reply content). In addition, stream=False cannot set the stream_options Parameter.
The following uses the OpenAI-compatible interface, non-stream Calling of qwen3.8-max with Enable thinking mode as an example:
from openai import OpenAI
import os

client = OpenAI(
    # 如果没有配置环境变量,请用阿里云百炼API Key替换:api_key="sk-xxx"
    # 各地域的API Key不同。获取API Key:https://help.aliyun.com/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 以下为华北2(北京)地域的配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)

completion = client.chat.completions.create(
    model="qwen3.8-max",  # 请替换为支持非流式输出的深度思考模型
    messages=[{"role": "user", "content": "你是谁"}],
    extra_body={"enable_thinking": True},
    stream=False,  # 非流式(同步)输出;stream=False 时不能设置 stream_options
)

# 非流式返回完整响应对象,直接读取 message,无需(也不能)迭代
message = completion.choices[0].message
print("=" * 20 + "思考过程" + "=" * 20 + "\n")
print(getattr(message, "reasoning_content", "") or "")
print("\n" + "=" * 20 + "完整回复" + "=" * 20 + "\n")
print(message.content)
Some models (such as qwen3.5-122b-a10b, qwen3.5-27b open-source versions) only support Stream, non-stream Calling will report an error parameter.enable_thinking only support stream call, for such models please Use stream Calling.
Go to Fees and CostsRecharge at the center to maintain sufficient account balance for normal model calling.
After exceeding the free quota, billing occurs automatically at minute-level intervals. For consumption details, go to ;Bill Details to view.
Refer to the following steps based on the tool you use:
The following uses common tools as examples; other large model tools follow a similar integration approach.
  • Chatbox
  • Cherry Studio
  • Cline
  • Dify
For more information, see Chatbox.
The models covered in this article only support text input. Qwen3-VL, QVQ models support image Deep Think,Qwen- LongModel supports document input.
Please follow the steps below:
  1. Update dependency libraries Update langchain_community and dashscope to the latest version:
pip install -U langchain_community dashscope
  1. Calling Deep Think Model Pass the following code to print the Thinking Process and reply content respectively:
from langchain_community.chat_models.tongyi import ChatTongyi
from langchain_core.messages import HumanMessage

chatLLM = ChatTongyi(
    # 您可按需更换为其它深度思考模型
    model="qwen3.8-max",
    model_kwargs={
        "enable_thinking":True
    }
)
completion = chatLLM.stream(
    [HumanMessage(content="你是谁")])
is_answering = False
print("="*20+"思考过程 "+"="*20)
for chunk in completion:
    if chunk.additional_kwargs.get("reasoning_content"):
        print(chunk.additional_kwargs.get("reasoning_content"),end="",flush=True)
    else:
        if not is_answering:
            print("\n"+"="*20+"回复内容"+"="*20)
            is_answering = True
        print(chunk.content,end="",flush=True)
Sample Output:
====================思考过程 ====================
好的,用户问“你是谁”,我需要给出一个准确且友好的回答。首先,我应该介绍自己的名字和基本功能,让用户了解我的用途。然后,可能需要提到我是通义实验室研发的,这样增加权威性。还要说明我能做什么,比如回答问题、创作文字等,这样用户知道可以怎么使用我。同时,保持语气亲切,避免太技术化的术语,让回答更易懂。另外,可能需要检查是否有遗漏的信息,比如多语言支持或者应用场景,但用户的问题比较基础,可能不需要太详细。最后,确保回答简洁明了,不冗长,符合用户的快速获取信息的需求。
====================回复内容====================
我是Qwen3,是阿里巴巴集团旗下的通义实验室自主研发的超大规模语言模型。我可以帮助你回答问题、创作文字(如写故事、公文、邮件、剧本等)、进行逻辑推理、编程,甚至表达观点和玩游戏。我支持多种语言,包括但不限于中文、英文、德语、法语、西班牙语等,旨在为全球用户提供高效、便捷的服务。如果你有任何问题或需要帮助,欢迎随时告诉我!
Model calls occur withinminutes-levelcan be viewed in monitoring charts. Log in to the Monitoring page (BeijingOrSingapore), select in the left navigation barO&M Management > Monitoringto enter the monitoring overview page, set the query conditions (e.g., select time range, workspace, etc.), then in theModelsarea find the target model and clickView Detailsto view the call statistics of the model. For details, see Monitoring & Alerts docs.
Monitoring data is updated at minute-level and is for reference only; it is not used as a billing basis.
When calling the model with a long prompt, generation failures or response timeouts usually occur because thinking mode is enabled (enable_thinking set to true). Thinking mode increases processing time, and in long-prompt scenarios this may cause the response to be truncated or the request to time out.Solution:
  • Disable thinking mode: Set enable_thinking to false, processing time can be reduced from about 50 s to about 30 s.
  • Enable Stream: Set stream to true to avoid the timeout limit of non-streaming calls.
  • Increase the timeout: If you need to keep thinking mode, set the client timeout to 180 s or more.
This is a client-side issue, not the Model limiting the Output of the Thinking Process. Bailian platform controls the thinking mode switch via the enable_thinking Parameter, and the reasoning_content Field contains the complete Thinking Process content, and the Model will normally return the thinking content. Disconnections are typically caused by client network fluctuations or client version compatibility issues.Troubleshooting steps:
  • Check the stability of the client network connection.
  • Upgrade the client to the latest Version.
  • Check the client logs to confirm the correlation between the disconnection time and the Output of thinking tags.
You can also directly Calling the Model via the DashScope API to verify whether the thinking function works normally.
The safety judgment Output by the visual Model is part of the text generated by the Model and is not an independent content moderation verdict. This conclusion may vary with Model Version and region, and may also be inconsistent with the content description in the same Response, so it is not recommended to use it as the sole basis for content compliance.If you need a stable and unified safety judgment standard, please connect to the AI safety guardrail to conduct independent content moderation on the Model's input and Output. For more information, see AI Safety Guardrail.

API Reference

Deep Think Model input Output Parameter, please seeText Generation.

Error Code

When an error occurs during execution, please seeError Codeto troubleshoot and resolve.
Token Plan
Model Playground
Fine-tuning
Model Compression
Statistics and Monitoring
Support