404 Invalid URL (POST /v1/chat/completions/chat/completions)
错误信息
404 Invalid URL (POST /v1/chat/completions/chat/completions)
AI 解决方案
报错分析报告
1. 错误翻译
原文:404 Invalid URL (POST /v1/chat/completions/chat/completions)
译文:404 无效URL(POST请求路径为/v1/chat/completions/chat/completions)
2. 原因分析
chat/completions段(正确路径应为/v1/chat/completions)。 3.解决方案
修正URL路径,移除重复的
chat/completions:# curl示例(正确路径)
curl -X POST https://api.dmxapi.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Hello"}]}'
# Python requests示例(正确路径)
import requests
url = "https://api.dmxapi.com/v1/chat/completions"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
}
data = {"model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Hello"}]}
response = requests.post(url, headers=headers, json=data)
print(response.json())
4.️ 预防措施
CHAT_COMPLETIONS_URL = "/v1/chat/completions"),减少硬编码失误。 ---
请优先检查URL路径的冗余问题,修正后即可正常请求。