All Products
Search
Document Center

Alibaba Cloud Model Studio:Deep thinking

Last Updated:Sep 22, 2026

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

本文介绍如何通过 OpenAI 兼容的 Chat Completion 接口或 DashScope 接口调用 Deep Think 模型。 Responses API 用法参见: Deep Think 。

Demo

以下是一个 Deep Think 模型的对话示例,展示模型如何先进行推理再给出回答。

用户提问

9.9 and 9.11,哪个更大?

思考过程(reasoning_content 字段)

首先,用户的问题是:"9.9 and 9.11,哪个更大?",这看起来是在比较两个数字:9.9 和 9.11。

我需要理解这些数字的含义。在数学中,9.9 等同于 9.90,而 9.11 是 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), and 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 look directly at the decimal part: the decimal part of 9.9 is 0.9, and 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 response(content field)

Conclusion: 9.9 is greater than 9.11.

Usage

The Bailian Deep Think Model is divided into two modes:

  • Mixed Thinking Mode: Thinking can be enabled or disabled per request, and the control parameters vary by model. The following example uses enable_thinking, the values are as follows:

    • Set totrue: the model thinks before responding;
    • Set tofalse: the model responds directly;

    OpenAI 兼容

    # 导入依赖与创建客户端...
    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
        }
    )
    

    DashScope

    Qwen3.5 series DashScope API uses a multimodal interface, the following example will throw an error url error, for the calling method, please refer to Enable/Disable Thinking Mode 。

    # 导入依赖...
    
    response = MultiModalConversation.call(
        # 若没有配置环境变量,请用阿里云百炼API Key将下行替换为:api_key = "sk-xxx",
        api_key=os.getenv("DASHSCOPE_API_KEY"),
        # 可按需更换为其它深度思考模型
        model="qwen3.8-max",
        messages=messages,
        enable_thinking=True,
        stream=True,
        incremental_output=True
    )
    
  • Thinking-only mode: The model always thinks before replying and cannot be disabled. Except that you do not need to set the enable_thinking parameter, the request format is consistent with the hybrid thinking mode.

The thinking content is returned through thereasoning_contentfield, and the reply content is returned through thecontentfield. Deep Think requires additional reasoning time. The examples in this article use streaming calling by default (recommended, you can view the Thinking Process in real time and avoid long waits). The commercial Deep Think model also supports non-streaming (synchronous) Output. For usage and precautions, see theFAQbelow; some models (such as qwen3-235b-a22b, qwen3-32b and other open-source versions) only support Stream Output, and non-streaming calling will report an error.

Supported Models

Qwen3.8

Qwen3.8 Max Series(Hybrid thinking mode, thinking mode enabled by default):qwen3.8-max

Qwen3.8 Flash series(Hybrid thinking mode, thinking mode enabled by default):qwen3.8-flash

Qwen3.8 open-source series(Hybrid thinking mode, thinking mode enabled by default):qwen3.8-27b

Qwen3.8 open-source series(Supports thinking mode only):qwen3.8-2.4t-a95b

Qwen3.8 Omni series(Hybrid thinking mode, thinking mode enabled by default): qwen3.8-omni-flash. Adjust thinking effort via reasoning_effort, for more information, see Thinking mode configuration。

Qwen3.7

Qwen3.7 Max series(Hybrid thinking mode, thinking mode enabled by default):qwen3.7-max、qwen3.7-max-2026-05-20、qwen3.7-max-2026-06-08

Qwen3.7 Max series(Only thinking mode supported):qwen3.7-max-preview、qwen3.7-max-2026-05-17

Qwen3.7 Plus series(Hybrid thinking mode, thinking mode enabled by default):qwen3.7-plus、qwen3.7-plus-2026-05-26

Qwen3.7 Flash series(Hybrid thinking mode, thinking mode enabled by default):qwen3.7-flash、qwen3.7-flash-2026-07-15

Qwen3.6

Qwen3.6 Max series(Hybrid thinking mode, thinking mode enabled by default):qwen3.6-max-preview

Qwen3.6 Plus Series(Hybrid Thinking Mode,Thinking mode enabled by default):qwen3.6-plus、qwen3.6-plus-2026-04-02

Qwen3.6 Flash Series(Hybrid Thinking Mode,Thinking mode enabled by default):qwen3.6-flash、qwen3.6-flash-2026-04-16

Qwen3.6 Open Source Edition:qwen3.6-35b-a3b

Qwen3.5

  • Commercial Edition
    • Qwen3.5 Plus Series(Hybrid Thinking Mode,Thinking mode enabled by default):qwen3.5-plus、qwen3.5-plus-2026-02-15
    • Qwen3.5 Flash series(Hybrid thinking mode, Thinking mode enabled by default):qwen3.5-flash、qwen3.5-flash-2026-02-23
  • Open-source version
    • Hybrid thinking mode, Thinking mode enabled by default:qwen3.5-397b-a17b、 qwen3.5-122b-a10b、qwen3.5-27b、qwen3.5-35b-a3b

Qwen3

  • Commercial version
    • Qwen Max series: qwen3-max, qwen3-max-2026-01-23, qwen3-max-preview (Hybrid thinking mode, thinking mode disabled by default)
    • Qwen Plus Series(Hybrid thinking mode, thinking mode not enabled by default):qwen-plus、qwen-plus-latest、qwen-plus-2025-04-28 及之后的快照版模型
    • Qwen Flash Series(Hybrid thinking mode, thinking mode not enabled by default):qwen-flash、qwen-flash-2025-07-28 及之后的快照版模型
    • Qwen Turbo Series(Hybrid thinking mode, thinking mode not enabled by default):qwen-turbo 及之后的快照版模型
  • Open Source Version
    • Hybrid thinking mode, thinking mode enabled by default:qwen3-235b-a22b、qwen3-32b、qwen3-30b-a3b、qwen3-14b、qwen3-8b
    • Thinking mode only:qwen3-next-80b-a3b-thinking、qwen3-235b-a22b-thinking-2507、qwen3-30b-a3b-thinking-2507

QwQ (基于 Qwen2.5)

Thinking mode only:qwq-plus

DeepSeek

  • Hybrid thinking mode, thinking mode enabled by default: deepseek-v4.1-flash、deepseek-v4-pro、deepseek-v4-flash
  • Hybrid thinking mode, thinking mode not enabled by default: deepseek-v3.2、deepseek-v3.2-exp、deepseek-v3.1
  • Thinking-only mode: deepseek-r1、deepseek-r1-0528、deepseek-r1 distillation models

GLM

  • Thinking-only mode: glm-5.3
  • Hybrid thinking mode, thinking mode enabled by default: glm-5.2、glm-5.2-fast-preview、glm-5.1、glm-5、glm-4.7、glm-4.6

Kimi

  • Hybrid thinking mode, thinking mode disabled by default: kimi-k2.6、kimi-k2.5
  • Thinking-only mode: kimi-k2.7-code、kimi-k2-thinking

MiniMax

Thinking-only mode: MiniMax-M2.5

Quick Start

API usage 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 at least 2.19.4 Version).

The following code uses stream Calling qwen3.8-max Enable thinking mode as an example.

OpenAI兼容

Python

Sample Code

from openai import OpenAI
import os

# 初始化OpenAI客户端
client = OpenAI(
    # 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
    # 如果没有配置环境变量,请用阿里云百炼API Key替换:api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
    base_url="https://{WorkspaceId}.ap-southeast-1.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,或者直接叫我千问。有什么我可以帮你的吗?

Node.js

Sample Code

import OpenAI from "openai";
import process from 'process';

// 初始化 openai 客户端
const openai = new OpenAI({
    apiKey: process.env.DASHSCOPE_API_KEY, // 从环境变量读取
    // 以下为新加坡地域base_url,若使用弗吉尼亚地域模型,需要将base_url换成https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/compatible-mode/v1
    // 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
    baseURL: 'https://{WorkspaceId}.ap-southeast-1.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: 'qwen-plus',
            messages,
            stream: true,
            enable_thinking: true
        });
        console.log('\n' + '='.repeat(20) + '思考过程' + '='.repeat(20) + '\n');

        for await (const chunk of stream) {
            if (!chunk.choices?.length) {
                console.log('\nUsage:');
                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;
            }

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

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

好的,用户问“你是谁”,我需要回答我的身份。首先,我应该明确说明我是千问,由阿里云开发的超大规模语言模型。接下来,可以提到我的主要功能,比如回答问题、创作文字、逻辑推理等。还要强调我的多语言支持,包括中文和英文,这样用户知道我可以处理不同语言的请求。另外,可能需要解释一下我的应用场景,比如学习、工作和生活中的帮助。不过用户的问题比较直接,可能不需要太详细的信息,保持简洁明了。同时,要确保语气友好,邀请用户进一步提问。检查有没有遗漏的重要信息,比如我的版本或最新更新,但可能用户不需要那么详细。最后,确认回答准确无误,没有错误信息。
====================完整回复====================

我是千问,是阿里巴巴集团旗下的通义实验室自主研发的超大规模语言模型。我能够回答问题、创作文字、逻辑推理、编程等多种任务,支持中英文等多种语言。如果你有任何问题或需要帮,欢迎随时告诉我!

HTTP

Sample Code

curl

# ======= 重要提示 =======
# 以下是新加坡base_url,如果使用北京地域的模型,需要将base_url替换为:https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions
# 如果使用弗吉尼亚地域的模型,需要将base_url替换为:https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions
# === 执行时请删除该注释 ===
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen3.8-max",
    "messages": [
        {
            "role": "user",
            "content": "你是谁"
        }
    ],
    "stream": true,
    "stream_options": {
        "include_usage": true
    },
    "enable_thinking": true
}'

Response

data: {"choices":[{"delta":{"content":null,"role":"assistant","reasoning_content":""},"index":0,"logprobs":null,"finish_reason":null}],"object":"chat.completion.chunk","usage":null,"created":1745485391,"system_fingerprint":null,"model":"qwen3.8-max","id":"chatcmpl-e2edaf2c-8aaf-9e54-90e2-b21dd5045503"}

.....

data: {"choices":[{"finish_reason":"stop","delta":{"content":"","reasoning_content":null},"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745485391,"system_fingerprint":null,"model":"qwen3.8-max","id":"chatcmpl-e2edaf2c-8aaf-9e54-90e2-b21dd5045503"}

data: {"choices":[],"object":"chat.completion.chunk","usage":{"prompt_tokens":10,"completion_tokens":360,"total_tokens":370},"created":1745485391,"system_fingerprint":null,"model":"qwen3.8-max","id":"chatcmpl-e2edaf2c-8aaf-9e54-90e2-b21dd5045503"}

data: [DONE]

DashScope

Qwen3.5 series DashScope API uses a multimodal interface, the following example will report an error url error , for the calling method please see Enable/Disable Deep Think mode 。

Python

Sample Code

import os
from dashscope import MultiModalConversation
import dashscope

# 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
dashscope.base_http_api_url = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1"

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

completion = MultiModalConversation.call(
    # 若没有配置环境变量,请用阿里云百炼API Key将下行替换为:api_key = "sk-xxx",
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model="qwen3.8-max",
    messages=messages,
    enable_thinking=True,
    stream=True,
    incremental_output=True,
)

# 定义完整思考过程
reasoning_content = ""
# 定义完整回复
answer_content = ""
# 判断是否结束思考过程并开始回复
is_answering = False

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

for chunk in completion:
    # 如果思考过程与回复皆为空,则忽略
    content = chunk.output.choices[0].message.content
    reasoning = chunk.output.choices[0].message.reasoning_content
    if not content and reasoning == "":
        pass
    else:
        # 如果当前为思考过程
        if reasoning != "" and not content:
            print(reasoning, end="", flush=True)
            reasoning_content += reasoning
        # 如果当前为回复
        elif content:
            if not is_answering:
                print("\n" + "=" * 20 + "完整回复" + "=" * 20)
                is_answering = True
            print(content[0]["text"], end="", flush=True)
            answer_content += content[0]["text"]

# 如果您需要打印完整思考过程与完整回复,请将以下代码解除注释后运行
# print("=" * 20 + "完整思考过程" + "=" * 20 + "\n")
# print(f"{reasoning_content}")
# print("=" * 20 + "完整回复" + "=" * 20 + "\n")
# print(f"{answer_content}")

Response

====================思考过程====================
好的,用户问:“你是谁?”我需要回答这个问题。首先,我要明确自己的身份,即千问,由阿里云开发的超大规模语言模型。接下来,要说明我的功能和用途,比如回答问题、创作文字、逻辑推理等。同时,要强调我的目标是成为用户的得力助手,提供帮助和支持。

在表达时,要保持口语化,避免使用专业术语或复杂句式。可以加入一些亲切的语气词,比如“你好呀~”,让对话更自然。另外,要确保信息准确,不遗漏关键点,比如我的开发者、主要功能和使用场景。

还要考虑用户可能的后续问题,比如具体的应用例子或技术细节,所以在回答中可以适当埋下伏笔,引导用户进一步提问。例如,提到“无论是日常生活的疑问还是专业领域的问题,我都能尽力提供帮助”,这样既全面又开放。

最后,检查回答是否流畅,有没有重复或冗余的信息,确保简洁明了。同时,保持友好和专业的平衡,让用户感受到既亲切又可靠。
====================完整回复====================
你好呀~我是千问,是阿里云开发的一款超大规模语言模型。我能够回答问题、创作文字、进行逻辑推理、编程等等,旨在为用户提供帮助和支持。无论是日常生活的疑问还是专业领域的问题,我都能尽力提供帮助。有什么我可以帮你的吗?

Java

Sample Code

// dashscope SDK的版本 >= 2.19.4
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
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.exception.UploadFileException;
import io.reactivex.Flowable;
import java.lang.System;
import com.alibaba.dashscope.utils.Constants;

public class Main {
    static {
        // 以下为新加坡地域base_url,若使用弗吉尼亚地域模型,需要将base_url换成https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1
        // 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
        Constants.baseHttpApiUrl="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }
    private static final Logger logger = LoggerFactory.getLogger(Main.class);
    private static StringBuilder reasoningContent = new StringBuilder();
    private static StringBuilder finalContent = new StringBuilder();
    private static boolean isFirstPrint = true;

    private static void handleMultiModalConversationResult(MultiModalConversationResult message) {
        String reasoning = message.getOutput().getChoices().get(0).getMessage().getReasoningContent();
        List<Map<String, Object>> contentList = (List<Map<String, Object>>) message.getOutput().getChoices().get(0).getMessage().getContent();
        String content = (contentList != null && !contentList.isEmpty()) ? (String) contentList.get(0).get("text") : "";

        if (!reasoning.isEmpty()) {
            reasoningContent.append(reasoning);
            if (isFirstPrint) {
                System.out.println("====================思考过程====================");
                isFirstPrint = false;
            }
            System.out.print(reasoning);
        }

        if (!content.isEmpty()) {
            finalContent.append(content);
            if (!isFirstPrint) {
                System.out.println("\n====================完整回复====================");
                isFirstPrint = true;
            }
            System.out.print(content);
        }
    }
    private static MultiModalConversationParam buildMultiModalConversationParam(MultiModalMessage userMsg) {
        return MultiModalConversationParam.builder()
                 // 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
                // 若没有配置环境变量,请用阿里云百炼API Key将下行替换为:.apiKey("sk-xxx")
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .model("qwen3.8-max")
                .enableThinking(true)
                .incrementalOutput(true)
                .messages(Arrays.asList(userMsg))
                .build();
    }
    public static void streamCallWithMessage(MultiModalConversation conv, MultiModalMessage userMsg)
            throws NoApiKeyException, ApiException, InputRequiredException, UploadFileException {
        MultiModalConversationParam param = buildMultiModalConversationParam(userMsg);
        Flowable<MultiModalConversationResult> result = conv.streamCall(param);
        result.blockingForEach(message -> handleMultiModalConversationResult(message));
    }

    public static void main(String[] args) {
        try {
            MultiModalConversation conv = new MultiModalConversation();
            MultiModalMessage userMsg = MultiModalMessage.builder().role(Role.USER.getValue()).content(Arrays.asList(Collections.singletonMap("text", "你是谁?"))).build();
            streamCallWithMessage(conv, userMsg);
//             打印最终结果
//            if (reasoningContent.length() > 0) {
//                System.out.println("\n====================完整回复====================");
//                System.out.println(finalContent.toString());
//            }
        } catch (ApiException | NoApiKeyException | InputRequiredException | UploadFileException e) {
            logger.error("An exception occurred: {}", e.getMessage());
        }
        System.exit(0);
    }
}

Response

====================思考过程====================
好的,用户问“你是谁?”,我需要根据之前的设定来回答。首先,我的角色是千问,阿里巴巴集团旗下的超大规模语言模型。要保持口语化,简洁易懂。

用户可能刚接触我,或者想确认我的身份。应该先直接回答我是谁,然后简要说明我的功能和用途,比如回答问题、创作文字、编程等。还要提到支持多语言,这样用户知道我可以处理不同语言的需求。

另外,根据指导方针,要保持拟人性,所以语气要友好,可能用表情符号增加亲切感。同时,可能需要引导用户进一步提问或使用我的功能,比如问他们需要什么帮助。

需要注意不要使用复杂术语,避免冗长。检查是否有遗漏的关键点,比如多语言支持和具体能力。确保回答符合所有要求,包括口语化和简洁。
====================完整回复====================
你好!我是千问,阿里巴巴集团旗下的超大规模语言模型。我能够回答问题、创作文字,比如写故事、写公文、写邮件、写剧本、逻辑推理、编程等,还能表达观点,玩游戏等。我熟练掌握多种语言,包括但不限于中文、英文、德语、法语、西班牙语等。有什么需要我帮忙的吗?

HTTP

Sample Code

curl

# ======= 重要提示 =======
# 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
# 以下为新加坡地域url,若使用北京地域的模型,需将url替换为:https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
# 若使用弗吉尼亚地域的模型,需要将base_url替换为:https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
# === 执行时请删除该注释 ===
curl -X POST "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-DashScope-SSE: enable" \
-d '{
    "model": "qwen3.8-max",
    "input":{
        "messages":[
            {
                "role": "user",
                "content": [{"text": "你是谁?"}]
            }
        ]
    },
    "parameters":{
        "enable_thinking": true,
        "incremental_output": true,
        "result_format": "message"
    }
}'

Response

id:1
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"嗯","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":14,"input_tokens":11,"output_tokens":3},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:2
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":15,"input_tokens":11,"output_tokens":4},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:3
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"用户","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":16,"input_tokens":11,"output_tokens":5},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:4
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"问","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":17,"input_tokens":11,"output_tokens":6},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:5
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"“","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":18,"input_tokens":11,"output_tokens":7},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}
......

id:358
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"帮助","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":373,"input_tokens":11,"output_tokens":362},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:359
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":",","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":374,"input_tokens":11,"output_tokens":363},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:360
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"欢迎","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":375,"input_tokens":11,"output_tokens":364},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:361
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"随时","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":376,"input_tokens":11,"output_tokens":365},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:362
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"告诉我","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":377,"input_tokens":11,"output_tokens":366},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:363
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"!","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":378,"input_tokens":11,"output_tokens":367},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:364
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"","role":"assistant"},"finish_reason":"stop"}]},"usage":{"total_tokens":378,"input_tokens":11,"output_tokens":367},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

Core Capabilities

Switch Thinking/Non-Thinking Mode

Enabling thinking mode can improve response quality, but will increase response latency and Token consumption. When using models with hybrid thinking mode, you can dynamically switch based on problem complexity without changing the model:

  • Simple tasks (daily chat, simple Q&A): Setenable_thinkingtofalseto disable thinking;
  • Complex tasks (logical reasoning, Code generation, mathematical solutions): Setenable_thinkingtotrueEnable thinking.

OpenAI兼容

Importantenable_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

Sample Code

from openai import OpenAI
import os

# 初始化OpenAI客户端
client = OpenAI(
    # 如果没有配置环境变量,请用阿里云百炼API Key替换:api_key="sk-xxx"
    # 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
    base_url="https://{WorkspaceId}.ap-southeast-1.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))

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,
    // 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
    baseURL: 'https://{WorkspaceId}.ap-southeast-1.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: 'qwen-plus',
            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);
                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

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

嗯,用户问“你是谁”,我需要先确定他们想知道什么。可能他们第一次接触我,或者想确认我的身份。我应该先介绍自己的名字和身份,比如千问,英文名Qwen。然后说明我是阿里巴巴集团旗下的通义实验室自主研发的超大规模语言模型。接下来要提到我的功能,比如回答问题、创作文字、编程、表达观点等,这样用户能了解我的用途。还要提到我支持多语言,这样国际用户会觉得有用。最后邀请他们提问,保持友好和开放的态度。注意用简洁易懂的语言,避免技术术语太多。可能用户需要帮助,或者只是好奇,所以回应要亲切,鼓励他们进一步互动。另外,可能需要考虑用户是否有更深层的需求,比如测试我的能力或者寻找特定帮助,但初次回答还是以基本信息和引导为主。保持口语化,不用复杂句子,让信息传达更有效。
====================完整回复====================

你好!我是千问,英文名Qwen,是阿里巴巴集团旗下的通义实验室自主研发的超大规模语言模型。我可以帮助你回答问题、创作文字(比如写故事、写公文、写邮件、写剧本等)、进行逻辑推理、编程,甚至表达观点和玩游戏。我支持多种语言,包括但不限于中文、英文、德语、法语、西班牙语等。

如果你有任何问题或需要帮助,随时告诉我!
====================Token 消耗====================

{
  prompt_tokens: 10,
  completion_tokens: 288,
  total_tokens: 298,
  completion_tokens_details: { reasoning_tokens: 188 },
  prompt_tokens_details: { cached_tokens: 0 }
}

HTTP

Sample Code

curl

# ======= 重要提示 =======
# 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/zh/model-studio/get-api-key
# 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
# === 执行时请删除该注释 ===
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen3.8-max",
    "messages": [
        {
            "role": "user",
            "content": "你是谁"
        }
    ],
    "stream": true,
    "stream_options": {
        "include_usage": true
    },
    "enable_thinking": true
}'

DashScope

The DashScope API of the Qwen3.5 series uses a multimodal interface. The following example will throw an error url error . For the calling method, see Enable/Disable Thinking Mode 。

Python

Sample Code

import os
from dashscope import MultiModalConversation
import dashscope

# 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
dashscope.base_http_api_url = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/"

# 初始化请求参数
messages = [{"role": "user", "content": [{"text": "你是谁?"}]}]

completion = MultiModalConversation.call(
    # 如果没有配置环境变量,请用阿里云百炼API Key替换:api_key="sk-xxx"
    # 各地域的API Key不同。获取API Key:请参考 https://www.alibabacloud.com/help/model-studio/regions
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model="qwen3.8-max",
    messages=messages,
    enable_thinking=True,     # 开启思考过程
    stream=True,              # 开启流式输出
    incremental_output=True,  # 开启增量输出
)

reasoning_content = ""  # 完整思考过程
answer_content = ""     # 完整回复
is_answering = False    # 是否进入回复阶段

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

for chunk in completion:
    message = chunk.output.choices[0].message

    # 只收集思考内容
    if message.reasoning_content:
        if not is_answering:
            print(message.reasoning_content, end="", flush=True)
        reasoning_content += message.reasoning_content

    # 收到 content,开始进行回复(content 为列表类型)
    if message.content:
        if not is_answering:
            print("\n" + "=" * 20 + "完整回复" + "=" * 20 + "\n")
            is_answering = True
        print(message.content[0]["text"], end="", flush=True)
        answer_content += message.content[0]["text"]

print("\n" + "=" * 20 + "Token 消耗" + "=" * 20 + "\n")
print(chunk.usage)
# 循环结束后,reasoning_content 和 answer_content 变量中包含了完整的内容
# 您可以在这里根据需要进行后续处理
# print(f"\n\n完整思考过程:\n{reasoning_content}")
# print(f"\n完整回复:\n{answer_content}")

Response

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

嗯,用户问“你是谁?”,我需要先确定他们想知道什么。可能他们第一次接触我,或者想确认我的身份。首先,我应该介绍自己的名字,千问,然后说明我是通义实验室研发的超大规模语言模型。接下来,可能需要解释我的功能,比如回答问题、创作文字、编程等,这样用户能了解我的用途。还要提到我支持多种语言,这样国际用户也能知道他们可以用不同语言交流。最后,保持友好,邀请他们提问,这样能促进进一步的互动。要注意用简洁易懂的语言,避免技术术语太多,让用户容易理解。可能用户有更深层的需求,比如测试我的能力,或者寻找帮助,所以提供具体的例子会更好,比如写故事、写公文、写邮件等。还要确保回答结构清晰,分点说明功能,但可能不需要用项目符号,而是自然过渡。另外,要强调我是AI助手,没有个人意识,所有回答都基于训练数据,这样避免误解。可能需要检查有没有遗漏的重要信息,比如多模态能力,或者最新的更新,但根据之前的回复,可能不需要太深入。总之,回答要全面但简洁,友好且有帮助,让用户感到被理解和支持。
====================完整回复====================

我是千问,阿里巴巴集团旗下的通义实验室自主研发的超大规模语言模型。我可以帮助你:

1. **回答问题**:无论是学术问题、常识问题还是专业领域问题,我都可以尝试为你解答。
2. **创作文字**:写故事、写公文、写邮件、写剧本等,我都可以帮你完成。
3. **逻辑推理**:我可以帮助你进行逻辑推理和解决问题。
4. **编程**:我可以理解并生成多种编程语言的代码。
5. **多语言支持**:我支持多种语言,包括但不限于中文、英文、德语、法语、西班牙语等。

如果你有任何问题或需要帮助,随时告诉我!
====================Token 消耗====================

{"input_tokens": 11, "output_tokens": 405, "total_tokens": 416, "output_tokens_details": {"reasoning_tokens": 256}, "prompt_tokens_details": {"cached_tokens": 0}}

Java

Sample Code

// dashscope SDK的版本 >= 2.19.4
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
import java.util.Collections;
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.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;
import io.reactivex.Flowable;
import java.lang.System;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {
    private static final Logger logger = LoggerFactory.getLogger(Main.class);
    private static StringBuilder reasoningContent = new StringBuilder();
    private static StringBuilder finalContent = new StringBuilder();
    private static boolean isFirstPrint = true;

    private static void handleMultiModalConversationResult(MultiModalConversationResult message) {
        String reasoning = message.getOutput().getChoices().get(0).getMessage().getReasoningContent();
        List<Map<String, Object>> contentList = (List<Map<String, Object>>) message.getOutput().getChoices().get(0).getMessage().getContent();
        String content = (contentList != null && !contentList.isEmpty()) ? (String) contentList.get(0).get("text") : "";

        if (!reasoning.isEmpty()) {
            reasoningContent.append(reasoning);
            if (isFirstPrint) {
                System.out.println("====================思考过程====================");
                isFirstPrint = false;
            }
            System.out.print(reasoning);
        }

        if (!content.isEmpty()) {
            finalContent.append(content);
            if (!isFirstPrint) {
                System.out.println("\n====================完整回复====================");
                isFirstPrint = true;
            }
            System.out.print(content);
        }
    }
    private static MultiModalConversationParam buildMultiModalConversationParam(MultiModalMessage userMsg) {
        return MultiModalConversationParam.builder()
                // 若没有配置环境变量,请用阿里云百炼API Key将下行替换为:.apiKey("sk-xxx")
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .model("qwen3.8-max")
                .enableThinking(true)
                .incrementalOutput(true)
                .messages(Arrays.asList(userMsg))
                .build();
    }
    public static void streamCallWithMessage(MultiModalConversation conv, MultiModalMessage userMsg)
            throws NoApiKeyException, ApiException, InputRequiredException, UploadFileException {
        MultiModalConversationParam param = buildMultiModalConversationParam(userMsg);
        Flowable<MultiModalConversationResult> result = conv.streamCall(param);
        result.blockingForEach(message -> handleMultiModalConversationResult(message));
    }

    public static void main(String[] args) {
        try {
            // 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
            MultiModalConversation conv = new MultiModalConversation("http", "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1");
            MultiModalMessage userMsg = MultiModalMessage.builder().role(Role.USER.getValue()).content(Arrays.asList(Collections.singletonMap("text", "你是谁?"))).build();
            streamCallWithMessage(conv, userMsg);
//             打印最终结果
//            if (reasoningContent.length() > 0) {
//                System.out.println("\n====================完整回复====================");
//                System.out.println(finalContent.toString());
//            }
        } catch (ApiException | NoApiKeyException | InputRequiredException | UploadFileException e) {
            logger.error("An exception occurred: {}", e.getMessage());
        }
        System.exit(0);
    }
}

Response

====================思考过程====================
嗯,用户问“你是谁?”,我需要先确定他们想了解什么。可能他们想知道我的身份,或者是在测试我的反应。首先,我应该明确回答我是千问,阿里巴巴集团旗下的超大规模语言模型。然后,可能需要简要介绍我的功能,比如回答问题、创作文字、编程等,这样用户能了解我的用途。还要提到我支持多种语言,这样国际用户也会知道他们可以用不同语言交流。最后,保持友好,邀请他们提问,这样他们会觉得亲切,愿意继续互动。要注意回答不要太长,但信息要全面。可能用户还有后续问题,比如我的技术细节或者使用场景,但初次回答应该简洁明了。确保没有使用专业术语,让所有用户都能理解。检查有没有遗漏的重要信息,比如多语言支持和具体功能例子。好的,这样应该能覆盖用户的需求了。
====================完整回复====================
我是千问,阿里巴巴集团旗下的超大规模语言模型。我能够回答问题、创作文字(如写故事、写公文、写邮件、写剧本等)、进行逻辑推理、编程、表达观点、玩游戏等,支持多语言交流,包括但不限于中文、英文、德语、法语、西班牙语等。如果你有任何问题或需要帮助,欢迎随时告诉我!

HTTP

Sample Code

curl

# ======= 重要提示 =======
# 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/zh/model-studio/get-api-key
# 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
# === 执行时请删除该注释 ===
curl -X POST "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-DashScope-SSE: enable" \
-d '{
    "model": "qwen3.8-max",
    "input":{
        "messages":[
            {
                "role": "user",
                "content": [{"text": "你是谁?"}]
            }
        ]
    },
    "parameters":{
        "enable_thinking": true,
        "incremental_output": true,
        "result_format": "message"
    }
}'

Response

id:1
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"嗯","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":14,"input_tokens":11,"output_tokens":3},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:2
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":15,"input_tokens":11,"output_tokens":4},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:3
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"用户","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":16,"input_tokens":11,"output_tokens":5},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:4
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"问","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":17,"input_tokens":11,"output_tokens":6},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:5
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"“","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":18,"input_tokens":11,"output_tokens":7},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}
......

id:358
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"帮助","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":373,"input_tokens":11,"output_tokens":362},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:359
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":",","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":374,"input_tokens":11,"output_tokens":363},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:360
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"欢迎","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":375,"input_tokens":11,"output_tokens":364},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:361
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"随时","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":376,"input_tokens":11,"output_tokens":365},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:362
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"告诉我","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":377,"input_tokens":11,"output_tokens":366},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:363
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"!","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":378,"input_tokens":11,"output_tokens":367},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

id:364
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"","role":"assistant"},"finish_reason":"stop"}]},"usage":{"total_tokens":378,"input_tokens":11,"output_tokens":367},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}

In addition, Qwen3 open-source hybrid thinking model and qwen-plus-2025-04-28 modelsupport dynamically controlling thinking mode through prompts.enable_thinkingWhentrue, add it to the prompt/no_thinkto disable thinking; in Multi-turn, to re-enable, add it to the latest prompt/think. The Model always follows the latest/think or /no_think instruction.

Limit Thinking Length

Deep Think Model sometimes generates verbose Thinking Process, increasing waiting time and consuming more Token. Throughthinking_budget Parameter sets the maximum Token number of Thinking Process, and after exceeding the limit, the Model immediately Output Response.

thinking_budget The Default Value is the maximum thought chain length of the Model, please see the Model card of Bailian console.

Importantthinking_budgetParameter for the maximum number of Tokens supported in the Thinking Process. Applicable to Qwen3.8, Qwen3.7, Qwen3.6, Qwen3.5, Qwen3-VL, Qwen3, GLM, and Kimi series models.

Experience Deep Think in the console

  1. Log in to the Bailian console of 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 the reasoning mode, and view the model's Thinking Process.
  5. Click the upper-right Debugging, and in the opened configuration panel, set the thinking_budgetParameter, which controls the maximum number of tokens output by the thought chain. Value range 1~32768, default value 4000. To experience more models, you can go to Bailian Model Plaza.

OpenAI兼容

Python

Sample Code

from openai import OpenAI
import os

# 初始化OpenAI客户端
client = OpenAI(
    # 如果没有配置环境变量,请用阿里云百炼API Key替换:api_key="sk-xxx"
    # 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
    base_url="https://{WorkspaceId}.ap-southeast-1.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

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

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

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

Node.js

Sample Code

import OpenAI from "openai";
import process from 'process';

// 初始化 openai 客户端
const openai = new OpenAI({
    apiKey: process.env.DASHSCOPE_API_KEY, // 从环境变量读取
    // 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
    baseURL: 'https://{WorkspaceId}.ap-southeast-1.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: 'qwen-plus',
            messages,
            stream: true,
            // enable_thinking 参数开启思考过程,thinking_budget 参数设置最大推理过程 Token 数
            enable_thinking: true,
            thinking_budget: 50
        });
        console.log('\n' + '='.repeat(20) + '思考过程' + '='.repeat(20) + '\n');

        for await (const chunk of stream) {
            if (!chunk.choices?.length) {
                console.log('\nUsage:');
                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;
            }

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

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

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

我是千问,是阿里巴巴集团旗下的通义实验室自主研发的超大规模语言模型。我能够回答问题、创作文字、逻辑推理、编程等多种任务。如果你有任何问题或需要帮助,欢迎随时告诉我!

HTTP

Sample Code

curl

# ======= 重要提示 =======
# 以下是新加坡base_url,如果使用北京地域的模型,需要将base_url替换为:https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions
# 如果使用弗吉尼亚地域的模型,需要将base_url替换为:https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions
# === 执行时请删除该注释 ===
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen3.8-max",
    "messages": [
        {
            "role": "user",
            "content": "你是谁"
        }
    ],
    "stream": true,
    "stream_options": {
        "include_usage": true
    },
    "enable_thinking": true,
    "thinking_budget": 50
}'

Response

data: {"choices":[{"delta":{"content":null,"role":"assistant","reasoning_content":""},"index":0,"logprobs":null,"finish_reason":null}],"object":"chat.completion.chunk","usage":null,"created":1745485391,"system_fingerprint":null,"model":"qwen3.8-max","id":"chatcmpl-e2edaf2c-8aaf-9e54-90e2-b21dd5045503"}

.....

data: {"choices":[{"finish_reason":"stop","delta":{"content":"","reasoning_content":null},"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745485391,"system_fingerprint":null,"model":"qwen3.8-max","id":"chatcmpl-e2edaf2c-8aaf-9e54-90e2-b21dd5045503"}

data: {"choices":[],"object":"chat.completion.chunk","usage":{"prompt_tokens":10,"completion_tokens":360,"total_tokens":370},"created":1745485391,"system_fingerprint":null,"model":"qwen3.8-max","id":"chatcmpl-e2edaf2c-8aaf-9e54-90e2-b21dd5045503"}

data: [DONE]

DashScope

Qwen3.5 series DashScope API uses a multimodal interface, and the following example will throw an error url error , for the calling method, see Enable/disable thinking mode 。

Python

Sample Code

import os
from dashscope import MultiModalConversation
import dashscope

# 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
dashscope.base_http_api_url = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/"

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

completion = MultiModalConversation.call(
    # 若没有配置环境变量,请用阿里云百炼API Key将下行替换为:api_key = "sk-xxx",
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model="qwen3.8-max",
    messages=messages,
    enable_thinking=True,
    # 设置最大推理过程 Token 数
    thinking_budget=50,
    stream=True,
    incremental_output=True,
)

# 定义完整思考过程
reasoning_content = ""
# 定义完整回复
answer_content = ""
# 判断是否结束思考过程并开始回复
is_answering = False

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

for chunk in completion:
    # 如果思考过程与回复皆为空,则忽略
    content = chunk.output.choices[0].message.content
    reasoning = chunk.output.choices[0].message.reasoning_content
    if not content and reasoning == "":
        pass
    else:
        # 如果当前为思考过程
        if reasoning != "" and not content:
            print(reasoning, end="", flush=True)
            reasoning_content += reasoning
        # 如果当前为回复
        elif content:
            if not is_answering:
                print("\n" + "=" * 20 + "完整回复" + "=" * 20)
                is_answering = True
            print(content[0]["text"], end="", flush=True)
            answer_content += content[0]["text"]

# 如果您需要打印完整思考过程与完整回复,请将以下代码解除注释后运行
# print("=" * 20 + "完整思考过程" + "=" * 20 + "\n")
# print(f"{reasoning_content}")
# print("=" * 20 + "完整回复" + "=" * 20 + "\n")
# print(f"{answer_content}")

Response

====================思考过程====================
好的,用户问“你是谁?”,我需要给出一个清晰且友好的回答。首先,我要介绍自己的身份,也就是千问,由阿里巴巴集团旗下的通义实验室研发。接下来,应该说明我的主要功能,比如
====================完整回复====================
我是千问,是阿里巴巴集团旗下的通义实验室自主研发的超大规模语言模型。我能够回答问题、创作文字、逻辑推理、编程等,旨在为用户提供全面、准确和有用的信息与帮助。有什么我可以帮您的吗?

Java

Sample Code

// dashscope SDK的版本 >= 2.19.4
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
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.exception.UploadFileException;
import io.reactivex.Flowable;
import java.lang.System;
import com.alibaba.dashscope.utils.Constants;

public class Main {
    static {
        // 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
        Constants.baseHttpApiUrl="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }
    private static final Logger logger = LoggerFactory.getLogger(Main.class);
    private static StringBuilder reasoningContent = new StringBuilder();
    private static StringBuilder finalContent = new StringBuilder();
    private static boolean isFirstPrint = true;

    private static void handleMultiModalConversationResult(MultiModalConversationResult message) {
        String reasoning = message.getOutput().getChoices().get(0).getMessage().getReasoningContent();
        List<Map<String, Object>> contentList = (List<Map<String, Object>>) message.getOutput().getChoices().get(0).getMessage().getContent();
        String content = (contentList != null && !contentList.isEmpty()) ? (String) contentList.get(0).get("text") : "";

        if (!reasoning.isEmpty()) {
            reasoningContent.append(reasoning);
            if (isFirstPrint) {
                System.out.println("====================思考过程====================");
                isFirstPrint = false;
            }
            System.out.print(reasoning);
        }

        if (!content.isEmpty()) {
            finalContent.append(content);
            if (!isFirstPrint) {
                System.out.println("\n====================完整回复====================");
                isFirstPrint = true;
            }
            System.out.print(content);
        }
    }
    private static MultiModalConversationParam buildMultiModalConversationParam(MultiModalMessage userMsg) {
        return MultiModalConversationParam.builder()
                // 若没有配置环境变量,请用阿里云百炼API Key将下行替换为:.apiKey("sk-xxx")
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .model("qwen3.8-max")
                .enableThinking(true)
                .thinkingBudget(50)
                .incrementalOutput(true)
                .messages(Arrays.asList(userMsg))
                .build();
    }
    public static void streamCallWithMessage(MultiModalConversation conv, MultiModalMessage userMsg)
            throws NoApiKeyException, ApiException, InputRequiredException, UploadFileException {
        MultiModalConversationParam param = buildMultiModalConversationParam(userMsg);
        Flowable<MultiModalConversationResult> result = conv.streamCall(param);
        result.blockingForEach(message -> handleMultiModalConversationResult(message));
    }

    public static void main(String[] args) {
        try {
            MultiModalConversation conv = new MultiModalConversation();
            MultiModalMessage userMsg = MultiModalMessage.builder().role(Role.USER.getValue()).content(Arrays.asList(Collections.singletonMap("text", "你是谁?"))).build();
            streamCallWithMessage(conv, userMsg);
//             打印最终结果
//            if (reasoningContent.length() > 0) {
//                System.out.println("\n====================完整回复====================");
//                System.out.println(finalContent.toString());
//            }
        } catch (ApiException | NoApiKeyException | InputRequiredException | UploadFileException e) {
            logger.error("An exception occurred: {}", e.getMessage());
        }
        System.exit(0);
    }
}

Response

====================思考过程====================
好的,用户问“你是谁?”,我需要给出一个清晰且友好的回答。首先,我要介绍自己的身份,也就是千问,由阿里巴巴集团旗下的通义实验室研发。接下来,应该说明我的主要功能,比如
====================完整回复====================
我是千问,是阿里巴巴集团旗下的通义实验室自主研发的超大规模语言模型。我能够回答问题、创作文字、逻辑推理、编程等,旨在为用户提供全面、准确和有用的信息与帮助。有什么我可以帮您的吗?

HTTP

Sample Code

curl

# ======= 重要提示 =======
# 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
# 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
# === 执行时请删除该注释 ===
curl -X POST "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-DashScope-SSE: enable" \
-d '{
    "model": "qwen3.8-max",
    "input":{
        "messages":[
            {
                "role": "user",
                "content": [{"text": "你是谁?"}]
            }
        ]
    },
    "parameters":{
        "enable_thinking": true,
        "thinking_budget": 50,
        "incremental_output": true,
        "result_format": "message"
    }
}'

Response

id:1
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"好的","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":14,"output_tokens":3,"input_tokens":11,"output_tokens_details":{"reasoning_tokens":1}},"request_id":"2ce91085-3602-9c32-9c8b-fe3d583a2c38"}

id:2
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":15,"output_tokens":4,"input_tokens":11,"output_tokens_details":{"reasoning_tokens":2}},"request_id":"2ce91085-3602-9c32-9c8b-fe3d583a2c38"}

......

id:133
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"!","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":149,"output_tokens":138,"input_tokens":11,"output_tokens_details":{"reasoning_tokens":50}},"request_id":"2ce91085-3602-9c32-9c8b-fe3d583a2c38"}

id:134
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"","role":"assistant"},"finish_reason":"stop"}]},"usage":{"total_tokens":149,"output_tokens":138,"input_tokens":11,"output_tokens_details":{"reasoning_tokens":50}},"request_id":"2ce91085-3602-9c32-9c8b-fe3d583a2c38"}

Pass Thinking Process

In Multi-turn, preserve_thinking controls whether the Model reads historical assistant message reasoning_content. When set to true, these thinking contents will be appended to the next-round input. The client needs to provide historical assistant messages and their messages in the request's reasoning_content. The Default Value of each model is based on Chat Completions Parameter Description.

Importantpreserve_thinkingThis Parameter only supports qwen3.8-max series, qwen3.8-flash, qwen3.8-omni-flash (enabled 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-max-preview, qwen3.6-plus, qwen3.6-plus-2026-04-02, qwen3.7-flash, qwen3.7-flash-2026-07-15, kimi-k2.7-code (Alibaba Cloud Bailian deployment), kimi-k2.6 (Alibaba Cloud Bailian deployment), kimi/kimi-k3 (Moonshot deployment), kimi/kimi-k2.7-code-highspeed (Moonshot deployment), kimi/kimi-k2.7-code (Moonshot deployment), kimi/kimi-k2.6 (Moonshot deployment).

For the above Qwen3.8 Max, Qwen3.7, Qwen3.6 and Kimi models that support this Parameter, if the historical messages do not contain reasoning_content,Enable this Parameter will not cause an error.

After Enable, in the historical conversation reasoning_content will be counted toward input Token count and billing.

OpenAI兼容

Notepreserve_thinkingNon OpenAI standard Parameter, Use Python SDK needs to Pass extra_bodyin.

Python

Sample Code

from openai import OpenAI
import os

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
    base_url="https://{WorkspaceId}.ap-southeast-1.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生态,它完全能胜任千万级消息场景。

Node.js

Sample Code

import OpenAI from "openai";
import process from 'process';

const openai = new OpenAI({
    apiKey: process.env.DASHSCOPE_API_KEY,
    // 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
    baseURL: 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1'
});

async function main() {
    // 第一轮对话
    let firstReasoning = '';
    let firstContent = '';
    let isAnswering = false;

    const stream1 = await openai.chat.completions.create({
        model: 'qwen3.7-plus',
        messages: [{ role: 'user', content: '我需要为一个日均千万消息的电商系统选择消息队列,请推荐' }],
        stream: true,
        enable_thinking: true
    });

    console.log('='.repeat(20) + '第一轮思考过程' + '='.repeat(20));

    for await (const chunk of stream1) {
        if (!chunk.choices?.length) continue;
        const delta = chunk.choices[0].delta;
        if (delta.reasoning_content !== undefined && delta.reasoning_content !== null) {
            firstReasoning += delta.reasoning_content;
            if (!isAnswering) process.stdout.write(delta.reasoning_content);
        }
        if (delta.content !== undefined && delta.content) {
            if (!isAnswering) {
                console.log('\n' + '='.repeat(20) + '第一轮回复' + '='.repeat(20));
                isAnswering = true;
            }
            process.stdout.write(delta.content);
            firstContent += delta.content;
        }
    }

    // 第二轮对话:传递思考过程
    let reasoningContent = '';
    let answerContent = '';
    isAnswering = false;

    const stream2 = await openai.chat.completions.create({
        model: 'qwen3.7-plus',
        messages: [
            { role: 'user', content: '我需要为一个日均千万消息的电商系统选择消息队列,请推荐' },
            {
                role: 'assistant',
                content: firstContent,
                reasoning_content: firstReasoning
            },
            { role: 'user', content: '你在对比时为什么排除了Kafka?' }
        ],
        stream: true,
        enable_thinking: true,
        // preserve_thinking 作为顶层参数传入
        preserve_thinking: true
    });

    console.log('\n' + '='.repeat(20) + '第二轮思考过程' + '='.repeat(20));

    for await (const chunk of stream2) {
        if (!chunk.choices?.length) 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) + '第二轮回复' + '='.repeat(20));
                isAnswering = true;
            }
            process.stdout.write(delta.content);
            answerContent += delta.content;
        }
    }
}

main();

Response

====================第一轮思考过程====================
用户需要为日均千万消息的电商系统选择消息队列。让我从吞吐量、可靠性、延迟消息、事务支持等维度对比主流方案...
====================第一轮回复====================
综合电商场景的核心需求,推荐 Apache RocketMQ。如果团队已有 Kafka 生态,Kafka 也是可行方案。
====================第二轮思考过程====================
用户追问为什么排除了Kafka。参考我之前的思考过程,我并没有排除Kafka...
====================第二轮回复====================
我并没有排除Kafka。Kafka在吞吐量和生态方面表现优秀,之所以RocketMQ评分略高,是因为电商核心链路的"开箱即用"特性匹配度。

HTTP

Sample Code

curl

# 各地域base_url不同,请根据实际地域修改
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen3.8-max",
    "messages": [
        {
            "role": "user",
            "content": "我需要为一个日均千万消息的电商系统选择消息队列,请推荐"
        },
        {
            "role": "assistant",
            "content": "综合电商场景的核心需求,推荐 Apache RocketMQ。",
            "reasoning_content": "用户需要为日均千万消息的电商系统选择消息队列。RocketMQ原生支持事务消息和延迟消息,更适合电商场景。Kafka吞吐量极高但需自研补偿机制。"
        },
        {
            "role": "user",
            "content": "你在对比时为什么排除了Kafka?"
        }
    ],
    "stream": true,
    "stream_options": {
        "include_usage": true
    },
    "enable_thinking": true,
    "preserve_thinking": true
}'

Response

data: {"choices":[{"delta":{"content":null,"role":"assistant","reasoning_content":""},"index":0,"logprobs":null,"finish_reason":null}],"object":"chat.completion.chunk","usage":null,"created":1743523200,"system_fingerprint":null,"model":"qwen3.8-max","id":"chatcmpl-example-001"}

.....

data: {"choices":[{"finish_reason":"stop","delta":{"content":"","reasoning_content":null},"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1743523200,"system_fingerprint":null,"model":"qwen3.8-max","id":"chatcmpl-example-001"}

data: {"choices":[],"object":"chat.completion.chunk","usage":{"prompt_tokens":3463,"completion_tokens":2387,"total_tokens":5850},"created":1743523200,"system_fingerprint":null,"model":"qwen3.8-max","id":"chatcmpl-example-001"}

data: [DONE]

DashScope

NoteJava SDK does not currently support preserve_thinking parameter. When Calling via HTTP, please put preserve_thinkinginto parameters object.

Python

Sample Code

import os
from dashscope import MultiModalConversation
import dashscope

# 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
dashscope.base_http_api_url = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/"

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

first_reasoning = ""
first_content = ""
is_answering = False

completion = MultiModalConversation.call(
    # 若没有配置环境变量,请用阿里云百炼API Key将下行替换为:api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model="qwen3.8-max",
    messages=messages,
    enable_thinking=True,
    stream=True,
    incremental_output=True,
)

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

for chunk in completion:
    content = chunk.output.choices[0].message.content
    reasoning = chunk.output.choices[0].message.reasoning_content
    if not content and reasoning == "":
        pass
    else:
        if reasoning != "" and not content:
            print(reasoning, end="", flush=True)
            first_reasoning += reasoning
        elif content:
            if not is_answering:
                print("\n" + "=" * 20 + "第一轮回复" + "=" * 20)
                is_answering = True
            print(content[0]["text"], end="", flush=True)
            first_content += content[0]["text"]

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

reasoning_content = ""
answer_content = ""
is_answering = False

completion = MultiModalConversation.call(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model="qwen3.8-max",
    messages=messages,
    enable_thinking=True,
    # 传递思考过程
    preserve_thinking=True,
    stream=True,
    incremental_output=True,
)

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

for chunk in completion:
    content = chunk.output.choices[0].message.content
    reasoning = chunk.output.choices[0].message.reasoning_content
    if not content and reasoning == "":
        pass
    else:
        if reasoning != "" and not content:
            print(reasoning, end="", flush=True)
            reasoning_content += reasoning
        elif content:
            if not is_answering:
                print("\n" + "=" * 20 + "第二轮回复" + "=" * 20)
                is_answering = True
            print(content[0]["text"], end="", flush=True)
            answer_content += content[0]["text"]

Response

====================第一轮思考过程====================
用户需要为日均千万消息的电商系统选择消息队列。让我从吞吐量、可靠性、延迟消息、事务支持等维度对比主流方案...
====================第一轮回复====================
综合电商场景的核心需求,推荐 Apache RocketMQ。如果团队已有 Kafka 生态,Kafka 也是可行方案。
====================第二轮思考过程====================
用户追问为什么排除了Kafka。参考我之前的思考过程,我并没有排除Kafka...
====================第二轮回复====================
我并没有排除Kafka。Kafka在吞吐量和生态方面表现优秀,之所以RocketMQ评分略高,是因为电商核心链路的"开箱即用"特性匹配度。

HTTP

Sample Code

curl

# 各地域base_url不同,请根据实际地域修改
curl -X POST "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-DashScope-SSE: enable" \
-d '{
    "model": "qwen3.8-max",
    "input":{
        "messages":[
            {
                "role": "user",
                "content": [{"text": "我需要为一个日均千万消息的电商系统选择消息队列,请推荐"}]
            },
            {
                "role": "assistant",
                "content": [{"text": "综合电商场景的核心需求,推荐 Apache RocketMQ。"}],
                "reasoning_content": "用户需要为日均千万消息的电商系统选择消息队列。RocketMQ原生支持事务消息和延迟消息,更适合电商场景。Kafka吞吐量极高但需自研补偿机制。"
            },
            {
                "role": "user",
                "content": [{"text": "你在对比时为什么排除了Kafka?"}]
            }
        ]
    },
    "parameters":{
        "enable_thinking": true,
        "preserve_thinking": true,
        "incremental_output": true,
        "result_format": "message"
    }
}'

Response

id:1
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"用户","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":3466,"output_tokens":3,"input_tokens":3463,"output_tokens_details":{"reasoning_tokens":1}},"request_id":"example-request-001"}

id:2
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"追问","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":3467,"output_tokens":4,"input_tokens":3463,"output_tokens_details":{"reasoning_tokens":2}},"request_id":"example-request-001"}

......

id:200
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"","role":"assistant"},"finish_reason":"stop"}]},"usage":{"total_tokens":5850,"output_tokens":2387,"input_tokens":3463,"output_tokens_details":{"reasoning_tokens":1347}},"request_id":"example-request-001"}

Other Features

Billing Details

  • Thinking content is billed by Output Token.

  • Some hybrid thinking models have different prices in thinking and non-thinking modes.

    If the model does not Output Thinking Process in thinking mode, it is billed at the non-thinking mode price.

FAQ

Q:怎么关闭思考模式?

Whether the thinking mode can be disabled depends on the model used:

  • Hybrid thinking mode models (such as qwen3.6-plus, deepseek-v4-pro): enable_thinking set to false to disable;
  • Thinking-only mode models (such as qwen3-235b-a22b-thinking-2507, deepseek-r1): cannot be disabled.

Q:qwen3.7-plus 调用响应慢如何排查?

qwen3.7-plus is a hybrid thinking mode model and enables thinking mode by default. The Thinking Process generates a large number of reasoning Tokens (measured to account for 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. The Token generation speed itself is not abnormal (measured at approximately 52~54 Tokens/s), and the difference in total time 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 Enable. qwen3.7-plus is Enable by default, which can be determined by whether the reasoning_content Field is returned in the response.
  2. Check the completion_tokens and reasoning_tokens in the response usage. If reasoning_tokens is relatively high, the total time consumption is an expected behavior of the Thinking mode.
  3. If no Thinking Process is needed, set enable_thinking to false to disable the Thinking mode. Once disabled, the Output Token is significantly reduced, and the actual 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 more quickly and view the Thinking Process in real time, avoiding long waits for the complete response.

The usage statistics display the overall time consumption of a single Calling (including the generation time of the Thinking Token), rather than the generation latency of a single Token.

Q:如何以非流式(同步)方式调用深度思考模型?

The examples in this article use Stream by default (Recommend, you can view the Thinking Process in real time and avoid long waits). The commercial version Deep Think Model (such as qwen-plus, qwen3-max, qwen-flash, etc.) also supports non-stream (synchronous) Output, returning the complete Thinking Process and response at once.

When changing the streaming example to non-streaming, please modifyResult parsing code: non-streaming Calling returns a complete Response object (completion),cannot iterate through for chunk in completion as in the streaming Sample Code (otherwise an error 'tuple' object has no attribute 'choices' will be raised), and 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 with non-streaming Calling of qwen3.8-max with thinking mode enabled as an example:

from openai import OpenAI
import os

client = OpenAI(
    # 各地域的API Key不同。获取API Key:https://www.alibabacloud.com/help/model-studio/get-api-key
    # 如果没有配置环境变量,请用阿里云百炼API Key替换:api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 以下为新加坡地域配置,调用时请将{WorkspaceId}替换为真实的业务空间ID,各地域的配置不同。
    base_url="https://{WorkspaceId}.ap-southeast-1.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-235b-a22b, qwen3-32b and other open-source versions) only support Stream output, and non-streaming Calling will result in an error parameter.enable_thinking only support stream call. For such models, please Use streaming Calling.

Q: 免费额度 用完后如何购买 Token?

Go to Fees and Costscenter to top up, keeping your account balance sufficient to call models normally.

After exceeding the Free Quota, billing is automatic at minute-level intervals. For consumption details, please go to ;Bill Details to view.

Q: 可以上传图片或文档进行提问吗 ?

The models involved in this article only support text input. Qwen3-VL and QVQ models support image Deep Think.

Q:如何查看Token 消耗 量 及 调用次数?

After Model Calling occursminute-levelcan be viewed in the monitoring chart. Log in to the Monitoring page (SingaporeorBeijing), select from the left navigation barOperations Management > Monitoringenter the monitoring overview page, set query conditions (for example, select time range, business space, etc.), then inModelsregion, find the target model and clickView Details, you can view the Calling statistics result of the model. For more information, see Monitoring Docs.

Monitoring data is updated at minute level, for reference only, not as billing basis.

Q:长提示词生成失败或超时怎么办?

When Calling the model with long prompts, generation failure or response timeout usually occurs because the thinking mode is enabled (enable_thinking is true). The thinking mode will increase processing time, and in long prompt scenarios may cause response truncation or request timeout.

Solution:

  • Disable thinking mode: Set enable_thinking to false, reducing processing time from about 50 s to about 30 s.
  • Enable Stream: Set stream set 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 seconds or above.

Q:使用第三方客户端调用深度思考模型时,输出思考标签后客户端断连怎么办?

This is a client-side issue, not the model limiting the Thinking Process output. The Bailian platform uses enable_thinking parameter to control the thinking mode toggle, and the model returns reasoning_content Field contains the complete Thinking Process content, and the model will normally return the thinking content. Disconnections are usually 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.
  • View the client logs to confirm the association between the disconnection time point and the thinking tag Output.

You can also Calling the model directly via the DashScope API to verify whether the thinking function is working properly.

API Reference

For the input and Output parameters of the Deep Think model, please seeText Generation。

Error Code

If an execution error occurs, see Error Code to troubleshoot and resolve.