Large language models (LLMs) are trained on historical data and therefore cannot answer real-time questions. With web search, the model can retrieve up-to-date information before generating its response.
Usage
Enable web search in one of three ways. Each method uses a different parameter:
OpenAI-Compatible Responses API
Use the tools parameter and add the web_search tool.
The Responses API supports only Qwen3.5, qwen3-max, qwen3-max-2026-01-23.
For best results, enable all three tools:web_search,web_extractor, andcode_interpreter.
# Import dependencies and create client...
response = client.responses.create(
model="qwen3-max-2026-01-23",
input="Weather in Hangzhou",
tools=[
{"type": "web_search"},
{"type": "web_extractor"},
{"type": "code_interpreter"}
],
extra_body={"enable_thinking": True}
)OpenAI-Compatible Chat Completions API
Set enable_search: true to enable web search.
# Import dependencies and create client...
completion = client.chat.completions.create(
# Use a model that supports web search
model="qwen3-max",
messages=[{"role": "user", "content": "What will the weather be like in Hangzhou tomorrow?"}],
# Because enable_search is not an OpenAI standard parameter, pass it via extra_body in Python SDK (or as a top-level parameter in Node.js SDK)
extra_body={"enable_search": True}
)DashScope
Set enable_search: true to enable web search.
# Import dependencies...
response = dashscope.Generation.call(
# If you have not set environment variables, replace the next line with your Model Studio API key: api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
# Use a model that supports web search
model="qwen3-max",
messages=[{"role": "user", "content": "What will the weather be like in Hangzhou tomorrow?"}],
# Enable web search using the enable_search parameter
enable_search=True,
result_format="message"
)Supported models
International
Qwen-Plus: qwen3.5-plus, qwen3.5-plus-2026-02-15 and later snapshot versions
Both thinking and non-thinking modes support the
agentandagent_maxsearch strategies.Qwen-Flash: qwen3.5-flash, qwen3.5-flash-2026-02-23 and later snapshot versions
Both thinking and non-thinking modes support the
agentandagent_maxsearch strategies.Qwen-Max:
qwen3-max and qwen3-max-2026-01-23:
In non-thinking mode: set the search strategy to
agent.In thinking mode: set the search strategy to
agentoragent_max(adds web scraping support).
qwen3-max-2025-09-23: set the search strategy to
agent.
Qwen-Omni: qwen3.5-omni-plus, qwen3.5-omni-plus-2026-03-15, qwen3.5-omni-flash, qwen3.5-omni-flash-2026-03-15
Set the search strategy to
agentQwen-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
Set the search strategy to
agentRole play: qwen-plus-character, qwen-flash-character
Global
Qwen-Plus: qwen3.5-plus, qwen3.5-plus-2026-02-15 and later snapshot versions
Qwen-Flash: qwen3.5-flash, qwen3.5-flash-2026-02-23 and later snapshot versions
Both thinking and non-thinking modes support the agent and agent_max search strategies.
Mainland China
Qwen-Max:
qwen3-max and qwen3-max-2026-01-23:
In non-thinking mode: set the search strategy to
agentIn thinking mode: set the search strategy to
agentoragent_max(adds web scraping support)
qwen3-max-2025-09-23: set the search strategy to
agent
Qwen-Plus: qwen3.5-plus, qwen3.5-plus-2026-02-15 and later snapshot versions
Both thinking and non-thinking modes support the
agentandagent_maxsearch strategiesQwen-Flash: qwen3.5-flash, qwen3.5-flash-2026-02-23 and later snapshot versions
Both thinking and non-thinking modes support the
agentandagent_maxsearch strategiesQwen-Omni: qwen3.5-omni-plus, qwen3.5-omni-plus-2026-03-15, qwen3.5-omni-flash, qwen3.5-omni-flash-2026-03-15
Set the search strategy to
agentQwen-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
Set the search strategy to
agentRole play: qwen-plus-character
Getting started
Query stock information using web search.
OpenAI-Compatible
The OpenAI-compatible protocol does not support returning search sources in responses.
Python
import os
from openai import OpenAI
client = OpenAI(
# If you have not set environment variables, replace the next line with your Model Studio API key: api_key="sk-xxx",
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="qwen3-max",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is Alibaba's stock price?"},
],
extra_body={
"enable_search": True,
"search_options": {
# Web search strategy; only agent is supported
"search_strategy": "agent"
}
}
)
print(completion.choices[0].message.content)Sample response
Based on the latest market data, Alibaba’s stock price is as follows:
* **U.S. Market (BABA)**: Latest price is about **$159.84**.
* **Hong Kong Market (09988.HK)**: Latest price is about **HK$158.00**.
Note: Stock prices change in real time. The above information is for reference only. Based on the latest market data, Alibaba’s stock price is as follows:
* **U.S. Market (BABA)**: Latest price is about **$159.84**.
* **Hong Kong Market (09988.HK)**: Latest price is about **HK$158.00**.
Note: Stock prices change in real time. The above information is for reference only.Node.js
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
});
async function main() {
const completion = await openai.chat.completions.create({
model: "qwen3-max",
messages: [
{ role: "user", content: "What is Alibaba's stock price?" }
],
enable_search: true,
search_options: {
// Web search strategy; only agent is supported
search_strategy: "agent"
}
});
console.log(completion.choices[0].message.content);
}
main();Sample response
Based on the latest market data, Alibaba’s stock price is as follows:
* **U.S. Market (BABA)**: Latest price is about **$159.84**.
* **Hong Kong Market (09988.HK)**: Latest price is about **HK$158.00**.
Note: Stock prices change in real time. The above information is for reference only. Based on the latest market data, Alibaba’s stock price is as follows:
* **U.S. Market (BABA)**: Latest price is about **$159.84**.
* **Hong Kong Market (09988.HK)**: Latest price is about **HK$158.00**.
Note: Stock prices change in real time. The above information is for reference only.curl
curl -X POST https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-max",
"messages": [
{
"role": "user",
"content": "What is Alibaba's stock price?"
}
],
"enable_search": true,
"search_options": {
"search_strategy": "agent"
}
}'DashScope
The DashScope protocol supports settingenable_sourcetotrueto include search sources in the response.
Python
import os
import dashscope
dashscope.base_http_api_url = "https://dashscope-intl.aliyuncs.com/api/v1"
response = dashscope.Generation.call(
api_key=os.getenv("DASHSCOPE_API_KEY"),
model="qwen3-max",
messages=[{"role": "user", "content": "What is Alibaba's stock price?"}],
enable_search=True,
search_options={
# Web search strategy; only agent is supported: call the web search tool and LLM multiple times to retrieve and synthesize information
"search_strategy": "agent",
"enable_source": True # Include search sources in response
},
result_format="message",
)
print("="*20 + "Search Results" + "="*20)
for web in response.output.search_info["search_results"]:
print(f"[{web['index']}]: [{web['title']}]({web['url']})")
print("="*20 + "Response Content" + "="*20)
print(response.output.choices[0].message.content)Sample response
====================Search Results====================
[1]: [Alibaba (BABA) Stock Price, Chart, and Quote — East Money](https://wap.eastmoney.com/quote/stock/106.BABA.html)
[2]: [Alibaba (BABA) U.S. Stock Price, Chart, and Quote — Sina Finance](https://gu.sina.cn/quotes/us/BABA)
[3]: [Alibaba (BABA) Stock Price, Chart, and Forecast — Investing.com](https://cn.investing.com/equities/alibaba)
[4]: [Alibaba-W (9988.HK) Stock Price, News, Quote, and Data — Yahoo Finance](https://hk.finance.yahoo.com/quote/9988.HK/)
[5]: [Alibaba (BABA) Stock Price, Discussion — Xueqiu](https://xueqiu.com/S/BABA)
[6]: [Alibaba (BABA) Stock Price, Market Cap, Real-Time Chart, Financial Reports — Moomoo](https://www.moomoo.com/hans/stock/BABA-US)
[7]: [Alibaba Group Holding Limited (BABA) Stock Price, News, Quote … — Yahoo Finance](https://finance.yahoo.com/quote/BABA/)
[8]: [Alibaba — Tencent Securities](https://gu.qq.com/usBABA.N)
[9]: [W (09988) Stock Price, Market Cap, Real-Time Chart, Financial Reports — Alibaba — Moomoo](https://www.moomoo.com/hans/stock/09988-HK)
====================Response Content====================
Based on the latest market data, Alibaba’s stock price is as follows:
* **U.S. Market (BABA)**:
* Today’s opening price: $160.98
* Yesterday’s closing price: $160.80
* Today’s high: $161.19
* Today’s low: $156.20
* **Hong Kong Market (09988.HK)**:
* Latest quote: HK$158.00–HK$158.10
* Today’s opening price: HK$156.50
* Previous trading day’s closing price: HK$162.00
* Today’s range: HK$156.30–HK$158.40Java
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 {
static {Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";}
public static void main(String[] args) {
Generation gen = new Generation();
Message userMsg = Message.builder()
.role(Role.USER.getValue())
.content("What is Alibaba's stock price?")
.build();
SearchOptions searchOptions = SearchOptions.builder()
// Web search strategy; only agent is supported
.searchStrategy("agent")
// Return search sources
.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)+"Search Results"+"=".repeat(20));
System.out.println(result.getOutput().getSearchInfo().getSearchResults());
System.out.println("=".repeat(20)+"Response Content"+"=".repeat(20));
System.out.println(result.getOutput().getChoices().get(0).getMessage().getContent());
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}Sample response
====================Search Results====================
[SearchInfo.SearchResult(siteName=null, icon=null, index=1, title=Alibaba (BABA) Stock Price, Chart, and Quote — East Money, url=https://wap.eastmoney.com/quote/stock/106.BABA.html), SearchInfo.SearchResult(siteName=null, icon=null, index=2, title=Alibaba (BABA) U.S. Stock Price, Chart, and Quote — Sina Finance, url=https://gu.sina.cn/quotes/us/BABA), SearchInfo.SearchResult(siteName=null, icon=null, index=3, title=Alibaba (BABA) Stock Price, Chart, and Forecast — Investing.com, url=https://cn.investing.com/equities/alibaba), SearchInfo.SearchResult(siteName=null, icon=null, index=4, title=Alibaba (BABA) Stock Price, Discussion — Xueqiu, url=https://xueqiu.com/S/BABA), SearchInfo.SearchResult(siteName=null, icon=null, index=5, title=Alibaba-W (9988.HK) Stock Price, News, Quote, and Data — Yahoo Finance, url=https://hk.finance.yahoo.com/quote/9988.HK/), SearchInfo.SearchResult(siteName=null, icon=null, index=6, title=Alibaba (BABA) Stock Price, Market Cap, Real-Time Chart, Financial Reports — 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=Alibaba — Tencent Securities, url=https://gu.qq.com/usBABA.N), SearchInfo.SearchResult(siteName=null, icon=null, index=9, title=W (09988) Stock Price, Market Cap, Real-Time Chart, Financial Reports — Alibaba — Moomoo, url=https://www.moomoo.com/hans/stock/09988-HK)]
====================Response Content====================
Based on the latest market data, Alibaba’s stock price is as follows:
* **U.S. Market (BABA)**: Latest price is about **$159.84**.
* **Hong Kong Market (09988.HK)**: Latest price is about **HK$158.00**.
Note: Stock prices change in real time. The above information is for reference only.curl
curl -X POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/text-generation/generation \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-max",
"input":{
"messages":[
{
"role": "user",
"content": "What is Alibaba's stock price?"
}
]
},
"parameters": {
"enable_search": true,
"search_options": {
"search_strategy": "agent",
"enable_source": true
},
"result_format": "message"
}
}'Sample response
{
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"content": "Based on the latest market data, Alibaba’s stock price differs between U.S. and Hong Kong markets:\n\n* **U.S. Market (BABA)**: Latest price is about **$160.40**.\n * Today’s opening price: $160.98\n * Today’s range: $156.20–$161.19\n\n* **Hong Kong Market (09988.HK)**: Latest price is about **HK$158.10**.\n * Today’s opening price: HK$156.50\n * Today’s range: HK$156.30–HK$158.40\n\nNote: Stock prices change in real time. The above information is for reference only.",
"role": "assistant"
}
}
],
"search_info": {
"search_results": [
{
"index": 1,
"title": "Alibaba (BABA) Stock Price, Chart, and Quote — East Money",
"url": "https://wap.eastmoney.com/quote/stock/106.BABA.html"
},
{
"index": 2,
"title": "Alibaba (BABA) U.S. Stock Price, Chart, and Quote — Sina Finance",
"url": "https://gu.sina.cn/quotes/us/BABA"
},
{
"index": 3,
"title": "Alibaba-W (9988.HK) Stock Price, News, Quote, and Data — Yahoo Finance",
"url": "https://hk.finance.yahoo.com/quote/9988.HK/"
},
{
"index": 4,
"title": "Alibaba (BABA) Stock Price, Chart, and Forecast — Investing.com",
"url": "https://cn.investing.com/equities/alibaba"
},
{
"index": 5,
"title": "Alibaba (BABA) Stock Price, Discussion — Xueqiu",
"url": "https://xueqiu.com/S/BABA"
},
{
"index": 6,
"title": "Alibaba (BABA) Stock Price, Market Cap, Real-Time Chart, Financial Reports — Moomoo",
"url": "https://www.moomoo.com/hans/stock/BABA-US"
},
{
"index": 7,
"title": "W (09988) Stock Price, Market Cap, Real-Time Chart, Financial Reports — Alibaba — Moomoo",
"url": "https://www.moomoo.com/hans/stock/09988-HK"
},
{
"index": 8,
"title": "Alibaba Group Holding Limited (BABA) Stock Price, News, Quote and Data — Yahoo Finance",
"url": "https://hk.finance.yahoo.com/quote/BABA/"
},
{
"index": 9,
"title": "Alibaba — Tencent Securities",
"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"
}With the Responses API
Use the tools parameter to enable web search. Add the web_search tool to the tools array.
Supported only with qwen3.5-plus, qwen3.5-plus-2026-02-15, qwen3.5-flash, qwen3.5-flash-2026-02-23; and qwen3-max and qwen3-max-2026-01-23 in thinking mode.
For best results, enable all three tools:web_search,web_extractor, andcode_interpreter.
from openai import OpenAI
import os
client = OpenAI(
# If you have not set environment variables, replace the next line with your Model Studio API key: api_key="sk-xxx",
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
)
response = client.responses.create(
model="qwen3-max-2026-01-23",
input="Weather in Singapore",
tools=[
{"type": "web_search"},
{"type": "web_extractor"},
{"type": "code_interpreter"}
],
extra_body={"enable_thinking": True}
)
print("="*20 + "Response Content" + "="*20)
print(response.output_text)
print("="*20 + "Tool Call Count" + "="*20)
usage = response.usage
if hasattr(usage, 'x_tools') and usage.x_tools:
print(f"Web search count: {usage.x_tools.get('web_search', {}).get('count', 0)}")
# Uncomment to view intermediate output
# for r in response.output:
# print(r.model_dump_json())import OpenAI from "openai";
const openai = new OpenAI({
// If you have not set environment variables, replace the next line with your Model Studio API key: apiKey: "sk-xxx",
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
});
async function main() {
const response = await openai.responses.create({
model: "qwen3-max-2026-01-23",
input: "Weather in Singapore",
tools: [
{ type: "web_search" },
{ type: "web_extractor" },
{ type: "code_interpreter" }
],
enable_thinking: true
});
console.log("====================Response Content====================");
console.log(response.output_text);
Set search scope strategy
console.log("====================Tool Call Count====================");
You can set the search scope strategy based on your needs for cost, accuracy, and response speed.
console.log(`Web search count: ${response.usage.x_tools.web_search?.count || 0}`);
// console.log(JSON.stringify(response.output[0], null, 2));
}
main();curl -X POST https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/responses \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-max-2026-01-23",
"input": "Weather in Singapore",
"tools": [
{"type": "web_search"},
{"type": "web_extractor"},
{"type": "code_interpreter"}
],
"enable_thinking": true
}'Billing details
Billing covers two areas:
Model call fees: Web search content is appended to the prompt, increasing input tokens. You are billed at the model’s standard rate. For pricing, see Model List.
Search strategy fees:
agent strategy:
Cost per 1,000 calls:
Mainland China and global deployment: $0.573411
International deployment: $10.00.
agent_max strategy (limited-time offer):
Covers both web search and web scraping fees.
Web search tool cost per 1,000 calls:
Mainland China deployment: $0.573411.
International deployment: $10.00.
Web scraping tool is free during this promotion.
Error messages
If an error occurs, see Error Messages for troubleshooting.