400 tools: "web_search" has no input_schema — Anthropic server-side tools cannot...
错误信息
API Error: 400 tools: "web_search" has no input_schema — Anthropic server-side tools cannot be proxied on a streaming request
AI 解决方案
🔍 报错分析
1. 🌐 错误翻译
原文:API Error: 400 tools: "web_search" has no input_schema — Anthropic server-side tools cannot be proxied on a streaming request
译文:API错误:400 tools:"web_search"没有input_schema——Anthropic服务端工具无法在流式请求中被代理
2. 🎯 原因分析
web_search工具缺少必需的input_schema参数定义,同时尝试在流式请求中使用Anthropic服务端工具,但平台不支持此操作。3. 💡 解决方案
1. 为
web_search工具添加完整的input_schema参数定义,包括参数类型和必填项。2. 将流式请求改为非流式请求,避免使用不被支持的流式模式代理Anthropic服务端工具。
- 示例代码(Python):
# 错误代码(流式请求 + 缺少input_schema)
# tools = [{"name": "web_search"}] # 缺少input_schema
# response = client.messages.create(
# model="claude-3-sonnet",
# messages=messages,
# tools=tools,
# stream=True # 流式请求不支持Anthropic服务端工具代理
# )
# 修复后的代码(非流式请求 + 补充input_schema)
tools = [{
"name": "web_search",
"input_schema": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "搜索关键词"
},
"max_results": {
"type": "integer",
"description": "最大结果数量,默认10",
"default": 10
}
},
"required": ["query"]
}
}]
response = client.messages.create(
model="claude-3-sonnet",
messages=messages,
tools=tools,
stream=False # 改为非流式请求
)
4. 🛡️ 预防措施
input_schema(参数类型、必填项、默认值等),可通过工具文档确认参数要求。