全部产品
Search
文档中心

大模型服务平台百炼:联网搜索

更新时间:Sep 10, 2026

大模型的训练数据存在知识截止日期,无法回答实时问题。启用联网搜索后,模型可从网络获取实时数据,准确回答股票价格、天气预报、最新新闻等时效性问题。

使用方式

联网搜索支持以下四种API调用方式,启用参数各有不同:

OpenAI 兼容-Responses API

通过 tools 参数添加 web_search 工具即可启用联网搜索。

Responses API 仅支持部分模型,支持的模型请参见Responses API的联网搜索

# 导入依赖与创建客户端...
response = client.responses.create(
    model="qwen3.8-max",
    input="杭州天气",
    tools=[
        {"type": "web_search"},
        {"type": "web_extractor"},
        {"type": "code_interpreter"}
    ],
    extra_body={"enable_thinking": True}
)

OpenAI 兼容-Chat Completions API

设置 enable_search: true 即可启用联网搜索。

# 导入依赖与创建客户端...
completion = client.chat.completions.create(
    # 需使用支持联网搜索的模型
    model="qwen-plus",
    messages=[{"role": "user", "content": "杭州明天天气如何"}],
    # 由于 enable_search 非 OpenAI 标准参数,使用 Python SDK 需要通过 extra_body 传入(使用Node.js SDK 需作为顶层参数传入)
    extra_body={"enable_search": True}
)

DashScope

设置 enable_search: true 即可启用联网搜索。

# 导入依赖...
response = dashscope.Generation.call(
    # 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx",
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 需使用支持联网搜索的模型
    model="qwen-plus",
    messages=[{"role": "user", "content": "杭州明天天气如何"}],
    # 通过 enable_search 参数开启联网搜索
    enable_search=True,
    result_format="message"
)

Anthropic 兼容

tools 参数中添加 Anthropic 服务端的联网搜索工具(nameweb_search)即可启用联网搜索。请求地址为 https://{WorkspaceId}.{region}.maas.aliyuncs.com/apps/anthropic

该方式面向 Claude Code 等 Anthropic 官方客户端。在客户端中直接用自然语言提问即可触发联网搜索,无需额外配置。

使用 Anthropic SDK 或 HTTP 直接调用时,需在 system 中传入客户端标识 x-anthropic-billing-header: cc_entrypoint=cli;,否则联网搜索不生效。

关于工具版本号type 中的日期后缀(例如 web_search_20250305)由 Anthropic 官方客户端的版本决定,客户端升级后可能改用其他日期的版本号。百炼按工具类别识别该工具,不校验具体的日期后缀,因此无需将 type 固定为某一版本,与客户端实际发送的值保持一致即可。

# 导入依赖与创建客户端...
message = client.messages.create(
    model="qwen3.8-max",
    max_tokens=2048,
    # 传入客户端标识
    system=[{"type": "text", "text": "x-anthropic-billing-header: cc_entrypoint=cli;"}],
    messages=[{"role": "user", "content": "杭州明天天气如何"}],
    tools=[
        {
            # 日期后缀由客户端版本决定,此处以 Claude Code 当前使用的版本为例
            "type": "web_search_20250305",
            "name": "web_search",
            # 可选,单次请求最多检索次数
            "max_uses": 8
        }
    ]
)

模型的检索过程通过 server_tool_use(检索请求)和 web_search_tool_result(检索结果)内容块返回,检索次数记录在 usage.server_tool_use.web_search_requests 中。

多模态模型的联网搜索

Qwen3.8 系列、Qwen3.7-Flash、Qwen3.7-Plus、Qwen3.6 系列、Qwen3.5 系列(含 qwen3.5-plus、qwen3.5-flash、qwen3.5-omni 系列与千问开源模型)等模型支持图片、视频等多模态输入,属于多模态模型。

搜索策略因系列而异:qwen3.5-omni 系列仅支持 agent 策略;Qwen3.8 系列不支持 agent 策略(使用默认的 turbomax);其余模型支持 turbomaxagent 策略。这类模型需通过多模态接口multimodal-generation 端点)调用:Python 与 Java 使用 MultiModalConversation,而不能使用面向纯文本模型的 Generationtext-generation 端点)。多模态模型的基础调用方式可参见《视觉推理》《图像与视频理解》文档。

若使用 Generationtext-generation 端点)调用上述多模态模型,会返回 400 url error, please check url,请改用 MultiModalConversationmultimodal-generation 端点)。Java SDK 的 MultiModalConversationParam 提供 enableSearch(true) 用于开启联网搜索,但未提供 searchOptions() 方法,需通过通用参数 parameter("search_options", ...) 注入搜索策略等配置;Python 的 MultiModalConversation.call 可直接传入 search_options。多模态模型开启联网搜索时需使用流式调用(Java 使用 streamCall,Python 设置 stream=True),否则会返回 Non-streaming mode does not support Web Search 报错。

import os
import dashscope
from dashscope import MultiModalConversation
# 以下为新加坡地域配置,调用时请将 {WorkspaceId} 替换为真实的业务空间ID,各地域的配置不同。
dashscope.base_http_api_url = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1"
responses = MultiModalConversation.call(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 需使用支持联网搜索的多模态模型
    model="qwen3.5-plus",
    messages=[{"role": "user", "content": [{"text": "杭州今天天气如何"}]}],
    # 多模态接口可直接传入 enable_search 与 search_options
    enable_search=True,
    search_options={
        # qwen3.5-omni 系列需设为 agent;Qwen3.8 系列不支持 agent,保持默认即可
        "search_strategy": "agent",
        "enable_source": True,
    },
    # 多模态模型开启联网搜索时需使用流式调用
    stream=True,
    incremental_output=True,
)
for response in responses:
    print(response.output.choices[0].message.content)
// dashscope SDK 版本 >= 2.19.0
import java.util.Arrays;
import java.util.Collections;
import io.reactivex.Flowable;
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.aigc.generation.SearchOptions;
import com.alibaba.dashscope.common.MultiModalMessage;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.utils.Constants;

public class Main {
    // 以下为新加坡地域配置,调用时请将 {WorkspaceId} 替换为真实的业务空间ID,各地域的配置不同。
    static { Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1"; }
    public static void main(String[] args) throws Exception {
        MultiModalConversation conv = new MultiModalConversation();
        MultiModalMessage userMsg = MultiModalMessage.builder()
                .role(Role.USER.getValue())
                .content(Arrays.asList(Collections.singletonMap("text", "杭州今天天气如何")))
                .build();
        SearchOptions searchOptions = SearchOptions.builder()
                // 多模态模型的联网搜索策略需设为 agent
                .searchStrategy("agent")
                .enableSource(true)
                .build();
        MultiModalConversationParam param = MultiModalConversationParam.builder()
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                // 需使用支持联网搜索的多模态模型
                .model("qwen3.5-plus")
                .messages(Arrays.asList(userMsg))
                // 原生方法:开启联网搜索
                .enableSearch(true)
                // MultiModalConversationParam 未提供 searchOptions() 方法,需通过通用 parameter() 注入 search_options
                .parameter("search_options", searchOptions)
                .incrementalOutput(true)
                .build();
        // 多模态模型开启联网搜索时需使用流式调用
        Flowable<MultiModalConversationResult> result = conv.streamCall(param);
        result.blockingForEach(message ->
                System.out.print(message.getOutput().getChoices().get(0).getMessage().getContent()));
    }
}

支持的模型

支持联网搜索的模型如下。支持多模态输入的模型(Qwen3.8 系列、Qwen3.7-Flash/Plus、Qwen3.6 系列、Qwen3.5 系列及千问开源模型等)需通过多模态接口调用,参见多模态模型的联网搜索

新加坡

  • 千问
    • Qwen3.8 系列:qwen3.8-max、qwen3.8-max-0902、qwen3.8-flash、qwen3.8-2.4t-a95b、qwen3.8-27b(不支持 agent 策略)
    • Qwen3.7 系列:qwen3.7-max、qwen3.7-max-preview、qwen3.7-max-2026-05-17及之后的快照版本、qwen3.7-plus、qwen3.7-plus-2026-05-26及之后的快照版本、qwen3.7-flash、qwen3.7-flash-2026-07-15及之后的快照版本
    • Qwen3.6 系列:qwen3.6-max-preview、qwen3.6-plus、qwen3.6-plus-2026-04-02及之后的快照版本、qwen3.6-flash、qwen3.6-flash-2026-04-16及之后的快照版本、qwen3.6-27b、qwen3.6-35b-a3b
    • Qwen3.5 系列:qwen3.5-plus、qwen3.5-plus-2026-02-15及之后的快照版本、qwen3.5-flash、qwen3.5-flash-2026-02-23及之后的快照版本、qwen3.5-27b、qwen3.5-35b-a3b、qwen3.5-122b-a10b、qwen3.5-397b-a17b
    • Qwen3-Max:qwen3-max、qwen3-max-2025-09-23及之后的快照版本
    • 千问Omni:qwen3.5-omni-plus、qwen3.5-omni-plus-2026-03-15、qwen3.5-omni-flash、qwen3.5-omni-flash-2026-03-15(搜索策略需设为 agent
    • 千问Omni-Realtime:qwen3.5-omni-plus-realtime、qwen3.5-omni-plus-realtime-2026-03-15、qwen3.5-omni-flash-realtime、qwen3.5-omni-flash-realtime-2026-03-15(搜索策略需设为 agent
  • 第三方模型
    • DeepSeek:deepseek-v4-pro、deepseek-v4-pro-0813、deepseek-v4-flash、deepseek-v4-flash-0731、deepseek-v3.2(其中 deepseek-v4 系列同时支持Responses API
    • GLM:glm-5.2(仅支持通过Responses API联网搜索)
    • Kimi:kimi-k3(仅支持通过Responses API联网搜索)

华北2(北京)

  • 千问
    • Qwen3.8 系列:qwen3.8-max、qwen3.8-max-0902、qwen3.8-flash、qwen3.8-2.4t-a95b、qwen3.8-27b(不支持 agent 策略)
    • Qwen3.7 系列:qwen3.7-max、qwen3.7-max-2026-05-20及之后的快照版本、qwen3.7-plus、qwen3.7-plus-2026-05-26及之后的快照版本、qwen3.7-flash、qwen3.7-flash-2026-07-15及之后的快照版本
    • Qwen3.6 系列:qwen3.6-max-preview、qwen3.6-plus、qwen3.6-plus-2026-04-02及之后的快照版本、qwen3.6-flash、qwen3.6-flash-2026-04-16及之后的快照版本、qwen3.6-27b、qwen3.6-35b-a3b
    • Qwen3.5 系列:qwen3.5-plus、qwen3.5-plus-2026-02-15及之后的快照版本、qwen3.5-flash、qwen3.5-flash-2026-02-23及之后的快照版本、qwen3.5-27b、qwen3.5-35b-a3b、qwen3.5-122b-a10b、qwen3.5-397b-a17b
    • Qwen3-Max:qwen3-max、qwen3-max-2025-09-23及之后的快照版本
    • Qwen-Max:qwen-max及之后的快照版本
    • Qwen-Plus:qwen-plus、qwen-plus-latest、qwen-plus-2025-07-14及之后的快照版本
    • Qwen-Flash:qwen-flash、qwen-flash-2025-07-28及之后的快照版本
    • Qwen-Turbo:qwen-turbo
    • QwQ:qwq-plus(仅支持默认搜索策略,不能设置 search_strategy
    • 千问Omni:qwen3.5-omni-plus、qwen3.5-omni-plus-2026-03-15、qwen3.5-omni-flash、qwen3.5-omni-flash-2026-03-15(搜索策略需设为 agent
    • 千问Omni-Realtime:qwen3.5-omni-plus-realtime、qwen3.5-omni-plus-realtime-2026-03-15、qwen3.5-omni-flash-realtime、qwen3.5-omni-flash-realtime-2026-03-15(搜索策略需设为 agent
    • 角色扮演:qwen-plus-character、qwen-flash-character(不支持 agent 策略)

    2025 年 7 月后发布的千问Max、千问Plus、千问Flash 模型都自动支持联网搜索。

  • 第三方模型
    • DeepSeek:deepseek-v4-pro、deepseek-v4-pro-0813、deepseek-v4-flash、deepseek-v4-flash-0731、deepseek-v3.2、deepseek-v3.2-exp、deepseek-v3.1、deepseek-r1-0528、deepseek-r1、deepseek-v3(其中 deepseek-v4 系列同时支持Responses API
    • GLM:glm-5.2(仅支持通过Responses API联网搜索)
    • Kimi:Moonshot-Kimi-K2-Instruct、kimi-k3(kimi-k3 仅支持通过Responses API联网搜索)

全球

美国(弗吉尼亚)、中国香港、日本(东京)、德国(法兰克福)地域支持以下模型。其中中国香港、日本(东京)、德国(法兰克福)需使用服务部署范围为全球的业务空间调用,参见选择地域、服务部署范围和接入域名

  • 千问
    • Qwen3.8 系列:qwen3.8-max、qwen3.8-max-0902、qwen3.8-flash

快速开始

以下示例通过联网搜索查询股票信息。

OpenAI 兼容

OpenAI 兼容协议不支持在响应中返回搜索来源。

Python

import os
from openai import OpenAI

client = OpenAI(
    # 若没有配置环境变量,请用百炼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="qwen-plus",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "阿里巴巴股价如何"},
    ],
    extra_body={
        "enable_search": True,
        "search_options": {
            # 联网搜索策略,仅支持配置为 agent
            "search_strategy": "agent"
        }
    }
)
print(completion.choices[0].message.content)
响应示例
根据最新的市场数据,阿里巴巴的股价在不同市场表现如下:

*   **美股 (BABA)**:最新股价约为 **159.84 美元**。
*   **港股 (09988.HK)**:最新股价约为 **158.00 港元**。

请注意,股价会实时波动,以上信息仅供参考。根据最新的市场数据,阿里巴巴的股价在不同市场表现如下:

*   **美股 (BABA)**:最新股价约为 **159.84 美元**。
*   **港股 (09988.HK)**:最新股价约为 **158.00 港元**。

请注意,股价会实时波动,以上信息仅供参考。

Node.js

import OpenAI from "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"
});

async function main() {
    const completion = await openai.chat.completions.create({
        model: "qwen-plus",
        messages: [
            { role: "user", content: "阿里巴巴股价如何" }
        ],
        enable_search: true,
        search_options: {
            // 联网搜索策略,仅支持配置为 agent
            search_strategy: "agent"
        }
    });
    console.log(completion.choices[0].message.content);
}

main();
响应示例
根据最新的市场数据,阿里巴巴的股价在不同市场表现如下:

*   **美股 (BABA)**:最新股价约为 **159.84 美元**。
*   **港股 (09988.HK)**:最新股价约为 **158.00 港元**。

请注意,股价会实时波动,以上信息仅供参考。根据最新的市场数据,阿里巴巴的股价在不同市场表现如下:

*   **美股 (BABA)**:最新股价约为 **159.84 美元**。
*   **港股 (09988.HK)**:最新股价约为 **158.00 港元**。

请注意,股价会实时波动,以上信息仅供参考。

curl

# 以下为新加坡地域配置,调用时请将 {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": "qwen-plus",
    "messages": [
        {
            "role": "user",
            "content": "阿里巴巴股价如何"
        }
    ],
    "enable_search": true,
    "search_options": {
        "search_strategy": "agent"
    }
}'

DashScope

DashScope 协议支持设置 enable_sourcetrue ,使返回数据中包含搜索来源。

Python

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

response = dashscope.Generation.call(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model="qwen-plus",
    messages=[{"role": "user", "content": "阿里巴巴股价"}],
    enable_search=True,
    search_options={
        # 联网搜索策略,目前仅支持 agent 策略:可多次调用联网搜索工具与大模型,实现多轮信息检索与内容整合
        "search_strategy": "agent",
        "enable_source": True # 是否返回搜索来源
    },
    result_format="message",
)
print("="*20 + "搜索结果" + "="*20)
for web in response.output.search_info["search_results"]:
    print(f"[{web['index']}]: [{web['title']}]({web['url']})")
print("="*20 + "回复内容" + "="*20)
print(response.output.choices[0].message.content)
响应示例
====================搜索结果====================
[1]: [阿里巴巴(BABA)股票价格_行情_走势图 - 东方财富](https://wap.eastmoney.com/quote/stock/106.BABA.html)
[2]: [阿里巴巴(BABA)_美股行情_今日股价与走势图_新浪财经](https://gu.sina.cn/quotes/us/BABA)
[3]: [阿里巴巴(BABA)股票最新价格行情,实时走势图,股价分析预测](https://cn.investing.com/equities/alibaba)
[4]: [阿里巴巴-W (9988.HK) 股價、新聞、報價和記錄 - Yahoo 財經](https://hk.finance.yahoo.com/quote/9988.HK/)
[5]: [阿里巴巴(BABA)股票股价_股价行情_讨论 - 雪球](https://xueqiu.com/S/BABA)
[6]: [阿里巴巴(BABA)股票股价, 市值, 实时行情, 走势图, 财报- Moomoo](https://www.moomoo.com/hans/stock/BABA-US)
[7]: [Alibaba Group Holding Limited (BABA) Stock Price, News, Quote ...](https://finance.yahoo.com/quote/BABA/)
[8]: [阿里巴巴 - 腾讯证券](https://gu.qq.com/usBABA.N)
[9]: [W(09988)股票股价, 市值, 实时行情, 走势图, 财报- 阿里巴巴 - Moomoo](https://www.moomoo.com/hans/stock/09988-HK)
====================回复内容====================
根据最新的市场数据,阿里巴巴的股价信息如下:

*   **美股 (BABA)**:
    *   今日开盘价:160.98美元
    *   昨日收盘价:160.80美元
    *   今日最高价:161.19美元
    *   今日最低价:156.20美元

*   **港股 (09988.HK)**:
    *   最新报价约为:158.00 - 158.10港元
    *   今日开盘价:156.50港元
    *   前一交易日收盘价:162.00港元
    *   今日波动范围:156.30 - 158.40港元

Java

import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.aigc.generation.SearchOptions;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.common.Role;
import java.util.Arrays;

public class Main {
    // 以下为新加坡地域配置,调用时请将 {WorkspaceId} 替换为真实的业务空间ID,各地域的配置不同。
    static {Constants.baseHttpApiUrl="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";}
    public static void main(String[] args) {
        Generation gen = new Generation();
        Message userMsg = Message.builder()
                .role(Role.USER.getValue())
                .content("阿里巴巴的股价")
                .build();

        SearchOptions searchOptions = SearchOptions.builder()
                // 联网搜索策略,仅支持配置为 agent
                .searchStrategy("agent")
                // 返回搜索来源
                .enableSource(true)
                .build();

        GenerationParam param = GenerationParam.builder()
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .model("qwen3-max")
                .messages(Arrays.asList(userMsg))
                .resultFormat(GenerationParam.ResultFormat.MESSAGE)
                .enableSearch(true)
                .searchOptions(searchOptions)
                .build();
        try {
            GenerationResult result = gen.call(param);
            System.out.println("=".repeat(20)+"搜索结果"+"=".repeat(20));
            System.out.println(result.getOutput().getSearchInfo().getSearchResults());
            System.out.println("=".repeat(20)+"回复内容"+"=".repeat(20));
            System.out.println(result.getOutput().getChoices().get(0).getMessage().getContent());
        } catch (Exception e) {
            System.out.println("Error: " + e.getMessage());
        }
    }
}
响应示例
====================搜索结果====================
[SearchInfo.SearchResult(siteName=null, icon=null, index=1, title=阿里巴巴(BABA)股票价格_行情_走势图 - 东方财富, url=https://wap.eastmoney.com/quote/stock/106.BABA.html), SearchInfo.SearchResult(siteName=null, icon=null, index=2, title=阿里巴巴(BABA)_美股行情_今日股价与走势图_新浪财经, url=https://gu.sina.cn/quotes/us/BABA), SearchInfo.SearchResult(siteName=null, icon=null, index=3, title=阿里巴巴(BABA)股票最新价格行情,实时走势图,股价分析预测, url=https://cn.investing.com/equities/alibaba), SearchInfo.SearchResult(siteName=null, icon=null, index=4, title=阿里巴巴(BABA)股票股价_股价行情_讨论 - 雪球, url=https://xueqiu.com/S/BABA), SearchInfo.SearchResult(siteName=null, icon=null, index=5, title=阿里巴巴-W (9988.HK) 股價、新聞、報價和記錄 - Yahoo 財經, url=https://hk.finance.yahoo.com/quote/9988.HK/), SearchInfo.SearchResult(siteName=null, icon=null, index=6, title=阿里巴巴(BABA)股票股价, 市值, 实时行情, 走势图, 财报- Moomoo, url=https://www.moomoo.com/hans/stock/BABA-US), SearchInfo.SearchResult(siteName=null, icon=null, index=7, title=Alibaba Group Holding Limited (BABA) - Yahoo Finance, url=https://finance.yahoo.com/quote/BABA/), SearchInfo.SearchResult(siteName=null, icon=null, index=8, title=阿里巴巴 - 腾讯证券, url=https://gu.qq.com/usBABA.N), SearchInfo.SearchResult(siteName=null, icon=null, index=9, title=W(09988)股票股价, 市值, 实时行情, 走势图, 财报- 阿里巴巴 - Moomoo, url=https://www.moomoo.com/hans/stock/09988-HK)]
====================回复内容====================
根据最新的市场数据,阿里巴巴的股价如下:

*   **美股 (BABA)**:最新股价约为 **159.84 美元**。
*   **港股 (09988.HK)**:最新股价约为 **158.00 港元**。

请注意,股价会随市场交易实时波动,以上信息仅供参考。

curl

# 以下为新加坡地域配置,调用时请将 {WorkspaceId} 替换为真实的业务空间ID,各地域的配置不同。
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen-plus",
    "input":{
        "messages":[
            {
                "role": "user",
                "content": "阿里巴巴的股价"
            }
        ]
    },
    "parameters": {
        "enable_search": true,
        "search_options": {
            "search_strategy": "agent",
            "enable_source": true
        },
        "result_format": "message"
    }
}'
响应示例
{
  "output": {
    "choices": [
      {
        "finish_reason": "stop",
        "message": {
          "content": "根据最新的市场数据,阿里巴巴的股价因其在美股和港股同时上市而有所不同:\n\n*   **美股 (BABA)**:最新股价约为 **160.40 美元**。\n    *   今日开盘价:160.98 美元\n    *   今日波动范围:156.20 - 161.19 美元\n\n*   **港股 (09988.HK)**:最新股价约为 **158.10 港元**。\n    *   今日开盘价:156.50 港元\n    *   今日波动范围:156.30 - 158.40 港元\n\n请注意,股价会随市场交易实时变动,以上信息仅供参考。",
          "role": "assistant"
        }
      }
    ],
    "search_info": {
      "search_results": [
        {
          "index": 1,
          "title": "阿里巴巴(BABA)股票价格_行情_走势图 - 东方财富",
          "url": "https://wap.eastmoney.com/quote/stock/106.BABA.html"
        },
        {
          "index": 2,
          "title": "阿里巴巴(BABA)_美股行情_今日股价与走势图_新浪财经",
          "url": "https://gu.sina.cn/quotes/us/BABA"
        },
        {
          "index": 3,
          "title": "阿里巴巴-W (9988.HK) 股價、新聞、報價和記錄 - Yahoo 財經",
          "url": "https://hk.finance.yahoo.com/quote/9988.HK/"
        },
        {
          "index": 4,
          "title": "阿里巴巴(BABA)股票最新价格行情,实时走势图,股价分析预测",
          "url": "https://cn.investing.com/equities/alibaba"
        },
        {
          "index": 5,
          "title": "阿里巴巴(BABA)股票股价_股价行情_讨论 - 雪球",
          "url": "https://xueqiu.com/S/BABA"
        },
        {
          "index": 6,
          "title": "阿里巴巴(BABA)股票股价, 市值, 实时行情, 走势图, 财报- Moomoo",
          "url": "https://www.moomoo.com/hans/stock/BABA-US"
        },
        {
          "index": 7,
          "title": "W(09988)股票股价, 市值, 实时行情, 走势图, 财报- 阿里巴巴 - Moomoo",
          "url": "https://www.moomoo.com/hans/stock/09988-HK"
        },
        {
          "index": 8,
          "title": "Alibaba Group Holding Limited (BABA) 股價、新聞、報價和記錄",
          "url": "https://hk.finance.yahoo.com/quote/BABA/"
        },
        {
          "index": 9,
          "title": "阿里巴巴 - 腾讯证券",
          "url": "https://gu.qq.com/usBABA.N"
        }
      ]
    }
  },
  "usage": {
    "input_tokens": 2004,
    "output_tokens": 203,
    "plugins": {
      "search": {
        "count": 1,
        "strategy": "agent"
      }
    },
    "prompt_tokens_details": {
      "cached_tokens": 0
    },
    "total_tokens": 2207
  },
  "request_id": "45c231d2-811e-4e04-a361-f2c1909f1dd9"
}

Responses API的联网搜索

通过 tools 参数的tools数组中添加 web_search 工具即可启用联网搜索。

支持以下模型:Qwen3.8、Qwen3.7、Qwen3.5 系列模型(含开源模型,不含Omni)、Qwen3.6-Plus、Qwen3.6-Flash 系列及 qwen3.6-35b-a3b;qwen3-max、qwen3-max-2026-01-23;deepseek-v4-flash、deepseek-v4-flash-0731、deepseek-v4-pro、deepseek-v4-pro-0813;glm-5.2;kimi-k3。

为了获得最佳回复效果,建议同时开启 web_searchweb_extractorcode_interpreter 工具。

关于Responses API的使用说明、代码示例和迁移指南,请参见 OpenAI兼容-Responses

from openai import OpenAI
import os

client = OpenAI(
    # 若没有配置环境变量,请用百炼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"
)

response = client.responses.create(
    model="qwen3.7-max",
    input="新加坡天气",
    tools=[
        {"type": "web_search"},
        {"type": "web_extractor"},
        {"type": "code_interpreter"}
    ],
    extra_body={"enable_thinking": True}
)

print("="*20 + "回复内容" + "="*20)
print(response.output_text)

print("="*20 + "工具调用次数" + "="*20)
usage = response.usage
if hasattr(usage, 'x_tools') and usage.x_tools:
    print(f"联网搜索次数: {usage.x_tools.get('web_search', {}).get('count', 0)}")
# 取消以下注释查看中间过程的输出
# for r in response.output:
#     print(r.model_dump_json())
import OpenAI from "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"
});

async function main() {
    const response = await openai.responses.create({
        model: "qwen3.7-max",
        input: "新加坡天气",
        tools: [
            { type: "web_search" },
            { type: "web_extractor" },
            { type: "code_interpreter" }
        ],
        enable_thinking: true
    });

    console.log("====================回复内容====================");
    console.log(response.output_text);

    console.log("====================工具调用次数====================");
    console.log(`联网搜索次数: ${response.usage?.x_tools?.web_search?.count || 0}`);

    // console.log(JSON.stringify(response.output[0], null, 2));
}

main();
# 以下为新加坡地域配置,调用时请将 {WorkspaceId} 替换为真实的业务空间ID,各地域的配置不同。
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/responses \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen3.7-max",
    "input": "新加坡天气",
    "tools": [
        {"type": "web_search"},
        {"type": "web_extractor"},
        {"type": "code_interpreter"}
    ],
    "enable_thinking": true
}'

获取搜索来源

执行联网搜索后,搜索来源会在响应的 output 数组中 typeweb_search_call 的元素内返回,其 action.sources 字段为搜索来源链接列表。可在上述示例的 response 基础上按如下方式提取:

Responses API 暂不支持 enable_sourceenable_citationcitation_format 参数,不会在回复内容中自动插入 [1] 角标。如需角标标注,请使用 DashScope 调用方式。

# 在上述 response 的基础上提取搜索来源
print("=" * 20 + "搜索来源" + "=" * 20)
for item in response.output:
    if item.type == "web_search_call":
        for i, source in enumerate(item.action.sources, start=1):
            print(f"[{i}] {source.url}")

计费说明

说明本文所述“联网搜索”为模型内置的联网搜索功能,其计费如下方所示,本身不提供免费调用额度。它与百炼 MCP 广场提供的“联网搜索 MCP”服务是相互独立的两个功能,计费也相互独立:联网搜索 MCP 全部用户前 2000 次调用免费,免费额度用尽后按 29 元/千次计费,详情请参见添加联网搜索MCP

联网搜索的费用包含两部分:

  • 模型调用费用:联网搜索的网页内容会拼接到提示词中,增加模型的输入 Token,按照模型的标准价格计费。价格详情请参考百炼控制台。使用 Responses API方式时,联网搜索工具的计费和agent 策略相同。

  • 搜索策略费用

    • agent 策略

      • 每调用 1000 次的费用为:

        • 华北2(北京)、美国(弗吉尼亚)、中国香港、日本(东京)、德国(法兰克福)地域:$0.573411
        • 新加坡地域 $10.00。
    • agent_max 策略(限时优惠):

      包含联网搜索与网页抓取的费用。

      • 联网搜索工具每 1000 次调用费用:

        • 华北2(北京)、美国(弗吉尼亚)、中国香港、日本(东京)、德国(法兰克福)地域:$0.573411。
        • 新加坡地域:$10.00。
      • 网页抓取工具限时免费。

Q:联网搜索后模型返回“无法回答”或无响应?

A:联网搜索结果可能包含管控信息,触发内容安全规则,导致模型返回 DataInspectionFailed 错误 (HTTP 400),响应内容为“抱歉,我无法回答这个问题”。排查方法:关闭联网搜索后重新发送相同查询,若模型正常回复,则确认是搜索返回的内容触发了拦截。内容安全拦截为非确定性行为,取决于搜索返回的具体内容,并非所有敏感话题查询都会触发。

错误信息

如果执行报错,请参见错误码进行解决。