401, auth error code: invalid_api_key
错误信息
unexpected status 401 Unauthorized: Incorrect API key provided: sk-lDOU3***************************************PfBW. You can find your API key at https://platform.openai.com/account/api-keys., url: https://api.openai.com/v1/responses, cf-ray: a2b5ce3a1a73af4e-NRT, request id: req_3c42fe70f01a432eb9795476d4fe2ea1, auth error: 401, auth error code: invalid_api_key
AI 解决方案
🔍 报错分析
1. 🌐 错误翻译
原文:unexpected status 401 Unauthorized: Incorrect API key provided: sk-lDOU3***************************************PfBW. You can find your API key at https://platform.openai.com/account/api-keys., url: https://api.openai.com/v1/responses, cf-ray: a2b5ce3a1a73af4e-NRT, request id: req_3c42fe70f01a432eb9795476d4fe2ea1, auth error: 401, auth error code: invalid_api_key
译文:意外状态 401 未授权:提供的API密钥不正确:sk-lDOU3***************************************PfBW。您可以在 https://platform.openai.com/account/api-keys 找到您的API密钥,url:https://api.openai.com/v1/responses,cf-ray:a2b5ce3a1a73af4e-NRT,请求ID:req_3c42fe70f01a432eb9795476d4fe2ea1,认证错误:401,认证错误代码:invalid_api_key
2. 🎯 原因分析
https://api.openai.com/v1/responses 发送请求时,携带的API密钥无法通过身份验证3. 💡 解决方案
// 替换为正确的API密钥
const API_KEY = "sk-你的有效API密钥"; // 请从 https://platform.openai.com/account/api-keys 获取
// 确保在请求头中正确设置
fetch("https://api.openai.com/v1/responses", {
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json"
},
// ...其他配置
});