❌ **AI 请求失败** API request failed: 404 Invalid URL (POST /v1/responses/v1/chat/co...
错误信息
❌ **AI 请求失败**
API request failed: 404
Invalid URL (POST /v1/responses/v1/chat/completions)
AI 解决方案
原文:API request failed: 404 Invalid URL (POST /v1/responses/v1/chat/completions)
译文:API请求失败:404 无效的 URL (POST /v1/responses/v1/chat/completions)
🎯 原因分析
错误的核心原因是 URL 路径重复/错误,具体表现为:
/v1:/v1/responses/v1/chat/completions💡 解决方案
请使用正确的 API 端点路径,移除多余的版本号:
// 修复后的代码:使用正确的 API 端点
const API_URL = 'https://api.example.com/v1/chat/completions'; // 确保 URL 中没有重复的 /v1
// 示例:发起 API 请求
const response = await fetch(API_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: 'Hello, world!' }]
})
});