错误信息: The role only supports :`user`、`assistant` - `messages.[0]` 堆栈信息: AI_APICa...
错误信息
错误名称: AI_APICallError
错误信息: The role only supports :`user`、`assistant` - `messages.[0]`
堆栈信息: AI_APICallError: The role only supports :`user`、`assistant` - `messages.[0]`
at file:///D:/Program%20Files/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-D-J5UN_L.js:52075:11
at async postToApi$2 (file:///D:/Program%20Files/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-D-J5UN_L.js:51970:24)
at async OpenAICompatibleChatLanguageModel.doStream (file:///D:/Program%20Files/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-D-J5UN_L.js:69970:48)
at async wrapStream (file:///D:/Program%20Files/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-D-J5UN_L.js:105780:32)
at async fn (file:///D:/Program%20Files/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-D-J5UN_L.js:104430:17)
at async file:///D:/Program%20Files/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-D-J5UN_L.js:100701:19
at async _retryWithExponentialBackoff (file:///D:/Program%20Files/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-D-J5UN_L.js:100891:10)
at async streamStep (file:///D:/Program%20Files/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-D-J5UN_L.js:104399:109)
at async fn (file:///D:/Program%20Files/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-D-J5UN_L.js:104716:5)
at async file:///D:/Program%20Files/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-D-J5UN_L.js:100701:19
错误原因: "[undefined]"
状态码: 400
请求路径: https://www.dmxapi.cn/v1/chat/completions
请求体: {
"model": "Baichuan-M3-Plus",
"user": "[undefined]",
"max_tokens": "[undefined]",
"temperature": "[undefined]",
"top_p": "[undefined]",
"frequency_penalty": "[undefined]",
"presence_penalty": "[undefined]",
"response_format": "[undefined]",
"stop": "[undefined]",
"seed": "[undefined]",
"serviceTier": "[undefined]",
"reasoning_effort": "[undefined]",
"verbosity": "[undefined]",
"messages": [
{
"role": "system",
"content": "In this environment you have access to a set of tools you can use to answer the user's question. You can use one or more tools per message, and will receive the result of that tool use in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.\n\n## Tool Use Formatting\n\nTool use is formatted using XML-style tags. The tool name is enclosed in opening and closing tags, and each parameter is similarly enclosed within its own set of tags. Here's the structure:\n\n<tool_use>\n <name>{tool_name}</name>\n <arguments>{json_arguments}</arguments>\n</tool_use>\n\nThe tool name should be the exact name of the tool you are using, and the arguments should be a JSON object containing the parameters required by that tool. IMPORTANT: When writing JSON inside the <arguments> tag, any double quotes inside string values must be escaped with a backslash (\"). For example:\n<tool_use>\n <name>search</name>\n <arguments>{ \"query\": \"browser,fetch\" }</arguments>\n</tool_use>\n\n<tool_use>\n <name>exec</name>\n <arguments>{ \"code\": \"const page = await CherryBrowser_fetch({ url: \\\"https://example.com\\\" })\nreturn page\" }</arguments>\n</tool_use>\n\n\nThe user will respond with the result of the tool use, which should be formatted as follows:\n\n<tool_use_result>\n <name>{tool_name}</name>\n <result>{result}</result>\n</tool_use_result>\n\nThe result should be a string, which can represent a file or any other output type. You can use this result as input for the next action.\nFor example, if the result of the tool use is an image file, you can use it in the next action like this:\n\n<tool_use>\n <name>image_transformer</name>\n <arguments>{\"image\": \"image_1.jpg\"}</arguments>\n</tool_use>\n\nAlways adhere to this format for the tool use to ensure proper parsing and execution.\n\n## Tool Use Rules\nHere are the rules you should always follow to solve your task:\n1. Always use the right arguments for the tools. Never use variable names as the action arguments, use the value instead.\n2. Call a tool only when needed: do not call the search agent if you do not need information, try to solve the task yourself.\n3. If no tool call is needed, just answer the question directly.\n4. Never re-do a tool call that you previously did with the exact same parameters.\n5. For tool use, MAKE SURE use XML tag format as shown in the examples above. Do not use any other format.\n\n\n## Tool Use Examples\n\nHere are a few examples using notional tools:\n---\nUser: Generate an image of the oldest person in this document.\n\nA: I can use the document_qa tool to find out who the oldest person is in the document.\n<tool_use>\n <name>document_qa</name>\n <arguments>{\"document\": \"document.pdf\", \"question\": \"Who is the oldest person mentioned?\"}</arguments>\n</tool_use>\n\nUser: <tool_use_result>\n <name>document_qa</name>\n <result>John Doe, a 55 year old lumberjack living in Newfoundland.</result>\n</tool_use_result>\n\nA: I can use the image_generator tool to create a portrait of John Doe.\n<tool_use>\n <name>image_generator</name>\n <arguments>{\"prompt\": \"A portrait of John Doe, a 55-year-old man living in Canada.\"}</arguments>\n</tool_use>\n\nUser: <tool_use_result>\n <name>image_generator</name>\n <result>image.png</result>\n</tool_use_result>\n\nA: the image is generated as image.png\n\n---\nUser: \"What is the result of the following operation: 5 + 3 + 1294.678?\"\n\nA: I can use the python_interpreter tool to calculate the result of the operation.\n<tool_use>\n <name>python_interpreter</name>\n <arguments>{\"code\": \"5 + 3 + 1294.678\"}</arguments>\n</tool_use>\n\nUser: <tool_use_result>\n <name>python_interpreter</name>\n <result>1302.678</result>\n</tool_use_result>\n\nA: The result of the operation is 1302.678.\n\n---\nUser: \"Which city has the highest population , Guangzhou or Shanghai?\"\n\nA: I can use the search tool to find the population of Guangzhou.\n<tool_use>\n <name>search</name>\n <arguments>{\"query\": \"Population Guangzhou\"}</arguments>\n</tool_use>\n\nUser: <tool_use_result>\n <name>search</name>\n <result>Guangzhou has a population of 15 million inhabitants as of 2021.</result>\n</tool_use_result>\n\nA: I can use the search tool to find the population of Shanghai.\n<tool_use>\n <name>search</name>\n <arguments>{\"query\": \"Population Shanghai\"}</arguments>\n</tool_use>\n\nUser: <tool_use_result>\n <name>search</name>\n <result>26 million (2019)</result>\n</tool_use_result>\n\nA: The population of Shanghai is 26 million, while Guangzhou has a population of 15 million. Therefore, Shanghai has the highest population.\n\n## Tool Use Available Tools\nAbove example were using notional tools that might not exist for you. You only have access to these tools:\n<tools>\n\n<tool>\n <name>builtin_web_search</name>\n <description>Web search tool for finding current information, news, and real-time data from the internet.\n\nThis tool has been configured with search parameters based on the conversation context:\n- Prepared queries: \"咳嗽是怎么回事?\n\"\n\nYou can use this tool as-is to search with the prepared queries, or provide additionalContext to refine or replace the search terms.</description>\n <arguments>\n {\"def\":{\"type\":\"object\",\"shape\":{\"additionalContext\":{\"def\":{\"type\":\"optional\",\"innerType\":{\"def\":{\"type\":\"string\"},\"type\":\"string\",\"format\":null,\"minLength\":null,\"maxLength\":null}},\"type\":\"optional\"}}},\"type\":\"object\"}\n </arguments>\n</tool>\n\n</tools>\n\n## Response rules\n\nRespond in the language of the user's query, unless the user instructions specify additional requirements for the language to be used.\n\n# User Instructions\n\n"
},
{
"role": "user",
"content": "咳嗽是怎么回事?"
}
],
"tools": "[undefined]",
"tool_choice": "[undefined]",
"stream": true,
"stream_options": "[undefined]"
}
响应首部: {
"cache-control": "no-cache",
"content-type": "text/event-stream",
"date": "Tue, 07 Jul 2026 21:40:55 GMT",
"document-policy": "include-js-call-stacks-in-crash-reports",
"server": "nginx",
"x-dmx-api-version": "v2.3.2",
"x-oneapi-request-id": "20260707214055814009498c14228f5DZEjeO6T"
}
响应内容: {
"error": {
"message": "The role only supports :`user`、`assistant` - `messages.[0]`",
"type": "invalid_request_error",
"param": "",
"code": null
}
}
数据: {
"error": {
"message": "The role only supports :`user`、`assistant` - `messages.[0]`",
"type": "invalid_request_error",
"param": "",
"code": null
}
}
AI 解决方案
1. 🌐 错误翻译
原文:The role only supports :`user`、`assistant` - `messages.[0]`
译文:角色仅支持:`user`、`assistant` - `messages.[0]`
2. 🎯 原因分析
根本原因:API 接口要求 messages 数组中的消息角色只能是 user 或 assistant,但请求中第一条消息使用了 system 角色,导致验证失败。
错误位置:messages.[0].role = "system",位于请求体 messages 数组的第一项。
3. 💡 解决方案
方法一:移除 system 角色,改为 user 角色
如果不需要 system 角色,直接将第一条消息的 role 改为 "user":
{
"model": "Baichuan-M3-Plus",
"messages": [
{
"role": "user",
"content": "In this environment you have access to a set of tools you can use to answer the user's question..."
},
{
"role": "user",
"content": "咳嗽是怎么回事?"
}
]
}
方法二:将系统指令合并到第一条 user 消息中
如果必须保留系统指令,将其合并到第一条 user 消息内容中:
{
"model": "Baichuan-M3-Plus",
"messages": [
{
"role": "user",
"content": "System instructions: In this environment you have access to a set of tools you can use to answer the user's question. Tool use formatting rules: ...\n\nUser question: 咳嗽是怎么回事?"
}
]
}
方法三:确认API是否支持 system 角色
若API文档说明支持 system 角色,可能是模型不兼容,需更换支持 system 角色的模型,或联系API提供方确认模型兼容性。
4. 🛡️ 预防措施
- 查阅API文档:调用任何API前,先确认其支持的消息角色类型(如 system、user、assistant、function 等),严格按文档规范构造请求体。
- 参数校验工具:使用 Postman、Insomnia 等API调试工具,提前校验请求参数格式,或在代码中添加请求参数格式校验逻辑,避免因格式错误导致请求失败。