web_search_20250305 服务端工具提供原生联网搜索 + 引用面板。OpenAI-Hub 完全透传 Anthropic 协议;当渠道不支持原生搜索时,会自动回退到 web_search_baidu 替代实现,对客户端完全无感。claude-sonnet-4、claude-opus-4、claude-haiku-4-5 等所有 Claude 4.x 系列。| 字段 | 类型 | 默认 | 说明 |
|---|---|---|---|
type | string | — | 固定 web_search_20250305 |
name | string | web_search | 自定义工具名(影响 SSE 块里的回显) |
max_uses | int | 5 | 单次对话最多调用搜索的次数;模型自主决策 |
allowed_domains | string[] | — | 域名白名单; 与 blocked_domains 互斥 |
blocked_domains | string[] | — | 域名黑名单 |
user_location | object | — | 地理位置提示 |
user_location.type | string | — | 固定 approximate |
user_location.country | string | — | ISO 3166-1 alpha-2 |
user_location.city | string | — | 城市英文名 |
user_location.region | string | — | 省/州英文名 |
{
"id": "msg_xxx",
"model": "claude-sonnet-4",
"type": "message",
"role": "assistant",
"content": [
{
"type": "server_tool_use",
"id": "srvtoolu_xxx",
"name": "web_search",
"input": { "query": "Buffett 2026 letter to shareholders" }
},
{
"type": "web_search_tool_result",
"tool_use_id": "srvtoolu_xxx",
"content": [
{
"type": "web_search_result",
"title": "Berkshire Hathaway 2026 Annual Letter",
"url": "https://www.berkshirehathaway.com/letters/2026.html",
"encrypted_content": "<base64...>"
}
]
},
{
"type": "text",
"text": "根据巴菲特 2026 致股东信,核心观点有三..."
}
],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 120,
"output_tokens": 380,
"server_tool_use": { "web_search_requests": 1 }
}
}event: message_start
event: content_block_start # type=server_tool_use
event: content_block_delta # input_json_delta,逐步输出 query JSON
event: content_block_stop
event: content_block_start # type=web_search_tool_result
event: content_block_stop
event: content_block_start # type=text
event: content_block_delta # text_delta 模型回答
...
event: message_delta # 含 usage.server_tool_use.web_search_requests
event: message_stopmax_uses > 1 时,模型可能:max_uses 或得到满意结果server_tool_use + web_search_tool_result 块(block index 递增)。web_search_baidu 替代实现:server_tool_use + web_search_tool_result)encrypted_content 留空字符串curl --location --request POST 'https://api.openai-hub.com/v1/messages' \
--header 'Authorization: Bearer sk-0ABIEXVjh9****Qckjy'{}