Web search
Large language models have a knowledge cutoff and cannot answer real-time questions from their training data alone. Enable web search to retrieve current information about stock prices, weather, and the latest news.
Usage
Web search supports four API calling methods:
| API | How to enable |
|---|---|
| DashScope, OpenAI-compatible Chat Completions | Set enable_search: true and configure the turbo, max, agent, or agent_max strategy in search_options. |
| OpenAI-compatible Responses, Anthropic-compatible API | Add the web_search tool to tools. |
Supported models
The following tables list support for web search strategies and protocols by model family. A Qwen version family includes the Plus, Flash, Max, and open-source models of that version.
Qwen3.6 and earlier
| Model | turbo / max | agent / agent_max | web_search (Responses) | web_search (Anthropic) |
|---|---|---|---|---|
Qwen3.6 family | Supported | Supported | Supported | Supported |
Qwen3.5 family | Supported | Supported | Supported | Supported |
Qwen-Max family | Supported | Not supported | Not supported | Not supported |
Qwen-Plus family | Supported | Supported | Supported (except qwen-plus-2025-01-25) | Not supported |
Qwen-Flash family | Supported | Supported | Supported | Not supported |
Core capabilities
| Search strategy | Feature | DashScope | Chat Completions | Responses / Anthropic |
|---|---|---|---|---|
turbo / max | Web search | Supported | Supported | Not supported |
Force web search | Supported | Supported | Not supported | |
Configure search strategy | Supported | Supported | Not supported | |
Domain-specific search | Supported | Not supported | Not supported | |
Set search freshness | Supported | Supported | Not supported | |
Restrict search sources to specific sites | Supported | Supported | Not supported | |
Guide the search scope with natural language | Supported | Supported | Not supported | |
Return search sources | Supported | Not supported | Not supported | |
Citation markers | Supported | Not supported | Not supported | |
Return search sources early | Supported | Not supported | Not supported | |
Mixed text and image output | Supported | Supported | Not supported | |
web_search | Web search | Not supported | Not supported | Supported |
agent / agent_max | Web search | Supported | Supported | Not supported |
Return search sources | Supported | Not supported | Not supported |
Parameter reference
See the table below for parameters related to enable_search. The web_search tool in the Responses API and Anthropic protocol does not support these parameters.
Top-level parameters
| Parameter | Type and values | Description |
|---|---|---|
| boolean; | Set to |
| object | Web search configuration. See the subparameters below. |
| boolean; | Return Chat Completions web search usage in |
| boolean; | Embed images in the response, independently of |
search_options
Place the following parameters in the search_options object.
| Parameter | Type and values | Description |
|---|---|---|
| string; |
|
| boolean; |
|
| boolean; | Return search sources in |
| boolean; | Add citation markers to the response. Requires |
| string; | The citation marker formats are |
| boolean; | Enable domain-specific search for exchange rates, weather, stocks, fuel prices, calendars, gold and silver prices, lotteries, TV series, movies, vehicle license plate restrictions, and football matches. Stock data includes real-time prices for A-shares, Hong Kong stocks, and US stocks, the previous trading day’s closing price, historical trends, and closing prices over 30 days. Weather data includes current conditions, forecasts, and historical data. |
| integer; | Retrieve content only from the specified number of recent days. If omitted, no time limit applies. Effective only with |
| array; | Restrict search sources to up to 25 sites. The default |
| string; | Use natural language to specify the search scope, such as a topic or region. |
| boolean; |
|
Examples
The examples use the multimodal model qwen4-max to search for weather and visitor notices for West Lake in Hangzhou. DashScope and Chat Completions use the max strategy; Responses and Anthropic use the web_search tool.
DashScope
import os
import dashscope
client = dashscope.Client(
api_key=os.environ["DASHSCOPE_API_KEY"],
workspace=os.environ["DASHSCOPE_WORKSPACE"],
region="cn-beijing",
)
stream = client.multimodal.chat.create(
model="qwen4-max",
messages=[{"role": "user", "content": [{"text": '请联网查询2026年11月18日杭州西湖的天气、气温、降雨和风力,以及景区近期游览提醒,给出简短路线与穿衣建议,注明信息来源,正文控制在200字以内。'}]}],
stream=True,
incremental_output=True,
max_tokens=2500,
enable_search=True,
search_options={
"search_strategy": "max",
"forced_search": True,
"enable_search_extension": True,
"enable_source": True,
"enable_citation": True,
"citation_format": "[ref_<number>]",
"prepend_search_result": True,
},
)
usage = None
sources_printed = False
for chunk in stream:
if chunk.search_info 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))
// Node.js 18 及以上,使用内置 fetch,无需安装依赖。
const response = await fetch(
`https://${process.env.DASHSCOPE_WORKSPACE}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation`,
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.DASHSCOPE_API_KEY}`,
"Content-Type": "application/json",
"X-DashScope-SSE": "enable",
},
body: JSON.stringify({
"model": "qwen4-max",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"text": "请联网查询2026年11月18日杭州西湖的天气、气温、降雨和风力,以及景区近期游览提醒,给出简短路线与穿衣建议,注明信息来源,正文控制在200字以内。"
}
]
}
]
},
"parameters": {
"incremental_output": true,
"max_tokens": 2500,
"enable_search": true,
"search_options": {
"search_strategy": "max",
"forced_search": true,
"enable_search_extension": true,
"enable_source": true,
"enable_citation": true,
"citation_format": "[ref_<number>]",
"prepend_search_result": true
}
}
}),
signal: AbortSignal.timeout(240000),
},
);
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
// 逐段输出 SSE 响应,包括搜索来源、回答分片和用量统计。
const decoder = new TextDecoder();
for await (const chunk of response.body) {
process.stdout.write(decoder.decode(chunk, { stream: true }));
}
process.stdout.write(decoder.decode());
#!/usr/bin/env bash
set -euo pipefail
: "${DASHSCOPE_API_KEY:?请设置 DASHSCOPE_API_KEY}"
: "${DASHSCOPE_WORKSPACE:?请设置 DASHSCOPE_WORKSPACE}"
host="https://${DASHSCOPE_WORKSPACE}.cn-beijing.maas.aliyuncs.com"
curl -sS --no-buffer --max-time 240 \
--config <(printf 'header = "Authorization: Bearer %s"\n' "$DASHSCOPE_API_KEY") \
"$host/api/v1/services/aigc/multimodal-generation/generation" \
-H "Content-Type: application/json" \
-H "X-DashScope-SSE: enable" \
--data-binary @- <<'JSON'
{
"model": "qwen4-max",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"text": "请联网查询2026年11月18日杭州西湖的天气、气温、降雨和风力,以及景区近期游览提醒,给出简短路线与穿衣建议,注明信息来源,正文控制在200字以内。"
}
]
}
]
},
"parameters": {
"incremental_output": true,
"max_tokens": 2500,
"enable_search": true,
"search_options": {
"search_strategy": "max",
"forced_search": true,
"enable_search_extension": true,
"enable_source": true,
"enable_citation": true,
"citation_format": "[ref_<number>]",
"prepend_search_result": true
}
}
}
JSON
output.search_info.search_results returns search sources, and [ref_n] markers in the response refer to source indexes. usage.plugins.search returns the search count and strategy.
OpenAI-compatible Chat Completions
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["DASHSCOPE_API_KEY"],
base_url=f"https://{os.environ['DASHSCOPE_WORKSPACE']}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
stream = client.chat.completions.create(
model="qwen4-max",
messages=[{"role": "user", "content": '请联网查询2026年11月18日杭州西湖的天气、气温、降雨和风力,以及景区近期游览提醒,给出简短路线与穿衣建议,注明信息来源,正文控制在200字以内。'}],
stream=True,
stream_options={"include_usage": True},
max_tokens=2500,
extra_body={
"enable_search": True,
"include_tool_usage": True,
"search_options": {"search_strategy": "max", "forced_search": True},
},
)
for chunk in stream:
for choice in chunk.choices:
print(choice.delta.content or "", end="", flush=True)
if chunk.usage:
print(chunk.usage.model_dump_json(indent=2))
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: `https://${process.env.DASHSCOPE_WORKSPACE}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1`,
});
const stream = await client.chat.completions.create({
model: "qwen4-max",
messages: [{ role: "user", content: "请联网查询2026年11月18日杭州西湖的天气、气温、降雨和风力,以及景区近期游览提醒,给出简短路线与穿衣建议,注明信息来源,正文控制在200字以内。" }],
stream: true,
stream_options: { include_usage: true },
max_tokens: 2500,
enable_search: true,
include_tool_usage: true,
search_options: { search_strategy: "max", forced_search: true },
});
for await (const chunk of stream) {
for (const choice of chunk.choices) process.stdout.write(choice.delta.content ?? "");
if (chunk.usage) console.log(JSON.stringify(chunk.usage, null, 2));
}
#!/usr/bin/env bash
set -euo pipefail
: "${DASHSCOPE_API_KEY:?请设置 DASHSCOPE_API_KEY}"
: "${DASHSCOPE_WORKSPACE:?请设置 DASHSCOPE_WORKSPACE}"
host="https://${DASHSCOPE_WORKSPACE}.cn-beijing.maas.aliyuncs.com"
curl -sS --no-buffer --max-time 240 \
--config <(printf 'header = "Authorization: Bearer %s"\n' "$DASHSCOPE_API_KEY") \
"$host/compatible-mode/v1/chat/completions" \
-H "Content-Type: application/json" \
--data-binary @- <<'JSON'
{
"model": "qwen4-max",
"messages": [
{
"role": "user",
"content": "请联网查询2026年11月18日杭州西湖的天气、气温、降雨和风力,以及景区近期游览提醒,给出简短路线与穿衣建议,注明信息来源,正文控制在200字以内。"
}
],
"stream": true,
"stream_options": {
"include_usage": true
},
"max_tokens": 2500,
"enable_search": true,
"include_tool_usage": true,
"search_options": {
"search_strategy": "max",
"forced_search": true
}
}
JSON
choices[].delta.content returns response chunks, and the final usage contains usage statistics. When include_tool_usage is enabled, the search count is in usage.x_tools.search.count.
OpenAI-compatible Responses
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["DASHSCOPE_API_KEY"],
base_url=f"https://{os.environ['DASHSCOPE_WORKSPACE']}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
response = client.responses.create(
model="qwen4-max",
input='请联网查询2026年11月18日杭州西湖的天气、气温、降雨和风力,以及景区近期游览提醒,给出简短路线与穿衣建议,注明信息来源,正文控制在200字以内。',
tools=[
{"type": "web_search"},
],
max_output_tokens=2500,
)
print(response.output_text)
for item in response.output:
if item.type != "message":
print(item.model_dump_json(indent=2))
print(response.model_dump_json(indent=2))
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: `https://${process.env.DASHSCOPE_WORKSPACE}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1`,
});
const response = await client.responses.create({
model: "qwen4-max",
input: "请联网查询2026年11月18日杭州西湖的天气、气温、降雨和风力,以及景区近期游览提醒,给出简短路线与穿衣建议,注明信息来源,正文控制在200字以内。",
tools: [{ type: "web_search" }],
max_output_tokens: 2500,
});
console.log(response.output_text);
console.log(JSON.stringify(response, null, 2));
#!/usr/bin/env bash
set -euo pipefail
: "${DASHSCOPE_API_KEY:?请设置 DASHSCOPE_API_KEY}"
: "${DASHSCOPE_WORKSPACE:?请设置 DASHSCOPE_WORKSPACE}"
host="https://${DASHSCOPE_WORKSPACE}.cn-beijing.maas.aliyuncs.com"
curl -sS --no-buffer --max-time 240 \
--config <(printf 'header = "Authorization: Bearer %s"\n' "$DASHSCOPE_API_KEY") \
"$host/compatible-mode/v1/responses" \
-H "Content-Type: application/json" \
--data-binary @- <<'JSON'
{
"model": "qwen4-max",
"input": "请联网查询2026年11月18日杭州西湖的天气、气温、降雨和风力,以及景区近期游览提醒,给出简短路线与穿衣建议,注明信息来源,正文控制在200字以内。",
"tools": [
{
"type": "web_search"
}
],
"max_output_tokens": 2500
}
JSON
web_search_call returns search status and source URLs; message returns the answer. tool_usage.web_search.num_requests returns the search count.
Anthropic-compatible API
import os
from anthropic import Anthropic
client = Anthropic(
api_key=os.environ["DASHSCOPE_API_KEY"],
base_url=f"https://{os.environ['DASHSCOPE_WORKSPACE']}.cn-beijing.maas.aliyuncs.com/apps/anthropic",
)
response = client.messages.create(
model="qwen4-max",
max_tokens=2500,
system=[{"type": "text", "text": "x-anthropic-billing-header: cc_entrypoint=cli;"}],
messages=[{"role": "user", "content": '请联网查询2026年11月18日杭州西湖的天气、气温、降雨和风力,以及景区近期游览提醒,给出简短路线与穿衣建议,注明信息来源,正文控制在200字以内。'}],
tools=[{"type": "web_search_20250305", "name": "web_search", "max_uses": 3}],
)
for block in response.content:
if block.type == "text":
print(block.text)
elif block.type in ("server_tool_use", "web_search_tool_result"):
print(block.model_dump_json(indent=2))
print(response.usage.model_dump_json(indent=2))
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: `https://${process.env.DASHSCOPE_WORKSPACE}.cn-beijing.maas.aliyuncs.com/apps/anthropic`,
});
const response = await client.messages.create({
model: "qwen4-max",
max_tokens: 2500,
system: [{ type: "text", text: "x-anthropic-billing-header: cc_entrypoint=cli;" }],
messages: [{ role: "user", content: "请联网查询2026年11月18日杭州西湖的天气、气温、降雨和风力,以及景区近期游览提醒,给出简短路线与穿衣建议,注明信息来源,正文控制在200字以内。" }],
tools: [{ type: "web_search_20250305", name: "web_search", max_uses: 3 }],
});
for (const block of response.content) {
if (block.type === "text") console.log(block.text);
else if (["server_tool_use", "web_search_tool_result"].includes(block.type)) console.log(JSON.stringify(block, null, 2));
}
console.log(JSON.stringify(response.usage, null, 2));
#!/usr/bin/env bash
set -euo pipefail
: "${DASHSCOPE_API_KEY:?请设置 DASHSCOPE_API_KEY}"
: "${DASHSCOPE_WORKSPACE:?请设置 DASHSCOPE_WORKSPACE}"
host="https://${DASHSCOPE_WORKSPACE}.cn-beijing.maas.aliyuncs.com"
curl -sS --no-buffer --max-time 240 \
--config <(printf 'header = "Authorization: Bearer %s"\n' "$DASHSCOPE_API_KEY") \
"$host/apps/anthropic/v1/messages" \
-H "Content-Type: application/json" \
-H "anthropic-version: 2023-06-01" \
--data-binary @- <<'JSON'
{
"model": "qwen4-max",
"max_tokens": 2500,
"system": [
{
"type": "text",
"text": "x-anthropic-billing-header: cc_entrypoint=cli;"
}
],
"messages": [
{
"role": "user",
"content": "请联网查询2026年11月18日杭州西湖的天气、气温、降雨和风力,以及景区近期游览提醒,给出简短路线与穿衣建议,注明信息来源,正文控制在200字以内。"
}
],
"tools": [
{
"type": "web_search_20250305",
"name": "web_search",
"max_uses": 3
}
]
}
JSON
server_tool_use and web_search_tool_result return tool calls and search results, respectively; text returns the answer. usage.server_tool_use.web_search_requests returns the search count.
Billing details
To help you try and test web search, the first 2000 web search calls under the same Alibaba Cloud primary account are free. Each account receives this allowance only once; it does not reset monthly. After it is exhausted, the current billing rules apply. The allowance covers:
- Web search through
enable_searchwithsearch_strategyset toturboormax. - Web Search MCP. For details, see Web Search MCP.
Web search charges consist of model usage and search tool charges:
- Model usage: Retrieved web content increases input tokens and is charged at the model’s standard rate. See Model pricing.
- Search tools: Prices are listed below. The
web_searchtool in Responses and Anthropic is priced at the same rate as theagentstrategy.
| Search strategy or tool | Region | Price per 1000 calls |
|---|---|---|
| turbo | China (Beijing) | CNY 3 |
| max | China (Beijing) | CNY 4 |
| agent, agent_max, web_search | China (Beijing), US (Virginia), China (Hong Kong), Japan (Tokyo), Germany (Frankfurt) | CNY 4 |
| agent, agent_max, web_search | Singapore | CNY 73.392381 |
Billing for turbo and max began at 00:00 on February 27, 2026. agent_max currently has a limited-time promotional price, with web page extraction temporarily free. The legacy standard and pro strategies are billed at the turbo rate; pro_max and pro_ultra are billed at the max rate. These legacy strategies are no longer recommended.
Rate limits
Web search is limited to 15 RPS (requests per second) per Alibaba Cloud primary account, across all API keys and models. When the limit is exceeded, the API does not return an error, but search is not triggered.
Frequently asked questions
Q: Why does the model not search the web after web search is enabled?
A: Possible reasons include:
- The model decides search is unnecessary: If the question does not require current information, the model may answer from its own knowledge. To force search, set
forced_search: trueinsearch_options. - Rate limit reached: Requests under the account exceed 15 RPS. The API skips search without returning an error. Reduce the request rate.
- Model not supported: The model does not support web search. See Supported models.
Q: How can I tell whether a search was performed?
A: Check two aspects:
-
Whether search was triggered
- DashScope: The response contains
search_info, andusagecontainsplugins. - Chat Completions: Set
include_tool_usage: trueand checkusage.x_tools.search.count. - Responses: Depending on the response structure, check
usage.x_tools.web_search.countor the top-leveltool_usage.web_search.num_requests. - Anthropic: Check
usage.server_tool_use.web_search_requests.
- DashScope: The response contains
-
Whether content was retrieved
- DashScope: Check
search_info.search_results. If a rate limit is reached, for example,search_infomay still be returned whilesearch_resultsis empty. - Responses: Check
web_search_call.action.sources. - Anthropic: Check the source URLs in
web_search_tool_result.content. - Input tokens: Compare token counts to see whether retrieved web content was included.
For example, asking “杭州天气” uses 10 input tokens without web search and 1953 input tokens with web search.
- DashScope: Check
Fields named
countare set during intent detection and do not indicate completed retrieval or provide a basis for billing or reconciliation. Qwen4 and Anthropic returnnum_requestsandweb_search_requests, respectively. See Billing count and API search count differences.
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: Depending on the response structure, check
usage.x_tools.web_search.countor the top-leveltool_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: Why does web search not run for an English query?
A: Support for English in search intent detection is being improved. For now, use Chinese queries or force web search for English queries.
Q: Does enabling web search expose the user’s query externally?
A: No. The original query is not passed directly to search engines. The system analyzes its intent and applies multiple layers of desensitization to extract only the information needed for retrieval. The query is rewritten multiple times before retrieval to prevent sensitive information from being exposed in plain text. Alibaba Cloud uses data encryption and privacy protection measures. See the Service agreement for details.
Q: Can vector retrieval leak information?
A: No. Vectors are high-dimensional mathematical representations and are not readable. External systems cannot reconstruct the original text from them. Vector matching takes place in a closed, trusted environment and is not exposed to public search engines.
Q: How does the system decide whether to search?
A: The system first decides whether search is needed. Queries unrelated to current events usually do not trigger search. Searches mostly involve current events or general knowledge, which has little overlap with confidential information. Each query is rewritten multiple times before retrieval.
Q: Why does the model return “unable to answer” or no response after web search?
A: Search results may contain restricted content and trigger content safety rules, resulting in a DataInspectionFailed error (HTTP 400) with the response “抱歉,我无法回答这个问题”. To troubleshoot, disable web search and resend the same query. If the model responds normally, the retrieved content triggered the block. Content safety blocking is non-deterministic and depends on the search results; not every query about a sensitive topic triggers it.
Q: What should I do if a stock price query returns prices on a non-trading day?
A: Use qwen3.7-max or a newer model. qwen3.7-max recognizes non-trading days and indicates that no closing price is available. qwen-max lacks date reasoning and returns stock prices obtained from search on non-trading days. enable_search_extension and prompt_intervene cannot resolve this issue.
Q: How do I enable web search for Kimi models?
A: kimi-k3.1-pro deployed on Alibaba Cloud Model Studio supports Responses web_search and Anthropic web_search in Beijing, Singapore, US (Virginia), Germany (Frankfurt), Japan (Tokyo), and China (Hong Kong). It does not support Chat Completions enable_search.
kimi-k3 supports the web_search tool in Responses and Anthropic, but not the enable_search parameter in Chat Completions. For more flexible retrieval, create an agent application in the Model Studio console and add a web search MCP tool, such as bailian_web_search, under Tools > MCP Services. Web Search MCP and built-in web search are separate features with independent billing. See Connect Harness tools for details.
Error messages
For errors, see Error codes.