错误信息: The `messages.[1]` message role is repeated 堆栈信息: AI_APICallError: The `me...

2026年03月23日 11:43 状态: processing

🚨 错误信息

错误名称: AI_APICallError 错误信息: The `messages.[1]` message role is repeated 堆栈信息: AI_APICallError: The `messages.[1]` message role is repeated at file:///Applications/Cherry%20Studio.app/Contents/Resources/app.asar/out/renderer/assets/dist-CUjkTMRK.js:2082:11 at async postToApi (file:///Applications/Cherry%20Studio.app/Contents/Resources/app.asar/out/renderer/assets/dist-CUjkTMRK.js:1977:24) at async OpenAICompatibleChatLanguageModel.doStream (file:///Applications/Cherry%20Studio.app/Contents/Resources/app.asar/out/renderer/assets/dist-BTy3HrgJ.js:451:48) at async wrapStream (file:///Applications/Cherry%20Studio.app/Contents/Resources/app.asar/out/renderer/assets/store-BDFHZEb3.js:48614:32) at async fn (file:///Applications/Cherry%20Studio.app/Contents/Resources/app.asar/out/renderer/assets/store-BDFHZEb3.js:47480:17) at async file:///Applications/Cherry%20Studio.app/Contents/Resources/app.asar/out/renderer/assets/store-BDFHZEb3.js:43834:19 at async _retryWithExponentialBackoff (file:///Applications/Cherry%20Studio.app/Contents/Resources/app.asar/out/renderer/assets/store-BDFHZEb3.js:43997:10) at async streamStep (file:///Applications/Cherry%20Studio.app/Contents/Resources/app.asar/out/renderer/assets/store-BDFHZEb3.js:47449:109) at async fn (file:///Applications/Cherry%20Studio.app/Contents/Resources/app.asar/out/renderer/assets/store-BDFHZEb3.js:47755:5) at async file:///Applications/Cherry%20Studio.app/Contents/Resources/app.asar/out/renderer/assets/store-BDFHZEb3.js:43834:19 错误原因: "[undefined]" 状态码: 400 请求路径: https://www.dmxapi.cn/v1/chat/completions 请求体: { "model": "Baichuan-M3-Plus", "user": "[undefined]", "max_tokens": "[undefined]", "temperature": 1, "top_p": 1, "frequency_penalty": "[undefined]", "presence_penalty": "[undefined]", "response_format": "[undefined]", "stop": "[undefined]", "seed": "[undefined]", "serviceTier": "[undefined]", "reasoning_effort": "[undefined]", "verbosity": "[undefined]", "messages": [ { "role": "user", "content": "你是谁" }, { "role": "user", "content": "你是谁" } ], "tools": "[undefined]", "tool_choice": "[undefined]", "stream": true, "stream_options": { "include_usage": true } } 响应首部: { "cache-control": "no-cache", "content-type": "text/event-stream", "date": "Mon, 23 Mar 2026 01:32:21 GMT", "document-policy": "include-js-call-stacks-in-crash-reports", "server": "nginx", "x-rixapi-request-id": "20260323093220202196687pXdtLfhB" } 响应内容: { "error": { "message": "The `messages.[1]` message role is repeated", "type": "rix_api_error", "param": "messages.[1].role", "code": null } } 数据: { "error": { "message": "The `messages.[1]` message role is repeated", "type": "rix_api_error", "param": "messages.[1].role", "code": null } }

🤖 AI解决方案

报错分析报告

1.错误翻译


``
原文:The
messages.[1] message role is repeated
译文:
messages数组的第1个元素(索引为1)的消息角色重复了
`

2. 原因分析


  • 根本原因:请求体中messages数组的第2条消息(索引1)与第1条消息的role均为user,违反API对消息角色唯一性的要求。

  • 具体位置:请求体messages字段([{"role":"user",...}, {"role":"user",...}]),两条连续消息的role重复。
  • 3.解决方案


    修正
    messages数组,确保角色不重复(以单条用户消息为例):
    json
    {
    "model": "Baichuan-M3-Plus",
    "messages": [
    {
    "role": "user",
    "content": "你是谁"
    }
    ],
    "stream": true,
    "stream_options": {
    "include_usage": true
    },
    "temperature": 1,
    "top_p": 1
    }

    > 注:移除请求体中
    [undefined]的无效字段,避免额外错误。

    4. 预防措施


  • ✅ 发送请求前,校验messages数组内相邻消息的role,确保无重复(如user后接assistant`)。

  • ✅ 使用API调试工具(如Postman、Apifox)预验证请求体格式,或用JSON Schema自动校验。
  • ---
    以上分析基于您提供的报错信息,聚焦代码/请求的错误修复。