","param":"","code":400}

2026年09月20日 19:12 14.45 秒 success

错误信息

400: {"message":"* ***.tools[0].function_declarations[8].parameters.any_of[0].required: only allowed for OBJECT type\n* ***.tools[0].function_declarations[8].parameters.any_of[0].required[0]: property is not defined\n* ***.tools[0].function_declarations[8].parameters.any_of[1].required: only allowed for OBJECT type\n* ***.tools[0].function_declarations[8].parameters.any_of[1].required[0]: property is not defined\n* ***.tools[0].function_declarations[8].parameters.any_of[1].required[1]: property is not defined\n* ***.tools[0].function_declarations[8].parameters.any_of[2].required: only allowed for OBJECT type\n* ***.tools[0].function_declarations[8].parameters.any_of[2].required[0]: property is not defined\n* ***.tools[0].function_declarations[8].parameters.any_of[2].required[1]: property is not defined\n* ***.tools[0].function_declarations[8].parameters.any_of[2].required[2]: property is not defined\n","type":"upstream_error","param":"","code":400}

AI 解决方案

原文:* ***.tools[0].function_declarations[8].parameters.any_of[0].required: only allowed for OBJECT type
译文:* ***.tools[0].function_declarations[8].parameters.any_of[0].required:仅允许用于 OBJECT 类型

🎯 原因分析


该错误发生在工具函数的参数定义中,具体是第8个函数声明(index为8)的参数配置。核心问题是:
  • required属性使用错误:required字段只能在type为OBJECT的参数定义中使用

  • 结构不匹配:在any_of(多选一结构)的非对象类型参数节点上错误地声明了required属性

  • 属性缺失:部分required数组中引用的属性在对应类型中未定义
  • 💡 解决方案


    以OpenAI函数定义规范为例,修正参数结构:

    // 修复前(错误示例)
    {
      "type": "function",
      "function": {
        "name": "example_func",
        "parameters": {
          "any_of": [
            {
              "type": "string",
              "required": ["prop1"] // ❌ 错误:非OBJECT类型不能有required
            },
            {
              "type": "object",
              "required": ["prop1", "prop2"], // ✅ 正确:OBJECT类型可包含required
              "properties": {
                "prop1": {"type": "string"},
                "prop2": {"type": "integer"}
              }
            }
          ]
        }
      }
    }
    
    // 修复后(正确示例)
    {
      "type": "function",
      "function": {
        "name": "example_func",
        "parameters": {
          "any_of": [
            {
              "type": "string",
              "description": "简单字符串参数"
            },
            {
              "type": "object",
              "required": ["prop1", "prop2"],
              "properties": {
                "prop1": {"type": "string"},
                "prop2": {"type": "integer"}
              }
            }
          ]
        }
      }
    }
    

    🛡️ 预防措施


  • 参数校验:使用JSON Schema验证工具,在提交前自动检查required属性是否符合类型规范

  • 规范文档:严格遵循OpenAI/Anthropic等模型的工具函数定义规范,确保OBJECT类型参数才声明required