Web search

Updated at:

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:

APIHow to enable
DashScope, OpenAI-compatible Chat CompletionsSet enable_search: true and configure the turbo, max, agent, or agent_max strategy in search_options.
OpenAI-compatible Responses, Anthropic-compatible APIAdd 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.

Qwen models

Modelturbo / maxagent / agent_maxweb_search (Responses)web_search (Anthropic)

Qwen4 and Qwen3.8 families

SupportedNot supportedSupportedSupported

Qwen3.7 family

SupportedSupportedSupportedSupported

Qwen3.8-Omni-Flash

Not supportedagent onlySupportedNot supported

Qwen3.5-Omni(Plus, Flash)
Qwen3.8-Omni-Flash-Realtime
Qwen3.5-Omni-Realtime(Plus, Flash)

Not supportedagent onlyNot supportedNot supported

qwen-plus-character, qwen-flash-character, qwen-flash-character-2026-02-26

SupportedNot supportedNot supportedNot supported

Other models

Modelturbo / maxagent / agent_maxweb_search (Responses)web_search (Anthropic)

DeepSeek V4 / V4.1 families

SupportedSupportedSupportedSupported

GLM family

Not supportedNot supportedglm-5.2 onlyglm-5.2 only

Kimi family

Not supportedNot supportedkimi-k3, kimi-k3.1-pro supportedkimi-k3, kimi-k3.1-pro supported

Qwen3.6 and earlier

Modelturbo / maxagent / agent_maxweb_search (Responses)web_search (Anthropic)

Qwen3.6 family

SupportedSupportedSupportedSupported

Qwen3.5 family

SupportedSupportedSupportedSupported

Qwen-Max family

SupportedNot supportedNot supportedNot supported

Qwen-Plus family

SupportedSupported

Supported (except qwen-plus-2025-01-25)

Not supported

Qwen-Flash family

SupportedSupportedSupportedNot supported

Core capabilities

Search strategyFeatureDashScopeChat CompletionsResponses / Anthropic

turbo / max

Web search

SupportedSupportedNot supported

Force web search

SupportedSupportedNot supported

Configure search strategy

SupportedSupportedNot supported

Domain-specific search

SupportedNot supportedNot supported

Set search freshness

SupportedSupportedNot supported

Restrict search sources to specific sites

SupportedSupportedNot supported

Guide the search scope with natural language

SupportedSupportedNot supported

Return search sources

SupportedNot supportedNot supported

Citation markers

SupportedNot supportedNot supported

Return search sources early

SupportedNot supportedNot supported

Mixed text and image output

SupportedSupportedNot supported

web_search

Web search

Not supportedNot supportedSupported

agent / agent_max

Web search

SupportedSupportedNot supported

Return search sources

SupportedNot supportedNot 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

ParameterType and valuesDescription

enable_search

boolean; true, false

Set to true to enable web search.

search_options

object

Web search configuration. See the subparameters below.

include_tool_usage

boolean; true

Return Chat Completions web search usage in usage.x_tools.search.count.

enable_text_image_mixed

boolean; true, false

Embed images in the response, independently of enable_search. Images are returned as HTML <img> tags, which you can render as HTML or convert to Markdown.

search_options

Place the following parameters in the search_options object.

ParameterType and valuesDescription

search_strategy

string; turbo (default), max, agent, agent_max

turbo balances speed and search quality. max queries multiple search engines for more comprehensive retrieval and may take longer to respond. agent and agent_max support multi-round retrieval and returning search sources; other search configuration options are unavailable. See Billing details for charges.

forced_search

boolean; true, false (default)

true forces web search; false lets the model decide whether to search.

enable_source

boolean; true, false

Return search sources in search_info.search_results.

enable_citation

boolean; true, false

Add citation markers to the response. Requires enable_source: true.

citation_format

string; [<number>] (default), [ref_<number>]

The citation marker formats are [1] and [ref_1], respectively.

enable_search_extension

boolean; true, false (default)

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.

freshness

integer; 7, 30, 180, 365

Retrieve content only from the specified number of recent days. If omitted, no time limit applies. Effective only with turbo.

assigned_site_list

array; ["baidu.com", "sina.cn"]

Restrict search sources to up to 25 sites. The default [] does not restrict sources. Effective only with turbo; results may be empty if the sites contain no relevant content.

intention_options.prompt_intervene

string; 仅检索 AI 技术相关内容

Use natural language to specify the search scope, such as a topic or region.

prepend_search_result

boolean; true, false (default)

true: The first chunk contains only search sources; response text follows in subsequent chunks. false: The first chunk contains search sources and the beginning of the response.

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.

View response example

Repeated entries, content chunks, and long text are omitted below.

id:1
event:result
:HTTP_STATUS/200
data: {"output":{"choices":[{"message":{"content":"","role":"assistant"},"finish_reason":"null"}],"search_info":{"search_results":[{"url":"https://www.sina.cn/news/detail/5366647989994682.html","title":"杭州11 月18 日16 时三小时天气预报","index":1,"icon":"https://img.alicdn.com/imgextra/i2/O1CN01mvEkNg1mbgbrppM5C_!!6000000004973-55-tps-32-32.svg","site_name":"新浪网"},"…(省略其余同类条目)"]}},"usage":{},"request_id":"18111bce-11b8-9833-ae80-1f0048984c37"}

…(省略重复的内容分片)

id:2
event:result
:HTTP_STATUS/200
data: {"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[],"reasoning_content":"The"}}],"search_info":{"extra_tool_info":[{"result":"杭州市2026-11-18基本天气信息:\n天气:阴\n温度:14℃\n风向:西北风\n风力:3级","tool":"weather"}],"search_results":[]}},"usage":{"input_tokens":1211,"output_tokens":1,"total_tokens":1212,"input_tokens_details":{"text_tokens":1211},"output_tokens_details":{"reasoning_tokens":1},"prompt_tokens_details":{"cached_tokens":0},"plugins":{"search":{"count":1,"strategy":"max"}}},"request_id":"18111bce-11b8-9833-ae80-1f0048984c37"}

…(省略重复的内容分片)

id:167
event:result
:HTTP_STATUS/200
data: {"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":[{"text":"**2"}],"reasoning_content":""}}],"search_info":{"extra_tool_info":[{"result":"杭州市2026-11-18基本天气信息:\n天气:阴\n温度:14℃\n风向:西北风\n风力:3级","tool":"weather"}],"search_results":[]}},"usage":{"input_tokens":1211,"output_tokens":547,"total_tokens":1758,"input_tokens_details":{"text_tokens":1211},"output_tokens_details":{"reasoning_tokens":544},"prompt_tokens_details":{"cached_tokens":0},"plugins":{"search":{"count":1,"strategy":"max"}}},"request_id":"18111bce-11b8-9833-ae80-1f0048984c37"}

…(省略重复的内容分片)

id:225
event:result
:HTTP_STATUS/200
data: {"output":{"choices":[{"finish_reason":"stop","message":{"role":"assistant","content":[]}}],"search_info":{"extra_tool_info":[{"result":"杭州市2026-11-18基本天气信息:\n天气:阴\n温度:14℃\n风向:西北风\n风力:3级","tool":"weather"}],"search_results":[]}},"usage":{"input_tokens":1211,"output_tokens":788,"total_tokens":1999,"input_tokens_details":{"text_tokens":1211},"output_tokens_details":{"reasoning_tokens":544},"prompt_tokens_details":{"cached_tokens":0},"plugins":{"search":{"count":1,"strategy":"max"}}},"request_id":"18111bce-11b8-9833-ae80-1f0048984c37"}

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.

View response example

Repeated entries, content chunks, and long text are omitted below.

data: {"model":"qwen4-max","id":"chatcmpl-ab888ded-f63b-9eee-93b8-fb015e1c081f","created":1795766819,"object":"chat.completion.chunk","usage":null,"choices":[{"logprobs":null,"index":0,"delta":{"role":"assistant","content":"","reasoning_content":""},"finish_reason":null}]}

…(省略重复的内容分片)

data: {"id":"chatcmpl-ab888ded-f63b-9eee-93b8-fb015e1c081f","object":"chat.completion.chunk","created":1795766819,"model":"qwen4-max","choices":[{"index":0,"delta":{"reasoning_content":"The","content":""},"logprobs":null,"finish_reason":null}],"usage":null}

…(省略重复的内容分片)

data: {"id":"chatcmpl-ab888ded-f63b-9eee-93b8-fb015e1c081f","object":"chat.completion.chunk","created":1795766819,"model":"qwen4-max","choices":[{"index":0,"delta":{"content":"**","reasoning_content":""},"logprobs":null,"finish_reason":null}],"usage":null}

…(省略重复的内容分片)

data: {"id":"chatcmpl-ab888ded-f63b-9eee-93b8-fb015e1c081f","object":"chat.completion.chunk","created":1795766819,"model":"qwen4-max","choices":[{"index":0,"delta":{"content":"","reasoning_content":""},"finish_reason":"stop","logprobs":null}],"usage":null}

…(省略重复的内容分片)

data: {"id":"chatcmpl-ab888ded-f63b-9eee-93b8-fb015e1c081f","object":"chat.completion.chunk","created":1795766819,"model":"qwen4-max","choices":[],"usage":{"prompt_tokens":1932,"total_tokens":2747,"completion_tokens":815,"prompt_tokens_details":{"cached_tokens":0,"text_tokens":1932},"completion_tokens_details":{"reasoning_tokens":609}}}

data: [DONE]

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.

View response example

Repeated entries, content chunks, and long text are omitted below.

{
  "background": false,
  "completed_at": 1795766978,
  "created_at": 1795766925,
  "frequency_penalty": 0.0,
  "id": "resp_4012e5f3-0630-90ae-ac11-4fd485a666b8",
  "max_output_tokens": 2500,
  "metadata": {},
  "model": "qwen4-max",
  "object": "response",
  "output": [
    {
      "content": [
        {
          "text": "The user is asking about the weather at West Lake in Hangzhou on November 18, 2026. Note: there's a …(省略后续文本)",
          "type": "reasoning_text"
        }
      ],
      "id": "rs_e5c82af9-9b6a-4ba0-ac2d-ffc07edc2f50",
      "status": "completed",
      "summary": [],
      "type": "reasoning"
    },
    {
      "action": {
        "queries": [
          "杭州 2026年11月18日 天气 气温",
          "…(省略其余同类条目)"
        ],
        "query": "杭州 2026年11月18日 天气 气温",
        "sources": [
          {
            "type": "url",
            "url": "https://www.tianqi.com/tianqi/hangzhou/20261118.html"
          },
          "…(省略其余同类条目)"
        ],
        "type": "search"
      },
      "id": "ws_9a6f7d63-101e-4d88-8377-4d25dc969502",
      "status": "completed",
      "type": "web_search_call"
    },
    {
      "content": [
        {
          "text": "The search results contain good data. Let me confirm the details: November 18, 2026 Hangzhou: light …(省略后续文本)",
          "type": "reasoning_text"
        }
      ],
      "id": "rs_0f6cfb19-3031-49ae-84ab-03de8471b929",
      "status": "completed",
      "summary": [],
      "type": "reasoning"
    },
    {
      "content": [
        {
          "text": "Confirmed data:\n- November 18, 2026, Hangzhou: light rain in the morning turning cloudy (tianqi.com …(省略后续文本)",
          "type": "reasoning_text"
        }
      ],
      "id": "rs_51ce5c32-52b1-49db-bbac-6291010e75d7",
      "status": "completed",
      "summary": [],
      "type": "reasoning"
    },
    {
      "content": [
        {
          "annotations": [],
          "logprobs": [],
          "text": "**天气**:11月18日西湖一带小雨转阴到多云,约9~15℃,20时实况11.2℃;冷空气影响,偏北风3级、阵风较大;降雨以小雨为主,傍晚渐止,次日转晴、最低仅5℃。\n\n**提醒**:9–11月秋季…(省略后续文本)",
          "type": "output_text"
        }
      ],
      "id": "msg_408428e5-cbe8-42a9-a750-68ccdf5395cd",
      "role": "assistant",
      "status": "completed",
      "type": "message"
    }
  ],
  "parallel_tool_calls": true,
  "presence_penalty": 0.0,
  "service_tier": "default",
  "status": "completed",
  "store": true,
  "temperature": 1.0,
  "text": {
    "format": {
      "type": "text"
    }
  },
  "tool_choice": "auto",
  "tool_usage": {
    "web_search": {
      "num_requests": 1
    }
  },
  "tools": [
    {
      "type": "web_search"
    },
    "…(省略其余同类条目)"
  ],
  "top_logprobs": 0,
  "top_p": 1.0,
  "usage": {
    "input_tokens": 11109,
    "input_tokens_details": {
      "cache_write_tokens": 0,
      "cached_tokens": 5120
    },
    "output_tokens": 1629,
    "output_tokens_details": {
      "reasoning_tokens": 997
    },
    "total_tokens": 12738
  }
}

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.

View response example

Repeated entries, content chunks, and long text are omitted below.

{
  "content": [
    {
      "signature": "",
      "thinking": "The user is asking in Chinese: search the web for the weather at West Lake in Hangzhou on November 1…(省略后续文本)",
      "type": "thinking"
    },
    {
      "caller": {
        "type": "direct"
      },
      "id": "srvtoolu_34f8e54c7e6c496e9fbcb5b5",
      "input": {
        "queries": [
          "杭州 2026年11月18日 天气 气温 降雨 风力",
          "…(省略其余同类条目)"
        ]
      },
      "name": "web_search",
      "type": "server_tool_use"
    },
    {
      "caller": {
        "type": "direct"
      },
      "content": [
        {
          "encrypted_content": "eyJ0aXRsZSI6ICLmna3lt54iLCAidXJsIjogImh0dHBzOi8vd29ybGR3ZWF0aGVyLndtby5pbnQvemgvY2l0eS5odG1sP2NpdHlJZD01NTYiLCAiaW5kZXgiOiAxfQ==",
          "title": "杭州",
          "type": "web_search_result",
          "url": "https://worldweather.wmo.int/zh/city.html?cityId=556"
        },
        "…(省略其余同类条目)"
      ],
      "tool_use_id": "srvtoolu_34f8e54c7e6c496e9fbcb5b5",
      "type": "web_search_tool_result"
    },
    {
      "signature": "",
      "thinking": "I have enough data. Regarding November 18, 2026: according to tianqi.com, light rain (xiaoyu), 15/9°…(省略后续文本)",
      "type": "thinking"
    },
    {
      "text": "**2026年11月18日杭州西湖**:阴到多云、局部小雨,气温约9~15℃,西北风3级,冷空气影响伴大风降温;当日16时市气象台发布霜冻蓝色预警,次日晨西湖街道等地最低仅2~4℃。\n\n**游览提醒*…(省略后续文本)",
      "type": "text"
    }
  ],
  "id": "msg_6c9a0823-cdba-48e9-89b3-c64e36153b6b",
  "model": "qwen4-max",
  "role": "assistant",
  "stop_reason": "end_turn",
  "type": "message",
  "usage": {
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "input_tokens": 4724,
    "output_tokens": 846,
    "prompt_tokens_details": {
      "cached_tokens": 512
    },
    "server_tool_use": {
      "web_search_requests": 1
    },
    "x_tools": {
      "web_search": {
        "count": 1
      }
    }
  }
}

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_search with search_strategy set to turbo or max.
  • 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_search tool in Responses and Anthropic is priced at the same rate as the agent strategy.
Search strategy or toolRegionPrice per 1000 calls
turboChina (Beijing)CNY 3
maxChina (Beijing)CNY 4
agent, agent_max, web_searchChina (Beijing), US (Virginia), China (Hong Kong), Japan (Tokyo), Germany (Frankfurt)CNY 4
agent, agent_max, web_searchSingaporeCNY 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: true in search_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, and usage contains plugins.
    • Chat Completions: Set include_tool_usage: true and check usage.x_tools.search.count.
    • Responses: Depending on the response structure, check usage.x_tools.web_search.count or the top-level tool_usage.web_search.num_requests.
    • Anthropic: Check usage.server_tool_use.web_search_requests.
  • Whether content was retrieved
    • DashScope: Check search_info.search_results. If a rate limit is reached, for example, search_info may still be returned while search_results is 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.

Fields named count are set during intent detection and do not indicate completed retrieval or provide a basis for billing or reconciliation. Qwen4 and Anthropic return num_requests and web_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.count or the top-level 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: 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.

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.

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.