Request rejected (429) · Invalid JSON payload received. Unknown name "propertyNa...

2026年06月02日 12:09 36.93 秒 success

错误信息

API Error: Request rejected (429) · Invalid JSON payload received. Unknown name "propertyNames" at 'tools[0].function_declarations[1]..properties[0].value': Cannot find field. Invalid JSON payload received. Unknown name "propertyNames" at 'tools[0].function_declarations[1]..properties[1].value': Cannot find field. (request id: 2026060212043533245142EV2smPwO)

AI 解决方案

1. 🌐 错误翻译


原文:API Error: Request rejected (429) · Invalid JSON payload received. Unknown name “propertyNames” at ‘tools[0].function_declarations[1]..properties[0].value’: Cannot find field.
Invalid JSON payload received. Unknown name “propertyNames” at ‘tools[0].function_declarations[1]..properties[1].value’: Cannot find field.
译文:API错误:请求被拒绝(429)· 收到无效的JSON负载。在‘tools[0].function_declarations[1]..properties[0].value’位置发现未知名称 “propertyNames”:找不到该字段。
收到无效的JSON负载。在‘tools[0].function_declarations[1]..properties[1].value’位置发现未知名称 “propertyNames”:找不到该字段。

2. 🎯 原因分析


此错误由两个核心问题导致:
  • 请求频率限制 (429):您的应用在短时间内向API发送了过多请求,触发了速率限制。request id表明这是一个特定的被拒绝请求。

  • JSON格式错误:您传递的工具定义(tools)JSON结构不符合API规范。具体问题是在tools数组的第二个工具定义(function_declarations[1])中,其properties数组内的某个属性值(value)对象里,使用了一个API不识别的字段名 "propertyNames"
  • 3. 💡 解决方案


    需要修复两个问题:处理速率限制并修正JSON格式。

    第一步:处理请求 (429)
    在代码中添加重试和指数退避机制,避免短时间内重复请求。以下是伪代码示例:

    import time
    import random
    
    max_retries = 5
    for attempt in range(max_retries):
        try:
            # 调用您的API
            response = call_your_api()
            break  # 成功则跳出循环
        except TooManyRequestsError:  # 捕获429错误
            wait_time = (2 ** attempt) + random.uniform(0, 1)
            print(f"请求过于频繁,等待 {wait_time:.2f} 秒后重试...")
            time.sleep(wait_time)
    else:
        print("达到最大重试次数,请求失败。")
    

    第二步:修正工具定义JSON
    检查并修正tools中第二个函数声明的JSON。移除或更正不被支持的 “propertyNames” 字段。正确的参数结构通常如下所示:

    {
      "tools": [
        {
          "function_declarations": [
            {
              "name": "函数名1",
              "description": "函数描述",
              "parameters": {
                "type": "OBJECT",
                "properties": {
                  "param1": {"type": "STRING", "description": "参数1描述"}
                },
                "required": ["param1"]
              }
            },
            {
              "name": "函数名2", // 检查这个函数定义
              "description": "函数描述",
              "parameters": {
                "type": "OBJECT",
                "properties": {
                  "param_a": {"type": "STRING", "description": "参数A描述"},
                  "param_b": { // ✅ 正确的结构:在属性值内定义其类型和描述
                    "type": "OBJECT",
                    "description": "参数B描述",
                    "properties": { // ✅ 内部属性在这里定义,而不是用propertyNames
                      "sub_param1": {"type": "NUMBER", "description": "子参数1"}
                    }
                  }
                },
                "required": ["param_a", "param_b"]
              }
            }
          ]
        }
      ]
    }
    

    关键修复:请检查您工具定义中第二个函数的参数部分,确保没有使用 "propertyNames" 这种字段。如果意图定义一个对象参数的内部结构,应将该参数的 type 设为 "OBJECT",并在其内部使用 "properties" 字段来声明子属性。

    4. 🛡️ 预防措施


  • 集成重试逻辑:在所有外部API调用中实现带有指数退避和随机抖动的重试机制,以优雅地处理速率限制。

  • API调试与验证:在发送请求前,使用API提供方的官方调试工具、测试界面或客户端库来验证请求负载的格式。仔细阅读所用API关于 toolsfunctions 参数定义的官方文档,确保结构完全合规。