":{"message":"\u003c400\u003e InternalError.Algo.InvalidParameter: The \"functio...

2026年10月12日 16:55 10.86 秒 success

错误信息

"error":{"message":"\u003c400\u003e InternalError.Algo.InvalidParameter: The \"function.arguments\" parameter of the code model must be in JSON format.","type":"invalid_request_error","param":"","code":"invalid_parameter_error"

AI 解决方案

原文:<400> InternalError.Algo.InvalidParameter: The "function.arguments" parameter of the code model must be in JSON format.
译文:<400> 内部错误.算法.无效参数:代码模型的"function.arguments"参数必须是JSON格式。

🎯 原因分析


该错误的核心原因是function.arguments参数被传递了不符合JSON格式的字符串。通常发生在调用函数时,未将参数严格序列化为合法的JSON对象/字符串,或结构不符合模型本身的预期。常见场景包括:传入了普通的字符串而非JSON,或者JSON结构不完整。

💡 解决方案


确保function.arguments是有效的JSON字符串。JSON格式要求双引号、无尾部逗号、数字不加引号等基础规范。

// 修复前 - 常见的错误写法(arguments 不是有效 JSON)
const functionArguments = '{"name": "test", "id": "1"}';  // 如果未转义或格式错误,可能报错

// 修复后 - 确保为合法 JSON 格式
// 方案一:直接传递合法的 JSON 字符串
const functionArguments = '{"name": "张三", "id": 1}';

// 方案二:先构造对象,再用 JSON.stringify 序列化(避免手动拼写错误)
const params = { name: "张三", id: 1 };
const functionArguments = JSON.stringify(params);

// 调用模型时使用
apiRequest({
  model: "your-model",
  functions: [{
    name: "queryUser",
    arguments: functionArguments  // 确保此处传递的是 JSON 字符串
  }]
});

🛡️ 预防措施


  • 🛠️ 使用工具校验:调用前通过JSON.parse(arguments)验证参数是否为合法JSON,解析失败则抛出明确错误,避免传递不规范数据。

  • 🧠 统一参数构造方式:尽量使用JSON.stringify()从对象生成JSON字符串,避免手动拼接,减少格式错误风险。