百度搜索插件 (web_search_baidu)
POST /v1/chat/completions
说明
简介
「百度搜索插件」让任何不带原生联网能力的模型(DeepSeek、GLM、通义千问、Kimi 等)也能在回答前自动检索互联网。
用法:在请求 tools[] 中传入 { "type": "web_search_baidu" } 即可。
请求示例
1. Chat Completions(任意模型可用)
curl https://api.openai-hub.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v3.1",
"stream": true,
"messages": [
{ "role": "user", "content": "今天 OpenAI 发布了什么新模型?" }
],
"tools": [
{ "type": "web_search_baidu", "name": "web_search" }
]
}'
2. Anthropic Messages 协议
curl https://api.openai-hub.com/v1/messages \
-H "x-api-key: $API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v3.1",
"stream": true,
"max_tokens": 1024,
"messages": [
{ "role": "user", "content": "今天 OpenAI 发布了什么新模型?" }
],
"tools": [
{ "type": "web_search_baidu", "name": "web_search" }
]
}'
3. OpenAI Responses 协议
curl https://api.openai-hub.com/v1/responses \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v3.1",
"stream": true,
"input": "今天 OpenAI 发布了什么新模型?",
"tools": [
{ "type": "web_search_baidu", "name": "web_search" }
]
}'
tools 字段
| 字段 | 必填 | 说明 |
|---|---|---|
type |
✅ | 固定 web_search_baidu |
name |
⛔ | 任意名称,建议 web_search |
计费
- 搜索成功扣一次「工具价格」中
web_search_baidu的单价 - 搜索失败 / 超时 / 0 结果 → 不计费,继续调用上游模型
- 多查询并行只按 1 次计费
常见问题
- 如果模型已经原生支持联网(如 Claude
web_search_20250305、GPT 系列web_search_preview)→ 自动走原生,不会重复触发百度搜索 - 要不要给模型显式提示「请联网查询」? → 不需要,传了
web_search_baidu就会自动检索 - 结果引用如何展示? → 三种协议返回的引用结构不同,可参考客户端实现或直接渲染
title/url
请求头
| 名称 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
| Authorization | header | string | 否 |
响应
| 字段 | 类型 | 必填 | 说明 |
|---|