API call failed after 3 retries: HTTP 404: Invalid URL (POST /v1/chat/completion...

2026年04月28日 15:21 processing

错误信息

API call failed after 3 retries: HTTP 404: Invalid URL (POST /v1/chat/completions/chat/completions)

AI 解决方案

报错分析报告

1.错误翻译


原文:HTTP 404: Invalid URL (POST /v1/chat/completions/chat/completions)
译文:HTTP 404:无效URL(POST请求路径为/v1/chat/completions/chat/completions)

2. 原因分析


  • 根本原因:请求URL路径重复(/v1/chat/completions后多叠加了chat/completions),服务器无法识别无效路径。

  • 发生位置:POST请求的目标URL设置错误(路径冗余)。
  • 3.解决方案


    import requests
    
    # 修正后的正确URL(移除重复路径)
    url = "https://api.dmxapi.com/v1/chat/completions"  
    headers = {
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type": "application/json"
    }
    payload = {
        "model": "gpt-3.5-turbo",
        "messages": [{"role": "user", "content": "Hello"}]
    }
    
    response = requests.post(url, headers=headers, json=payload)
    print(response.json())
    

    4. 预防措施


  • ✅ 核对API文档确认端点路径,避免拼写错误或路径叠加;

  • ✅ 用Postman/curl预测试端点有效性,再集成到代码。
  • ---
    :替换YOUR_API_KEY为实际密钥,确保域名与平台一致。