","param":"","code":""} INVALID_REQUEST

2026年08月17日 16:59 16.35 秒 success

错误信息

本轮运行失败404: {"message":"Invalid URL (POST /v1/chat/completions/chat/completions)","type":"invalid_request_error","param":"","code":""} INVALID_REQUEST

AI 解决方案

🔍 报错分析

1. 🌐 错误翻译


原文:Invalid URL (POST /v1/chat/completions/chat/completions)
译文:无效的URL (POST /v1/chat/completions/chat/completions)

2. 🎯 原因分析


根本原因:API请求URL路径重复拼接,导致路径格式错误。

具体位置:请求的完整路径为 /v1/chat/completions/chat/completions,其中 /chat/completions 被重复添加,违反了API接口的标准路径格式。

3. 💡 解决方案


检查并修正代码中的API请求URL,确保路径正确。以下是修复后的示例代码:

// 错误示例(重复路径)
const response = await fetch('https://api.example.com/v1/chat/completions/chat/completions', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ /* 请求参数 */ })
});

// 修复后的代码(正确的URL路径)
const response = await fetch('https://api.example.com/v1/chat/completions', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ /* 请求参数 */ })
});

4. 🛡️ 预防措施


  • 规范路径配置:将API基础路径和接口路径分离管理,避免手动拼接时重复,例如使用环境变量或配置对象统一存储基础URL。

  • 工具校验检查:使用Postman、Insomnia等API调试工具先验证接口路径,再写入代码;或在代码中添加路径格式校验逻辑(如避免包含重复的固定片段)。