联网搜索
使用 Anthropic 的 web_search 服务端工具让 Claude 在服务端进行联网搜索。
联网搜索不是一个单独的接口。而是在常规的 POST /v1/messages 请求中加入
Anthropic 的 web_search 服务端工具。模型会在服务端执行搜索,并在响应中引用结果。仅支持 Claude 模型。
示例
curl https://api.tokapi.ai/v1/messages \
-H "Authorization: Bearer sk-lazytech-..." \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"messages": [{ "role": "user", "content": "Node.js 最新的 LTS 版本是多少?" }],
"tools": [{ "type": "web_search_20250305", "name": "web_search", "max_uses": 5 }]
}'说明
- 每次搜索都计为一次服务端工具使用,与其他用量一样计量。
- 仅 Claude 模型支持
web_search服务端工具。 - 响应的
usage对象中会包含server_tool_use条目,便于你查看执行了多少次搜索。
查看用量请参阅用量 API。