You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用Azure OpenAI添加数据API遇400错误:请求体JSON无效求助

问题排查与解决

直接原因:JSON语法错误(末尾多余逗号)

你的请求JSON中,messages字段结尾处多了一个不必要的逗号,这违反了JSON语法规则——JSON不允许对象最后一个键值对或数组最后一个元素后保留尾随逗号(trailing comma),这正是导致Invalid JSON in request body错误的核心原因。

错误位置示例:

"messages": [{"role":"system","content":"You are an AI assistant that helps people find information."}],
// ↑ 此处逗号需删除

修正后的请求体

删除该多余逗号后,JSON格式即可正确解析。修正后的请求体部分代码如下:

{
  "dataSources": [
    {
      "type": "AzureCognitiveSearch",
      "parameters": {
        "endpoint": "'$search_endpoint'",
        "key": "'$search_key'",
        "indexName": "'$search_index'"
      }
    }
  ],
  "messages": [{"role":"system","content":"You are an AI assistant that helps people find information."}]
}

额外验证点

  • 确认所有shell变量(如$search_endpoint、$search_key)的值不包含未转义的双引号、反斜杠等JSON特殊字符,这类字符会破坏JSON结构。当前你的变量值为URL和密钥,通常不会存在此类问题,但如果后续仍出现解析错误可优先排查此点。

内容的提问来源于stack exchange,提问作者k-o-i

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 01:45:02