] API错误 (400 ): { "error": { "message": "{\n \"error\": {\n \"code\": 400,\n \"m...

2025年12月24日 15:22 状态: processing

🚨 错误信息

[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.sendToLLMapp.js:1573:39)→ ASRProcessor.onSpeechRecognizedvoice-chat.js:54:25

  • HTTP状态码:400 Bad Request

  • 错误类型INVALID_ARGUMENT(无效参数)

  • 追踪ID8f6731ebca1584180c9a67539afba1b7
  • 可能的具体原因

  • 请求体格式错误:JSON结构不符合API规范

  • 缺少必需参数:如缺少modelmessages等必填字段

  • 参数值类型错误:例如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文档:确认api.yuegle.com的API接口规范

  • 使用调试工具:先用Postman或curl测试请求

  • 验证JSON结构:确保请求体是完全有效的JSON

  • 检查必填字段:确认modelmessages等字段存在且格式正确
  • 4. ️ 预防措施

    最佳实践建议

  • API请求验证:在发送请求前,创建验证函数检查参数有效性


  •    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必须是数组');
         }
       }
       

  • 使用API客户端库:考虑使用官方SDK或成熟的HTTP客户端库,它们通常包含参数验证和错误处理机制

  • 记录详细日志:在开发环境中记录完整的请求体和响应,便于调试
  • 推荐工具

  • Postman/Insomnia:用于API测试和调试

  • JSONLint:验证JSON格式正确性

  • 浏览器开发者工具:查看网络请求详情

---
建议:首先检查voice-chat.js第54行和app.js第1573行附近的代码,确认发送给API的请求体格式是否正确,特别是modelmessages参数。