CC Switch local proxy failed while handling Codex endpoint /responses. Provider:...

2026年08月22日 15:06 48.18 秒 success

错误信息

CC Switch local proxy failed while handling Codex endpoint /responses. Provider: DMXAPI; model: gpt-5.6-terra; upstream_status: HTTP 400; cause: Invalid 'input[37].content': array too long. Expected an array with maximum length 0, but got an array with length 1 instead.

AI 解决方案

🔍 报错分析

1. 🌐 错误翻译


原文:CC Switch local proxy failed while handling Codex endpoint /responses. Provider: DMXAPI; model: gpt-5.6-terra; upstream_status: HTTP 400; cause: Invalid 'input[37].content': array too long. Expected an array with maximum length 0, but got an array with length 1 instead.
译文:在处理Codex端点/responses时,CC Switch本地代理失败。提供商:DMXAPI;模型:gpt-5.6-terra;上游状态:HTTP 400;原因:无效的'input[37].content':数组过长。预期最大长度为0的数组,但得到的数组长度为1。

2. 🎯 原因分析


该错误的核心原因是向模型API发送的请求参数不符合要求:
  • 问题定位:请求中的 input[37].content 字段

  • 根本原因:该字段预期为长度0的数组(即空数组或不允许有元素),但实际传入了长度为1的数组,存在不符合API要求的额外数据

  • 错误类型:参数校验失败,上游服务(模型API)拒绝了不符合规范的请求
  • 3. 💡 解决方案


    需检查请求构造代码,定位input数组中索引为37的元素,移除其content字段中的非空数据,确保该字段符合长度要求。以下是修复示例:
    // 假设原请求参数构造代码(存在问题)
    const originalInput = /* 包含input[37].content为长度1数组的完整输入 */;
    
    // 修复后的请求参数构造代码
    const fixedInput = originalInput.map((item, index) => {
      // 仅处理索引为37的元素,确保其content为长度0的数组
      if (index === 37) {
        return {
          ...item,
          // 强制设置为空数组,满足最大长度0的要求
          content: []
        };
      }
      return item;
    });
    
    // 使用修复后的fixedInput构造请求体
    const response = await fetch('/responses', {
      method: 'POST',
      body: JSON.stringify({ input: fixedInput }),
      headers: { 'Content-Type': 'application/json' }
    });
    

    4. 🛡️ 预防措施


  • 参数校验前置:在发送请求前,对核心参数(尤其是涉及数组长度、格式要求的部分)进行校验,例如添加条件判断,确保关键数组长度符合API预期(如最大长度0时,必须为空数组)。

  • 借助工具校验:使用TypeScript定义请求参数的类型和长度约束,或在开发阶段用工具(如Postman、API测试脚本)提前模拟请求,验证参数合法性,提前暴露不符合要求的数据。