Skip to main content

联网搜索

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

使用方式

DashScope、Chat Completions 设置 enable_search: true,通过 search_options 配置 agent 或 agent_max;Responses、Anthropic 通过 web_search 工具启用联网搜索。

支持的模型

下表按模型和协议列出联网搜索的支持情况。 Qwen 版本系列指该版本下的 Max、Plus、Flash 和开源模型。

千问模型

模型agent / agent_maxweb_search (Responses)web_search (Anthropic)
Qwen4、Qwen3.8不支持支持支持
Qwen3.7支持支持Max / Plus / Flash
Qwen3.8-Omni-Flash仅 agent支持不支持
Qwen3.5-Omni(Plus、Flash)
Qwen3.8-Omni-Flash-Realtime
Qwen3.5-Omni-Realtime(Plus、Flash)
仅 agent不支持不支持

第三方模型

模型agent / agent_maxweb_search (Responses)web_search (Anthropic)
deepseek-v4-pro、deepseek-v4-pro-0813
deepseek-v4-flash-0731、deepseek-v4.1-flash-1017
支持支持支持
glm-5.2不支持支持支持
kimi-k3、kimi-k3.1-pro不支持支持支持
模型agent / agent_maxweb_search (Responses)web_search (Anthropic)
Qwen3.6(Plus、Flash)支持支持支持
qwen3.6-35b-a3b支持支持不支持
qwen3.6-27b支持不支持不支持
Qwen3.5(Plus、Flash)支持支持支持
qwen3.5-27b、qwen3.5-35b-a3b
qwen3.5-122b-a10b、qwen3.5-397b-a17b
支持支持不支持
Qwen-Plus、Qwen-Flash 支持 agent 策略。

调用示例

以下示例使用新加坡配置,查询天气及景区游览提醒。DashScope、Chat Completions 使用多模态模型 qwen3.7-plus 和 agent 策略;Responses、Anthropic 使用 qwen4-max 和 web_search 工具。 其他地域的接入域名和业务空间部署范围,参见选择地域、服务部署范围和接入域名。 多模态模型使用多模态接口;DashScope 联网搜索需流式调用(stream=True),Java 使用 MultiModalConversation.streamCall。文本模型使用文本生成接口。
  • DashScope
  • Chat Completions
  • Responses
  • Anthropic
import os
import dashscope

client = dashscope.Client(
    api_key=os.environ["DASHSCOPE_API_KEY"],
    workspace=os.environ["DASHSCOPE_WORKSPACE"],
    region="ap-southeast-1",
)
stream = client.multimodal.chat.create(
    model="qwen3.7-plus",
    messages=[{"role": "user", "content": [{"text": 'Search the web for current weather in Singapore and recent visitor notices for Gardens by the Bay. Give temperature, rain, a short route, clothing advice, and source URLs in at most 200 words.'}]}],
    stream=True,
    incremental_output=True,
    max_tokens=2500,
    enable_search=True,
    search_options={"search_strategy": "agent", "enable_source": True},
)
usage = None
sources_printed = False
for chunk in stream:
    if chunk.search_info and chunk.search_info.search_results and not sources_printed:
        print(chunk.search_info.model_dump_json(indent=2))
        sources_printed = True
    for choice in chunk.choices:
        print(choice.delta.content or "", end="", flush=True)
    if chunk.usage:
        usage = chunk.usage
print()
if usage:
    print(usage.model_dump_json(indent=2))
output.search_info.search_results 返回搜索来源,usage.plugins.search 返回搜索计数和策略。

查看响应示例

以下响应省略了重复条目、内容分片和长文本。
id:1
event:result
:HTTP_STATUS/200
data: {"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","reasoning_content":"Thinking","content":[]}}],"search_info":{"search_results":[]}},"usage":{"input_tokens":370,"output_tokens":1,"total_tokens":371,"output_tokens_details":{"reasoning_tokens":1,"text_tokens":1},"prompt_tokens_details":{"cached_tokens":0},"input_tokens_details":{"text_tokens":370}},"request_id":"1e85c487-48dd-980f-853c-5bd164877bf9"}

... (repeated chunks omitted)

id:93
event:result
:HTTP_STATUS/200
data: {"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","reasoning_content":"","content":[]}}],"search_info":{"search_results":[{"title":"Singapore, Central Singapore, Singapore Weather Forecast","url":"https://www.accuweather.com/en/sg/singapore/300597/weather-forecast/300597","index":1},"... (remaining entries omitted)"]}},"usage":{"input_tokens":370,"output_tokens":357,"total_tokens":727,"output_tokens_details":{"reasoning_tokens":305,"text_tokens":357},"prompt_tokens_details":{"cached_tokens":0},"plugins":{"search":{"count":1,"strategy":"agent"}},"input_tokens_details":{"text_tokens":370}},"request_id":"1e85c487-48dd-980f-853c-5bd164877bf9"}

... (repeated chunks omitted)

id:372
event:result
:HTTP_STATUS/200
data: {"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"text":"**"}],"reasoning_content":""}}],"search_info":{"search_results":[{"title":"Singapore, Central Singapore, Singapore Weather Forecast","url":"https://www.accuweather.com/en/sg/singapore/300597/weather-forecast/300597","index":1},"... (remaining entries omitted)"]}},"usage":{"input_tokens":2425,"output_tokens":1322,"total_tokens":3747,"output_tokens_details":{"reasoning_tokens":1266,"text_tokens":1322},"prompt_tokens_details":{"cached_tokens":0},"plugins":{"search":{"count":1,"strategy":"agent"}},"input_tokens_details":{"text_tokens":2425}},"request_id":"1e85c487-48dd-980f-853c-5bd164877bf9"}

... (repeated chunks omitted)

id:445
event:result
:HTTP_STATUS/200
data: {"output":{"choices":[{"finish_reason":"stop","message":{"role":"assistant","content":[],"reasoning_content":""}}],"search_info":{"search_results":[{"title":"Singapore, Central Singapore, Singapore Weather Forecast","url":"https://www.accuweather.com/en/sg/singapore/300597/weather-forecast/300597","index":1},"... (remaining entries omitted)"]}},"usage":{"input_tokens":2425,"output_tokens":1591,"total_tokens":4016,"output_tokens_details":{"reasoning_tokens":1266,"text_tokens":1591},"prompt_tokens_details":{"cached_tokens":0},"plugins":{"search":{"count":1,"strategy":"agent"}},"input_tokens_details":{"text_tokens":2425}},"request_id":"1e85c487-48dd-980f-853c-5bd164877bf9"}

计费说明

联网搜索费用由模型调用费用和搜索工具费用组成。
  • 模型调用费用:检索到的网页内容增加输入 Token,按所用模型的标准价格计费,价格请查看百炼控制台。
  • 搜索工具费用:按下表计费,Responses 和 Anthropic 的 web_search 与 agent 策略价格相同。
搜索策略或工具地域每 1000 次调用价格
agent、agent_max、web_search华北2(北京)、美国(弗吉尼亚)、中国香港、日本(东京)、德国(法兰克福)$0.573411
agent、agent_max、web_search新加坡$10.00
agent_max 当前为限时优惠价格,包含联网搜索与网页抓取费用,其中网页抓取工具限时免费。

常见问题

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

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

Q:账单的联网搜索次数与 API 返回的搜索次数不一致,如何对账?

A:不同协议和模型返回的搜索计次字段不同:
  • DashScope: usage.plugins.search.count.
  • Chat Completions: usage.x_tools.search.count.
  • Responses: usage.x_tools.web_search.count / tool_usage.web_search.num_requests.
  • Anthropic: usage.server_tool_use.web_search_requests.
其中,名称为 count 的字段表示本轮对话经意图判定需要联网搜索,不代表检索已实际完成。即使触发限流或检索未返回结果,仍可能返回计数;num_requests 和 web_search_requests 表示 API 返回的搜索请求次数。 账单以搜索服务实际完成检索并正常返回结果为计费依据。API 返回的计次字段用于观察调用情况,对账请以账单出账数据为准。

错误信息

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