跳到主要内容

联网搜索

让答案包含实时信息(行情、新闻、天气、事实核查)。图灵平台提供两条路径,适用场景不同:

路径典型用法你写什么
路径 A:模型内置搜索一次 LLM 调用就得到"已整合搜索结果"的最终答案/chat/completions/messages/responses 请求里加 toolsenable_search 参数
路径 B:独立搜索端点你自己控制 pipeline:先搜索、再喂给任意 LLM / RAG直接调用 /proxy/<provider>/search,拿到结果后自行拼 prompt

不确定走哪条?在需要 "模型自己决定何时搜索、且引用要自动注入回答" 的场景选 A;需要 "搜索结果要进 embedding / 做检索 / 和业务系统融合" 时选 B。


路径 A:模型内置搜索

Qwen / Gemini / Claude 走标准 /v1/chat/completions endpoint,参数差异体现在 tools / extra_body 里;字节火山(Ark)是唯一的例外,它的内置搜索只在 /v1/responses 上可用。完整请求体 schema 见 /api/create-chat-completion;Claude 原生协议见 Messages 接口;Responses 协议见 Response 接口

支持的模型

完整支持范围以模型列表中的厂商段落和 Web Search / 内置工具标记为准:

Qwen

from openai import OpenAI

client = OpenAI(
api_key="your-api-key",
base_url="https://live-turing.cn.llm.tcljd.com/api/v1"
)

response = client.chat.completions.create(
model="qwen-plus-latest",
messages=[
{"role": "user", "content": "杭州明天天气如何"}
],
# enable_search 非 OpenAI 标准参数,Python SDK 通过 extra_body 传入
extra_body={
"enable_search": True
}
)

print(response.choices[0].message.content)
curl $TURING_BASE_URL/chat/completions \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen-plus-latest",
"messages": [
{"role": "user", "content": "杭州明天天气如何"}
],
"enable_search": true
}'

Gemini

Gemini 系列用 tools 参数配置 Google Search,两种搜索模式:

  • googleSearch:标准 Google 搜索
  • enterpriseWebSearch:企业级搜索,提供更安全、合规的搜索结果
from openai import OpenAI

client = OpenAI(
api_key="your-api-key",
base_url="https://live-turing.cn.llm.tcljd.com/api/v1"
)

response = client.chat.completions.create(
model="turing/gemini-3-pro-latest",
messages=[
{"role": "user", "content": "上海今天天气如何"}
],
extra_body={
"tools": [{"googleSearch": {}}]
}
)

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

切换到企业级模式只需把 googleSearch 换成 enterpriseWebSearch

extra_body={
"tools": [{"enterpriseWebSearch": {}}]
}

Claude

Claude 系列通过 tools 参数传入 Anthropic 原生的 web_search_20250305 工具类型,模型会自动判断何时检索,并把搜索结果与引用整合到回答中。

官方文档:Web search tool (Anthropic)

可选字段:

  • max_uses:单次对话最多调用搜索的次数上限
  • allowed_domains / blocked_domains:域名白/黑名单(二选一)
  • user_location:提示模型检索时结合的地理位置信息
from openai import OpenAI

client = OpenAI(
api_key="your-api-key",
base_url="https://live-turing.cn.llm.tcljd.com/api/v1"
)

response = client.chat.completions.create(
model="turing/claude-sonnet-5",
max_tokens=4096,
messages=[
{"role": "user", "content": "今日上证指数收盘价是多少?"}
],
extra_body={
"tools": [
{
"type": "web_search_20250305",
"name": "web_search",
"max_uses": 3
}
]
}
)

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

Claude 响应结构

Claude 的响应里会包含搜索调用次数和引用元数据,具体字段位置取决于所用接口。无论走哪条接口,usage.server_tool_use.web_search_requests 都会返回本次请求实际触发的搜索次数,用于计费对账。

通过 /v1/messages(Anthropic 原生接口) —— content 数组按顺序出现以下 block:

  1. server_tool_use — 模型发起的搜索请求(含 input.query
  2. web_search_tool_result — 搜索结果列表(title / url / encrypted_content / page_age
  3. text — 最终回答;引用以独立 text block 形式插入,block 上的 citations[] 数组指向对应的 web_search_result_location

示例(节选):

{
"model": "claude-sonnet-5",
"content": [
{
"type": "server_tool_use",
"id": "srvtoolu_vrtx_01FZ...",
"name": "web_search",
"input": { "query": "上证指数今日收盘价" }
},
{
"type": "web_search_tool_result",
"tool_use_id": "srvtoolu_vrtx_01FZ...",
"content": [
{
"type": "web_search_result",
"title": "上证指数 (SSEC) 实时行情…",
"url": "https://cn.investing.com/indices/shanghai-composite",
"page_age": "5 days ago"
}
]
},
{
"type": "text",
"text": "上证指数最新报价为4,051.43点",
"citations": [
{
"type": "web_search_result_location",
"cited_text": "上证指数(SSEC)最新指数报价为4,051.43…",
"url": "https://cn.investing.com/indices/shanghai-composite",
"title": "上证指数 (SSEC) 实时行情…"
}
]
}
],
"usage": {
"input_tokens": 11505,
"output_tokens": 235,
"server_tool_use": {
"web_search_requests": 1
}
}
}

通过 /chat/completions(OpenAI 兼容接口) —— 响应形态贴近 OpenAI:

  • choices[0].message.content — 模型的最终文本回答
  • choices[0].message.tool_calls — 模型实际发起的每一次 web_search 调用
  • choices[0].message.provider_specific_fields.citations — 引用数组,含 cited_text / url / title / supported_text
  • usage.server_tool_use.web_search_requests — 本次触发的搜索次数
提示

encrypted_content / encrypted_index 字段是 Anthropic 侧用于多轮对话签名校验的不透明数据,透传回下一轮请求即可,不要篡改

字节火山 Ark

字节火山的联网搜索由 Ark 在服务端执行,通过 tools: [{"type": "web_search"}] 启用,模型自己决定检索时机并把引用写回回答。

只在 /v1/responses 上可用

这是和上面三家最大的差别。往 /chat/completions 传同样的 tools 会被 Ark 直接拒绝:

{"error": {"message": "VolcengineException - The request failed because it is missing `tools.function` parameter", "code": "400"}}

/chat/completions 上的 tools 只接受 type: function。需要联网就走 /v1/responses

官方文档:联网内容插件(火山方舟)↗

适用模型以 模型列表 → 字节火山 里的内置工具标记为准。

from openai import OpenAI

client = OpenAI(
api_key="your-api-key",
base_url="https://live-turing.cn.llm.tcljd.com/api/v1"
)

response = client.responses.create(
model="bytedance/deepseek-v4-flash",
input="用联网搜索查一下今天深圳的天气,给出信息来源链接",
tools=[{"type": "web_search"}],
)

print(response.output_text)
curl $TURING_BASE_URL/responses \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "bytedance/deepseek-v4-flash",
"input": "用联网搜索查一下今天深圳的天气,给出信息来源链接",
"tools": [{"type": "web_search"}]
}'

Ark 响应结构

output 数组里除了 reasoningmessage,还会多出 web_search_call 项,记录模型实际发起的每一次检索:

{
"output": [
{ "type": "reasoning", "summary": [], "status": "completed" },
{
"type": "web_search_call",
"id": "ws_0217858...",
"status": "completed",
"action": {
"type": "search",
"query": "深圳天气 2026年8月4日;深圳今日天气"
}
},
{
"type": "message",
"role": "assistant",
"content": [{ "type": "output_text", "text": "..." }]
}
]
}

引用以 url_citation 标注挂在 output_text 上。流式模式(stream: true)会额外推 response.web_search_call.in_progress / .searching / .completed 三个事件,引用则通过 response.output_text.annotation.added 增量下发。

usage 里会带上本次实际发起的检索次数,字段和 Claude / Gemini 都不一样tool_usage 是总数,tool_usage_details 是按内容来源拆开的明细。

"usage": {
"input_tokens": 3996,
"output_tokens": 1050,
"tool_usage": { "web_search": 3 },
"tool_usage_details": { "web_search": { "search_engine": 3 } }
}

流式与非流式口径一致,tool_usage 随最终的 response.completed 事件返回。


路径 B:独立搜索端点

平台代理了多家第三方搜索引擎,适合自定义 RAG pipeline:先拿结果,再做 embedding / rerank / 喂给任意 LLM。

Baidu(百度,仅中国区)

curl $TURING_BASE_URL/proxy/baidu/search \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"q": "帮我搜索一下今天的中证50的表现",
"count": 10
}'

响应节选:

{
"trace_id": "trace_32bHCrZm1GIXbYNyP6duD",
"code": 0,
"message": "Success",
"data": {
"requestId": "51ec6302-1aa0-4c09-b32a-d7e18c4676fc",
"references": [
{
"id": 1,
"title": "中证A50(930050)股票价格_行情_走势图…",
"url": "https://emwap.eastmoney.com/quote/stock/2.930050.html",
"website": "东方财富",
"content": "今开 最高 …",
"date": "2026-02-27 00:00:00",
"type": "web"
}
]
}
}

Tavily(全球,LLM-optimized)

请求体与响应结构完全透传 Tavily 官方协议,完整参数(search_depthtopictime_rangeinclude_domainsinclude_answerinclude_raw_content 等)请见 Tavily Search API Reference

  • 端点POST /proxy/tavily/search
  • 必填参数query
  • 常用参数max_resultssearch_depthbasic / advanced)、topicgeneral / news / finance)、time_rangeinclude_answerinclude_raw_contentinclude_domainsexclude_domains
curl $TURING_BASE_URL/proxy/tavily/search \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "latest AI developments 2024",
"max_results": 5
}'

响应节选:

{
"query": "latest AI developments 2024",
"results": [
{
"title": "2024 Global Trends in AI - WEKA",
"url": "https://www.weka.io/resources/analyst-report/2024-global-trends-in-ai/",
"content": "Discover key AI trends in 2024…",
"score": 0.7498395
}
],
"responseTime": 0.86,
"requestId": "bb84e696-88cd-4b0f-b832-0aba925d312e"
}

Tavily Extract(网页正文提取)

从一批已知 URL 中提取干净正文,适合你已经有链接列表(自己爬到的候选页、用户粘贴的链接),需要拿去做 embedding / RAG。

  • 端点POST /proxy/tavily/extract
  • 必填参数urls(单个 URL 字符串或 URL 数组)
  • 常用参数query(让提取聚焦于与该查询相关的内容)、extract_depthbasic / advanced,advanced 计费翻倍)、formatmarkdown / text)、chunks_per_sourceinclude_imagesinclude_favicontimeout
curl $TURING_BASE_URL/proxy/tavily/extract \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"urls": ["https://example.com/pricing"],
"extract_depth": "advanced",
"format": "markdown"
}'

响应节选:

{
"results": [
{
"url": "https://example.com/pricing",
"raw_content": "# Pricing\n..."
}
],
"failed_results": []
}
提示

只按成功返回的 URL 计费,出现在 failed_results 里的链接不计费。计费公式:(成功 URL 数 / 5) × (1,basic 或 2,advanced) × $0.008

Tavily Crawl(站内爬取)

从一个起始 URL 出发,按链接向外爬取并提取沿途每个页面的正文,适合你没有现成 URL 列表、只有一个入口页面,需要自动发现并抓取相关子页面。

  • 端点POST /proxy/tavily/crawl
  • 必填参数url(起始 URL)
  • 常用参数instructions(自然语言描述要找哪些页面,如 "find pricing pages")、max_depth(跟随的链接深度)、max_breadth(每页最多跟随的链接数)、limit(爬取页面总数上限)、select_paths / select_domains(正则白名单)、exclude_paths / exclude_domains(正则黑名单)、allow_external(是否跟随站外链接)、extract_depth(对每个爬到的页面生效,语义同 Extract)
curl $TURING_BASE_URL/proxy/tavily/crawl \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"instructions": "find pricing pages",
"max_depth": 2,
"limit": 20
}'

响应节选:

{
"base_url": "https://example.com",
"results": [
{ "url": "https://example.com/pricing", "raw_content": "..." },
{ "url": "https://example.com/plans", "raw_content": "..." }
]
}
提示

计费 = Map 费用 + Extract 费用,两者都按同一批成功页面数计算:map_cost(页面数) + extract_cost(页面数, extract_depth)。例如 20 个成功页面、extract_depth: "basic" 时为 (20/10 × $0.008) + (20/5 × $0.008) = $0.048

Tavily Map(站点结构发现)

只发现站点的 URL 结构、不提取正文内容,适合你只是想知道"这个站点下有哪些页面",之后再按需挑选页面调用 Extract。

  • 端点POST /proxy/tavily/map
  • 必填参数url(起始 URL)
  • 常用参数instructions(自然语言描述要包含哪些页面,设置后计费翻倍)、max_depthmax_breadthlimit(语义同 Crawl)、select_paths / select_domains(正则白名单)、exclude_paths / exclude_domains(正则黑名单)、allow_external
curl $TURING_BASE_URL/proxy/tavily/map \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"max_depth": 3,
"select_paths": ["/docs/.*"]
}'

响应节选:

{
"base_url": "https://example.com",
"results": [
"https://example.com/docs/quickstart",
"https://example.com/docs/api-reference"
]
}
提示

成功发现的页面数计费,不提取正文,是三者中最便宜的:(成功页面数 / 10) × (1,未设置 instructions 或 2,设置了 instructions) × $0.008

限流与错误

Extract / Crawl / Map 与 /proxy/tavily/search 共用同一套按 Key / 按团队的限流策略——超出配额或 RPM 限制的请求会在消耗 Tavily 额度之前被直接拒绝。Tavily 返回的错误会原样映射为对应的 HTTP 状态码(400/422 参数错误、401 凭证失效、408/504 超时、429 限流、5xx 上游故障),不会被统一包装成 500。

Cloudsway(搜索,中国区)

中国区的另一条搜索通道,适合你先拿网页结果,再自行做摘要、RAG、重排或喂给其他模型。

  • 端点GET /proxy/cloudsway/search
  • 必填参数q
  • 常用参数countfreshnessoffsetenableContentcontentTypecontentTimeoutmainTextsitesblockWebsites
  • 请求头:通常只需要 AuthorizationPragmaAccept 等头可按调用方需要自行决定是否传入
curl --location "$TURING_BASE_URL/proxy/cloudsway/search?q=%E6%97%A5%E6%9C%AC" \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Accept: */*"

参数说明:

  • q:搜索查询词,不能为空。
  • count:返回结果数量,默认 10,最大 50,可选值范围 1-50
  • freshness:按时间过滤结果,可选 Day / Week / Month
  • offset:分页偏移量,默认 0;设置过大时可能返回空结果。
  • enableContent:是否抓取网页长摘要;true 返回长摘要,false 不返回,默认 false
  • contentType:长摘要格式,仅在 enableContent=true 时生效,可选 HTML / MARKDOWN / TEXT,默认返回 TEXT
  • contentTimeout:长摘要读取超时,单位秒,默认 0,最大 10,仅在 enableContent=true 时生效。
  • mainText:是否返回与查询最相关的正文片段,仅在 enableContent=true 时生效。
  • sites:只保留指定站点结果,值需填写 host,例如 baijiahao.baidu.com
  • blockWebsites:过滤指定站点结果,值需填写 host,例如 baijiahao.baidu.com

响应字段与 Legacy Bing Proxy 基本一致,常见字段包括:

  • queryContext.originalQuery:原始查询词。
  • webPages.value[]:搜索结果数组。
  • webPages.value[].name / url / snippet:标题、链接、短摘要。
  • webPages.value[].datePublished:页面发布时间,部分结果包含。
  • webPages.value[].mainText:与查询最相关的正文片段。
  • webPages.value[].siteName:站点名称,部分结果包含。
  • webPages.value[].contentCrawled:长摘要是否抓取成功。
  • webPages.value[].content:网页长摘要正文。
  • webPages.value[].logo / imageList / score:站点图标、图片列表、内容相关性分数。
提示

如果你只需要标准搜索结果,通常只传 qcount 即可;只有在要做摘要增强或构造 RAG 上下文时,再打开 enableContent / mainText

备注

sitesblockWebsites 都要求填写 host,不要带协议头,例如填写 www.tiktok.com,不要写成 https://www.tiktok.com

Legacy Bing Proxy(自动路由 Baidu/Google)

历史接口。国内自动走 Baidu,国外自动走 Google。新项目建议直接调用上面对应的端点,以获得更稳定的返回结构。

  • 端点POST /proxy/bing/v7.0/search
  • 参数q(必填,查询字符串)、count(可选,默认 10,最大 25)
curl $TURING_BASE_URL/proxy/bing/v7.0/search \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"q": "明故宫",
"count": "10"
}'

响应字段:queryContext.originalQuerywebPages.value[](含 id / name / url / snippet / displayUrl / datePublished 等)、_type: "SearchResponse"

注意事项
  • API Key 妥善保管,不要在客户端代码中暴露。
  • 搜索结果的可用性和准确性取决于搜索引擎提供商。
  • 部分搜索结果包含第三方内容,使用时请注意版权。

See also