404 Invalid URL (POST /v1/chat/completions/chat/completions)

2026年04月02日 02:43 processing

错误信息

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. 原因分析


  • 根本原因:请求URL路径错误,重复拼接了chat/completions段(正确路径应为/v1/chat/completions)。

  • 具体位置:POST请求的端点路径存在冗余,服务器无法识别该无效路径。
  • 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.️ 预防措施


  • 编写请求前,对照API文档验证端点路径,避免手动拼接错误。

  • 使用常量定义路径(如CHAT_COMPLETIONS_URL = "/v1/chat/completions"),减少硬编码失误。
  • ---
    请优先检查URL路径的冗余问题,修正后即可正常请求。