400 tools: "web_search" has no input_schema — Anthropic server-side tools cannot...

2026年08月11日 07:00 30.54 秒 success

错误信息

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服务端工具,但平台不支持此操作。

  • 具体位置:错误发生在调用Anthropic工具的API请求阶段,涉及工具配置和请求模式的兼容性问题。
  • 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. 🛡️ 预防措施


    • 最佳实践1:调用第三方工具前,严格遵循工具定义规范,完整填写input_schema(参数类型、必填项、默认值等),可通过工具文档确认参数要求。

    • 最佳实践2:使用第三方服务端工具时,优先采用非流式请求模式,查阅平台对工具类型和请求模式的兼容性说明,避免混用不支持的组合。

    • 推荐工具:使用Postman或cURL验证API请求格式,通过官方API文档核对工具参数和请求限制,确保配置正确。