Skip to main content

Web search

The training data for large language models has a knowledge cutoff date, preventing them from answering real-time questions. Enabling web search lets the model retrieve real-time data and accurately answer time-sensitive questions, such as stock prices, weather forecasts, and breaking news.

Usage

Web search supports the following four API call methods, each with different parameters for enabling it:
  • OpenAI compatible-Responses API
  • OpenAI compatible-Chat Completions API
  • DashScope
  • Anthropic compatible
Add the web_search tool via the tools parameter to enable web search.
The Responses API supports only some models. For supported models, see Web search with the Responses API.
# 导入依赖与创建客户端...
response = client.responses.create(
    model="qwen4-max",
    input="杭州天气",
    tools=[
        {"type": "web_search"},
        {"type": "web_extractor"},
        {"type": "code_interpreter"}
    ],
    extra_body={"enable_thinking": True}
)

Web search for multimodal models

Models such as the Qwen4-Max series, Qwen3.8 Max, Flash, and open-source series, Qwen3.7-Flash, Qwen3.7-Plus, the Qwen3.6 series, and the Qwen3.5 series (including the qwen3.5-plus, qwen3.5-flash, and qwen3.5-omni series, as well as Qwen open-source models) support multimodal input such as images and videos, and are multimodal models. Search strategies vary by series: the qwen3.5-omni series supports only the agent strategy; qwen4-max, qwen3.8-max, qwen3.8-max-0902, qwen3.8-flash, qwen3.8-2.4t-a95b, and qwen3.8-27b do not support the agent strategy with the multimodal interface (they use the default turbo or max). To use agent-style search with Qwen4 or Qwen3.8, switch to Web search with the Responses API; the other models listed in this section support the turbo, max, and agent strategies. These models must be called through the multimodal interface (the multimodal-generation endpoint): Python SDK 2.0 uses client.multimodal.chat.create, and Java uses MultiModalConversation, rather than the text-generation endpoint intended for text-only models. For basic usage of multimodal models, see the Visual Reasoning and Image and Video Understanding documentation.
If you call the multimodal models above through the text-generation endpoint, they return 400 url error, please check url. Use the multimodal interface instead (the multimodal-generation endpoint; client.multimodal.chat.create in Python and MultiModalConversation in Java). The Java SDK's MultiModalConversationParam provides enableSearch(true) to enable web search but does not provide a searchOptions() method; use the generic parameter parameter("search_options", ...) to inject configuration such as the search strategy. Python's client.multimodal.chat.create accepts search_options directly. When web search is enabled for multimodal models, you must use streaming calls (streamCall in Java, stream=True in Python); otherwise the error Non-streaming mode does not support Web Search is returned.
Python
import os
import dashscope

# The following is the configuration for the Singapore (ap-southeast-1) region. Replace {WorkspaceId} with your actual workspace ID. The region value varies by region.
client = dashscope.Client(
    # If you have not configured the environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
    # API keys differ by region. To get an API key, see https://www.alibabacloud.com/help/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    workspace="{WorkspaceId}",
    region="ap-southeast-1",
)
stream = client.multimodal.chat.create(
    # Use a multimodal model that supports web search
    model="qwen3.5-plus",
    messages=[{"role": "user", "content": [{"text": "杭州今天天气如何"}]}],
    # The multimodal API accepts enable_search and search_options directly
    enable_search=True,
    search_options={
        # The qwen3.5-omni series requires "agent"; the Qwen3.8 series does not support agent on the multimodal API, keep the default
        "search_strategy": "agent",
        "enable_source": True,
    },
    # Web search on multimodal models requires streaming
    stream=True,
)
for chunk in stream:
    content = chunk.choices[0].delta.content or ""
    print(content)

Supported models

The models that support web search are as follows. Models that support multimodal input (the Qwen4-Max series, Qwen3.8 Max, Flash, and open-source series, Qwen3.7-Flash/Plus, the Qwen3.6 series, the Qwen3.5 series, and Qwen open-source models) must be called through the multimodal interface; see Web search for multimodal models.
  • Singapore
  • China (Beijing)
  • Global
  • Qwen
    • Qwen4 series: qwen4-max (search_strategy does not support agent; for agent-style search, use the web_search tool via the Responses API)
    • Qwen3.8 series: qwen3.8-max, qwen3.8-max-0902, qwen3.8-flash, qwen3.8-2.4t-a95b, qwen3.8-27b (search_strategy does not support agent; for agent-style search, use the web_search tool via the Responses API)
    • Qwen3.7 series: qwen3.7-max, qwen3.7-max-preview, qwen3.7-max-2026-05-17 and later snapshot versions, qwen3.7-plus, qwen3.7-plus-2026-05-26 and later snapshot versions, qwen3.7-flash, qwen3.7-flash-2026-07-15 and later snapshot versions
    • Qwen3.6 series: qwen3.6-plus, qwen3.6-plus-2026-04-02 and later snapshot versions, qwen3.6-flash, qwen3.6-flash-2026-04-16 and later snapshot versions, qwen3.6-27b, qwen3.6-35b-a3b
    • Qwen3.5 series: qwen3.5-plus, qwen3.5-plus-2026-02-15 and later snapshot versions, qwen3.5-flash, qwen3.5-flash-2026-02-23 and later snapshot versions, qwen3.5-27b, qwen3.5-35b-a3b, qwen3.5-122b-a10b, qwen3.5-397b-a17b
    • Qwen Omni: qwen3.8-omni-flash, qwen3.5-omni-plus, qwen3.5-omni-plus-2026-03-15, qwen3.5-omni-flash, qwen3.5-omni-flash-2026-03-15 (the search strategy must be set to agent)
    • Qwen Omni-Realtime: qwen3.8-omni-flash-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 (the search strategy must be set to agent)
  • Third-party models
    • DeepSeek: deepseek-v4-pro, deepseek-v4-pro-0813, deepseek-v4-flash-0731, deepseek-v4.1-flash-1017 (the deepseek-v4 series also supports the Responses API)
    • GLM: glm-5.2 (supports web search only via the Responses API)
    • Kimi: kimi-k3.1-pro (supports Responses web_search and Anthropic web_search, but not Chat Completions enable_search); kimi-k3 (supports web search only via the Responses API)

QuickStart

The following example queries stock information through web search.
  • OpenAI compatible
  • DashScope
Enable web search with enable_search=True. When using qwen3.8-omni-flash, you also need to set search_options={"search_strategy": "agent"}; if you call through the Responses API, configure tools=[{"type": "web_search"}]. See Responses API web search.
The OpenAI-compatible protocol does not support returning search sources in the response.
  • Python
  • Node.js
  • curl
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)
Response example
根据最新的市场数据,阿里巴巴的股价在不同市场表现如下:

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

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

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

请注意,股价会实时波动,以上信息仅供参考。
Adding the web_search tool to the tools array of the tools parameter enables web search.
When enabled through the web_search tool, the model runs in an agent-style multi-round retrieval mode—it autonomously initiates multiple web_search_call requests (combined with web_extractor_call when necessary) based on the question, and finally integrates the results to answer.
The following models are supported: the Qwen4-Max series; Qwen3.8 Max, Flash, and open-source series, qwen3.8-omni-flash; Qwen3.7 and Qwen3.5 series models (including open-source models, excluding Omni), Qwen3.6-Plus, the Qwen3.6-Flash series, and qwen3.6-35b-a3b; deepseek-v4-flash-0731, deepseek-v4.1-flash-1017, deepseek-v4-pro, deepseek-v4-pro-0813; glm-5.2; kimi-k3; kimi-k3.1-pro.
Agent-style retrieval for the Qwen4 / Qwen3.8 series: Qwen4-Max (qwen4-max) and the Qwen3.8 series (qwen3.8-max, qwen3.8-max-0902, qwen3.8-flash, qwen3.8-2.4t-a95b, qwen3.8-27b) do not support search_strategy: agent under the Chat Completions/DashScope protocols, but you can achieve the same agent-style multi-round retrieval capability through the Responses API web_search tool described in this section.
The Responses API does not use the search_strategy parameter. Whether a web search is initiated and whether multi-round retrieval is performed are both determined by whether the web_search tool is mounted and by the model's autonomous decision; passing search_options.search_strategy is silently ignored and does not trigger a search.
For models that support the following tools, it is recommended to enable web_search, web_extractor, and code_interpreter at the same time. The built-in tools of qwen3.8-omni-flash support only web_search.
For usage instructions, code examples, and migration guides for the Responses API, see OpenAI-compatible Responses .
python
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(
    # Qwen3.8 系列通过 Responses API 的 web_search 工具即可使用 agent 式多轮检索
    model="qwen4-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 = getattr(response, "tool_usage", {})
if usage:
    print(f"联网搜索次数: {usage.get('web_search', {}).get('num_requests')}")
    print(f"网页抓取次数: {usage.get('web_extractor', {}).get('num_requests')}")

# 打印每一轮 web_search_call 的搜索来源,观察 agent 式多轮检索过程
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}")
The Responses API of qwen4-max uses the top-level tool_usage of the response, where each tool's num_requests is the number of billable requests and pdf_page_parser.num_requests is the number of parsed pages. The Responses example for Qwen3.8 still uses usage.x_tools. The following example shows the output and tool counts of multi-round retrieval. Billable requests are based on tool_usage, not on the number of output items.
{
  "output": [
    {
      "type": "reasoning"
    },
    {
      "type": "web_search_call",
      "action": {
        "sources": [
          "..."
        ]
      }
    },
    {
      "type": "web_extractor_call"
    },
    {
      "type": "reasoning"
    },
    {
      "type": "web_search_call",
      "action": {
        "sources": [
          "..."
        ]
      }
    },
    {
      "type": "message",
      "content": [
        "..."
      ]
    }
  ],
  "tool_usage": {
    "web_search": {
      "num_requests": 2
    },
    "web_extractor": {
      "num_requests": 2
    }
  }
}

Get search sources

After a web search is performed, the search sources are returned in the element whose type is web_search_call in the response's output array, and its action.sources field is a list of search source links. Based on the response in the example above, you can extract them as follows:
The Responses API does not currently support the enable_source, enable_citation, or citation_format parameters, and it does not automatically insert [1] superscript citations into the reply content. If you need superscript citations, use the DashScope call method.
# 在上述 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}")

Billing Details

The fee for web search consists of two parts:
  • Model call fee: The web page content retrieved by web search is concatenated into the prompt, increasing the model's input tokens, and is billed at the model's standard price. For pricing details, refer to the Model Studio console. When using the Responses API or the Anthropic-compatible method, the billing for the web search tool is the same as for the agent strategy.
  • Search strategy fee:
    • agent strategy:
      • The fee for every 1,000 calls is:
        • China (Beijing), US (Virginia), Hong Kong (China), Japan (Tokyo), and Germany (Frankfurt) regions: $0.573411
        • Singapore region: $10.00.
    • agent_max policy (limited-time offer): The fee includes web search and web page fetching.
      • Web search tool fee per 1,000 calls:
        • China (Beijing), US (Virginia), Hong Kong (China), Japan (Tokyo), and Germany (Frankfurt) regions: $0.573411.
        • Singapore region: $10.00.
      • The web page fetching tool is free of charge for a limited time.

Q: After a web search, the model returns "unable to answer" or no response?

A: The web search results may contain controlled information that triggers content safety rules, causing the model to return the DataInspectionFailed error (HTTP 400) with the response "Sorry, I cannot answer this question". Troubleshooting method: disable web search and resend the same query; if the model replies normally, it confirms that the content returned by the search triggered the interception. Content safety interception is non-deterministic behavior that depends on the specific content returned by the search; not all sensitive-topic queries will trigger it.

Q: The web search count on the bill does not match the count field returned by the API. How do I reconcile them?

A: The two use different statistical scopes, so a difference in values is expected:
  • Billing: A call is billed when the search service actually completes retrieval and returns a successful result.
  • The count field (usage.plugins.search.count in the DashScope API, usage.x_tools.search.count (Chat Completions / Qwen3.8 Responses) in the OpenAI-compatible API; the two carry the same value): Indicates that intent detection determined this turn required a web search. The field is set during the intent-detection stage and does not mean retrieval actually completed. It still returns a value even when the rate limit is exceeded or retrieval returns no results; it is not set to 0 and is not omitted.
Therefore, count is not a basis for billing or reconciliation. Use your bill as the authoritative source for reconciliation.

Error messages

To troubleshoot errors, see Error codes.