Skip to main content
Tool calling

Web search

Ground model responses in real-time web data

The training data for large language models has a knowledge cutoff date, preventing them from answering real-time questions. Enabling web search lets a model retrieve real-time data from the internet and accurately answer time-sensitive questions, such as stock prices, weather forecasts, and breaking news. Get an API key and set it as an environment variable. qwen4-max supports web search. Chat Completions does not support search_strategy: agent; use the Responses API web_search tool for multi-turn retrieval. For DashScope and Chat Completions, set enable_search: true and configure agent or agent_max in search_options. For Responses and Anthropic, add the web_search tool.
  • OpenAI compatible
  • Responses API
  • DashScope
  • Anthropic-compatible
Set enable_search: true and optionally pass search_options to choose a strategy.
The OpenAI compatible Chat Completions endpoint does not return search sources. Use the Responses API or DashScope if you need citations.
import os
from openai import OpenAI

client = OpenAI(
  api_key=os.getenv("DASHSCOPE_API_KEY"),
  # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
  # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
  base_url="https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
  model="qwen3.7-max",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "How is Alibaba's stock price?"},
  ],
  extra_body={
    "enable_search": True,
    "search_options": {
      "search_strategy": "agent"
    }
  }
)
print(completion.choices[0].message.content)

Web search with multimodal models

The Qwen3.8 Max, Flash, and open-source series, Qwen3.7-Flash, Qwen3.7-Plus, the Qwen3.6 series, and the Qwen3.5 series (including qwen3.5-plus, qwen3.5-flash, the qwen3.5-omni series, and Qwen open-source models) accept multimodal input (images, video) and are multimodal models. Search strategy support varies 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 on the multimodal API (use the default turbo or max)—to run Qwen3.8 with agent-style retrieval, use Web search with the Responses API; other models listed in this section support the turbo, max, and agent strategies. Call these models through the multimodal API (the multimodal-generation endpoint): use client.multimodal.chat.create in the Python SDK 2.0 and MultiModalConversation in Java, not the text-generation endpoint, which is for text-only models. For the basics of calling multimodal models, see the Visual reasoning and Image and video understanding topics.
  • Calling the multimodal models above through the text-generation endpoint returns 400 url error, please check url. Use the multimodal API instead (the multimodal-generation endpoint; client.multimodal.chat.create in Python, MultiModalConversation in Java).
  • In the Java SDK, MultiModalConversationParam provides enableSearch(true) to enable web search, but does not provide a searchOptions() method. Inject the search strategy and other options through the generic parameter("search_options", ...) method. In Python, client.multimodal.chat.create accepts search_options directly.
  • Web search on multimodal models requires streaming calls (use streamCall in Java, or set stream=True in Python); otherwise the request returns a Non-streaming mode does not support Web Search error.
import os
import dashscope

# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
client = dashscope.Client(
  api_key=os.getenv("DASHSCOPE_API_KEY"),
  base_url="https://ap-southeast-1.maas.qwencloudapi.com/api/v1",
)
stream = client.multimodal.chat.create(
  model="qwen3.5-plus",
  messages=[{"role": "user", "content": [{"text": "What is the weather in Hangzhou today?"}]}],
  enable_search=True,
  search_options={
    # The qwen3.5-omni series requires agent. On the multimodal API the Qwen3.8 series does not support agent; 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 following models support web search. Models with multimodal input (the Qwen3.8 series, Qwen3.7-Flash/Plus, the Qwen3.6 series, the Qwen3.5 series, and Qwen open-source models) must be called through the multimodal API. See Web search with multimodal models. Supported models differ by region. Use an API key from the region you call. In Germany (Frankfurt), China (Hong Kong), and Japan (Tokyo), call from a workspace whose service deployment scope is Global.
  • Singapore
  • China North 2 (Beijing)
  • Germany (Frankfurt)
  • China (Hong Kong)
  • Japan (Tokyo)
  • US (Virginia)
Qwen
Model seriesAvailable models
Qwen4 seriesqwen4-max (search_strategy: agent is not supported; for agent-style retrieval, use the web_search tool through the Responses or Anthropic API)
Qwen3.8 seriesqwen3.8-max, qwen3.8-max-0902, qwen3.8-flash, qwen3.8-2.4t-a95b, qwen3.8-27b (search_strategy: agent is not supported; for agent-style retrieval, use the web_search tool through the Responses or Anthropic API)
Qwen3.7 seriesqwen3.7-max, qwen3.7-max-preview, qwen3.7-max-2026-05-17 and later snapshots, qwen3.7-plus, qwen3.7-plus-2026-05-26 and later snapshots, qwen3.7-flash, qwen3.7-flash-2026-07-15 and later snapshots
Qwen3.6 seriesqwen3.6-plus, qwen3.6-plus-2026-04-02 and later snapshots, qwen3.6-flash, qwen3.6-flash-2026-04-16 and later snapshots, qwen3.6-27b, qwen3.6-35b-a3b
Qwen3.5 seriesqwen3.5-plus, qwen3.5-plus-2026-02-15 and later snapshots, qwen3.5-flash, qwen3.5-flash-2026-02-23 and later snapshots, qwen3.5-27b, qwen3.5-35b-a3b, qwen3.5-122b-a10b, qwen3.5-397b-a17b
Qwen-Omniqwen3.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-Realtimeqwen3.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
ProviderAvailable models
DeepSeekdeepseek-v4.1-flash, deepseek-v4.1-flash-1017, deepseek-v4-pro, deepseek-v4-pro-0813, deepseek-v4-flash-0731 (all listed models also support the agent / agent_max strategies and the web_search tool in the Responses and Anthropic APIs)
GLMglm-5.2 (supported by the web_search tool in the Responses and Anthropic APIs)
Kimikimi-k3.1-pro (supports Responses web_search and Anthropic web_search; Chat Completions enable_search is not supported); kimi-k3 (supports Responses and Anthropic web_search; Chat Completions enable_search is not supported)

Search strategies

Use the search_strategy field in search_options to choose the retrieval mode:
  • agent (default) -- Calls the web search tool and the model multiple times for multi-round information retrieval and integration. Suitable for complex queries and English scenarios. Applies to the Qwen3.5 series (including open-source models and the Omni series), the Qwen3.6 series, the Qwen3.7 series, and the DeepSeek V4/V4.1 series. Streaming calls are required when calling through the text endpoint. The Qwen3.8 series and Qwen4 do not support agent; use the web_search tool through the Responses or Anthropic API instead. When enabled, only enable_source: true (returning search sources) is supported; other web search options are unavailable. Each invocation is billed additionally, see Billing.
  • agent_max -- An enhanced multi-round mode that includes web search and web page extraction. Billed at the same rate as agent; web page extraction is free for a limited time.
For everyday queries, agent is sufficient. For research or report generation that requires high accuracy and multi-source cross-validation, choose agent_max.

Read search results

When you set enable_source: true (DashScope only), the response includes a search_info.search_results array. Each entry contains:
FieldDescription
indexCitation number referenced in the response text
titlePage title of the source
urlURL of the source
Use these fields to render inline citations or a references list in your application. The model's response text may reference sources by index (e.g., "according to source [1]").

Get search sources

After a web search runs, the search sources are returned in the response. They appear in the element whose type is web_search_call within the output array, and its action.sources field is the list of source links. You can extract them from the response in the example above as follows:
The Responses API does not support the enable_source, enable_citation, or citation_format parameters, and does not insert [1] citation markers into the response content. To use citation markers, use the DashScope API.
# Extract search sources from the response above
print("=" * 20 + "Search sources" + "=" * 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

Billing involves two aspects:
  • Model call fees: The web content from the web search is added to the prompt, which increases the number of input tokens for the model. You are charged based on the standard pricing of the model. For more information about pricing, see Pricing.
  • Search call fees (per 1,000 calls):
    The web_search tool in the Responses and Anthropic APIs is billed at the same rate as the agent strategy.
    The prices listed below are list prices. For current promotions and discounted pricing, visit the Model Marketplace.
    Strategy (search_strategy)What it doesFee
    agent (default)Model searches the web as neededSingapore: $10.00. China North 2 (Beijing), Germany (Frankfurt), China (Hong Kong), Japan (Tokyo), US (Virginia): $0.573411
    agent_max (limited-time offer)Includes web search and web extractorSingapore: $10.00. China North 2 (Beijing), Germany (Frankfurt), China (Hong Kong), Japan (Tokyo), US (Virginia): $0.573411. The web extractor is free for a limited time

Q: The number of web searches on the bill differs from the number returned by the API. How do I reconcile them?

A: Search usage fields differ by protocol and model:
  • 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.
Fields named count indicate that intent detection determined a web search was needed, not that retrieval completed. They may contain a count even when rate limits are reached or retrieval returns no results. num_requests and web_search_requests report the number of search requests returned by the API. Billing is based on retrieval that the search service completes and returns successfully. API usage fields help you observe calls; use the issued bill to reconcile charges.

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". To troubleshoot, disable web search and resend the same query. If the model replies normally, the content returned by the search triggered the interception. Content safety interception is non-deterministic and depends on the specific content returned by the search; not all sensitive-topic queries trigger it.

Error codes

If a call fails, see Error messages.