联网搜索

为实时问题开启搜索能力,支持 Chat Completions、Responses 与 DashScope 差异化接入

概述

Ling.AI 会透传百炼侧的联网搜索参数。对于 /v1/chat/completions,通常通过 enable_searchsearch_options 开启;对于 /v1/responses,则通过 tools 数组中的 web_searchweb_extractorcode_interpreter 工具启用。

协议差异

OpenAI 兼容 Chat Completions 适合快速接入搜索;Responses API 适合带工具编排的复杂检索;需要返回搜索来源、角标引用或首包提前返回搜索结果时,请优先使用 DashScope 协议。

网页抓取

如果您的目标不是“搜到相关网页”,而是“进一步进入网页抽取正文”,请参考 网页抓取指南。该场景通常需要 web_extractorsearch_strategy=agent_max

文搜图

如果您的目标是根据文本描述搜索图片,请参考 文搜图指南。该场景通过 Responses API 的 web_search_image 工具启用。

图搜图

如果您的目标是根据输入图片搜索视觉相似结果,请参考 图搜图指南。该场景同样仅支持 Responses API,但使用的是 image_search 工具,并且请求中必须包含 input_image

Chat Completions

/v1/chat/completions 中,开启搜索最常见的方式是传入 enable_search: true,并通过 search_options 配置策略。

Python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.vip.lingapi.ai/v1",
    api_key="sk-xxxxxxxx"
)

completion = client.chat.completions.create(
    model="qwen-plus",
    messages=[
        {"role": "user", "content": "杭州明天天气如何"}
    ],
    extra_body={
        "enable_search": True,
        "search_options": {
            "forced_search": True,
            "search_strategy": "max"
        }
    }
)

print(completion.choices[0].message.content)

常见 search_options 字段包括:

  • search_strategy:搜索策略,如 turbomaxagent
  • forced_search:是否强制触发搜索。
  • enable_search_extension:是否开启垂域搜索增强。
  • freshness:限制搜索时效范围。
  • assigned_site_list:限制搜索来源站点。
  • intention_options.prompt_intervene:用自然语言干预检索范围。

Responses API

/v1/responses 中,联网搜索通过工具方式启用。常见组合是同时传入 web_searchweb_extractorcode_interpreter

Python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.vip.lingapi.ai/v1",
    api_key="sk-xxxxxxxx"
)

response = client.responses.create(
    model="qwen3-max-2026-01-23",
    input="杭州天气",
    tools=[
        {"type": "web_search"},
        {"type": "web_extractor"},
        {"type": "code_interpreter"}
    ],
    enable_thinking=True
)

print(response.output_text)

Responses 提示

Responses API 下的联网搜索不是通过 enable_search 开关触发,而是通过工具列表触发。若您在同一请求中还需要其他工具,请按 Responses 工具格式一并传入。

DashScope 增强能力

若使用 DashScope 协议,可额外获得更细的搜索结果控制能力,包括来源返回、引用标注和搜索结果首包提前返回。

  • enable_source:在响应中返回搜索来源列表。
  • enable_citation:在正文中插入引用角标。
  • prepend_search_result:流式场景下先返回搜索来源,再返回模型正文。
Python
import dashscope

response = dashscope.Generation.call(
    api_key="sk-xxxxxxxx",
    model="qwen-plus",
    messages=[{"role": "user", "content": "杭州明天天气如何"}],
    enable_search=True,
    search_options={
        "enable_source": True,
        "enable_citation": True,
        "prepend_search_result": True
    },
    result_format="message"
)

图文混合输出

enable_text_image_mixed 与联网搜索相互独立。若模型支持图文混合输出,您可以单独开启,或和联网搜索一起组合使用。

计费与判定

  • 搜索结果会增加模型输入 Token,因此会抬高模型调用成本。
  • 若响应中包含百炼风格的 usage.plugins.searchsearch_info,通常说明搜索链路已执行。
  • Responses 或 DashScope 搜索工具的调用次数,可能会以 usage.x_toolsoutput 中的 *_call 或工具调用统计形式出现,Ling.AI 会保留这些信息供结算和审计使用。