] API错误 (400 ): { "error": { "message": "{\n \"error\": {\n \"code\": 400,\n \"m...
🚨 错误信息
[2025-12-24T07:21:53.925Z] [INFO] 开始发送请求到LLM API: https://api.yuegle.com/v1/chat/completions
[2025-12-24T07:21:54.874Z] [ERROR] API错误 (400 ):
{
"error": {
"message": "{\n \"error\": {\n \"code\": 400,\n \"message\": \"Request contains an invalid argument.\",\n \"errors\": [\n {\n \"message\": \"Request contains an invalid argument.\",\n \"domain\": \"global\",\n \"reason\": \"badRequest\"\n }\n ],\n \"status\": \"INVALID_ARGUMENT\"\n }\n}\n(traceid: 8f6731ebca1584180c9a67539afba1b7) (request id: )",
"type": "invalid_request_error",
"param": "",
"code": null
}
}
[2025-12-24T07:21:54.875Z] [ERROR] LLM处理错误: API错误: 400
详细信息: {
"error": {
"message": "{\n \"error\": {\n \"code\": 400,\n \"message\": \"Request contains an invalid argument.\",\n \"errors\": [\n {\n \"message\": \"Request contains an invalid argument.\",\n \"domain\": \"global\",\n \"reason\": \"badRequest\"\n }\n ],\n \"status\": \"INVALID_ARGUMENT\"\n }\n}\n(traceid: 8f6731ebca1584180c9a67539afba1b7) (request id: )",
"type": "invalid_request_error",
"param": "",
"code": null
}
}
[2025-12-24T07:21:54.876Z] [ERROR] 错误堆栈: Error: API错误: 400
详细信息: {
"error": {
"message": "{\n \"error\": {\n \"code\": 400,\n \"message\": \"Request contains an invalid argument.\",\n \"errors\": [\n {\n \"message\": \"Request contains an invalid argument.\",\n \"domain\": \"global\",\n \"reason\": \"badRequest\"\n }\n ],\n \"status\": \"INVALID_ARGUMENT\"\n }\n}\n(traceid: 8f6731ebca1584180c9a67539afba1b7) (request id: )",
"type": "invalid_request_error",
"param": "",
"code": null
}
}
at voiceChat.sendToLLM (file:///E:/friend/my-neuro_20250930_195805/my-neuro-bundle-V5.4.6/live-2d/app.js:1573:39)
at async ASRProcessor.onSpeechRecognized (E:\friend\my-neuro_20250930_195805\my-neuro-bundle-V5.4.6\live-2d\js\voice-chat.js:54:25)
[2025-12-24T07:21:54.876Z] [ERROR] 用户显示错误: 未知错误: API错误: 400
详细信息: {
"error": {
"message": "{\n \"error\": {\n \"code\": 400,\n \"messag...
[2025-12-24T07:21:54.874Z] [ERROR] API错误 (400 ):
{
"error": {
"message": "{\n \"error\": {\n \"code\": 400,\n \"message\": \"Request contains an invalid argument.\",\n \"errors\": [\n {\n \"message\": \"Request contains an invalid argument.\",\n \"domain\": \"global\",\n \"reason\": \"badRequest\"\n }\n ],\n \"status\": \"INVALID_ARGUMENT\"\n }\n}\n(traceid: 8f6731ebca1584180c9a67539afba1b7) (request id: )",
"type": "invalid_request_error",
"param": "",
"code": null
}
}
[2025-12-24T07:21:54.875Z] [ERROR] LLM处理错误: API错误: 400
详细信息: {
"error": {
"message": "{\n \"error\": {\n \"code\": 400,\n \"message\": \"Request contains an invalid argument.\",\n \"errors\": [\n {\n \"message\": \"Request contains an invalid argument.\",\n \"domain\": \"global\",\n \"reason\": \"badRequest\"\n }\n ],\n \"status\": \"INVALID_ARGUMENT\"\n }\n}\n(traceid: 8f6731ebca1584180c9a67539afba1b7) (request id: )",
"type": "invalid_request_error",
"param": "",
"code": null
}
}
[2025-12-24T07:21:54.876Z] [ERROR] 错误堆栈: Error: API错误: 400
详细信息: {
"error": {
"message": "{\n \"error\": {\n \"code\": 400,\n \"message\": \"Request contains an invalid argument.\",\n \"errors\": [\n {\n \"message\": \"Request contains an invalid argument.\",\n \"domain\": \"global\",\n \"reason\": \"badRequest\"\n }\n ],\n \"status\": \"INVALID_ARGUMENT\"\n }\n}\n(traceid: 8f6731ebca1584180c9a67539afba1b7) (request id: )",
"type": "invalid_request_error",
"param": "",
"code": null
}
}
at voiceChat.sendToLLM (file:///E:/friend/my-neuro_20250930_195805/my-neuro-bundle-V5.4.6/live-2d/app.js:1573:39)
at async ASRProcessor.onSpeechRecognized (E:\friend\my-neuro_20250930_195805\my-neuro-bundle-V5.4.6\live-2d\js\voice-chat.js:54:25)
[2025-12-24T07:21:54.876Z] [ERROR] 用户显示错误: 未知错误: API错误: 400
详细信息: {
"error": {
"message": "{\n \"error\": {\n \"code\": 400,\n \"messag...
🤖 AI解决方案
错误分析报告
1. 错误翻译
原文:Request contains an invalid argument.
译文:请求包含无效参数。
2. 原因分析
核心问题:发送给 LLM API(https://api.yuegle.com/v1/chat/completions)的请求中包含一个或多个无效参数。
具体分析:
- 错误位置:
voiceChat.sendToLLM(app.js:1573:39)→ASRProcessor.onSpeechRecognized(voice-chat.js:54:25) - HTTP状态码:400 Bad Request
- ️ 错误类型:
INVALID_ARGUMENT(无效参数) - 追踪ID:
8f6731ebca1584180c9a67539afba1b7 - 请求体格式错误:JSON结构不符合API规范
- 缺少必需参数:如缺少
model、messages等必填字段 - 参数值类型错误:例如
temperature不是数字类型 - ⚡ 参数值超出范围:某些参数值不在允许范围内
可能的具体原因:
3. 解决方案
检查并修复API请求配置:
// 示例:检查并修复sendToLLM函数中的请求配置
async function sendToLLM(userMessage) {
const apiUrl = 'https://api.yuegle.com/v1/chat/completions';
// 确保请求体符合API规范
const requestBody = {
model: "gpt-3.5-turbo", // 明确指定模型
messages: [
{
role: "user",
content: userMessage
}
],
temperature: 0.7, // 确保是数字类型
max_tokens: 1000,
// 添加其他必需参数(参考API文档)
};
try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY' // 确保API密钥正确
},
body: JSON.stringify(requestBody)
});
if (!response.ok) {
// 打印详细错误信息
const errorData = await response.json();
console.error('API错误详情:', errorData);
throw new Error(`API错误: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error('发送请求失败:', error);
throw error;
}
}
调试步骤:
api.yuegle.com的API接口规范model、messages等字段存在且格式正确4. ️ 预防措施
最佳实践建议:
function validateRequestBody(body) {
const requiredFields = ['model', 'messages'];
const missingFields = requiredFields.filter(field => !body[field]);
if (missingFields.length > 0) {
throw new Error(`缺少必需字段: ${missingFields.join(', ')}`);
}
// 验证messages格式
if (!Array.isArray(body.messages)) {
throw new Error('messages必须是数组');
}
}
推荐工具:
---
建议:首先检查voice-chat.js第54行和app.js第1573行附近的代码,确认发送给API的请求体格式是否正确,特别是model和messages参数。