NotFoundError: Error code: 404 - {'error': {'message': 'Invalid URL (POST /v1/ch...

2026年04月03日 18:08 processing

错误信息

Unknown agent error: NotFoundError: Error code: 404 - {'error': {'message': 'Invalid URL (POST /v1/chat/completions/chat/completions)', 'type': 'invalid_request_error', 'code': ''}}

AI 解决方案

报错分析报告

1.错误翻译


原文:NotFoundError: Error code: 404 - Invalid URL (POST /v1/chat/completions/chat/completions)
译文:未找到错误:错误码404 - 无效URL(POST请求路径为/v1/chat/completions/chat/completions)

2.原因分析


  • 根本原因:请求URL路径错误(重复叠加chat/completions段)。

  • 具体位置:POST请求的端点路径应为/v1/chat/completions,但实际写成了/v1/chat/completions/chat/completions,导致服务器无法识别该资源。
  • 3.解决方案


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

    4. 预防措施


  • 最佳实践1:发送请求前对照API文档核对URL路径,避免手动拼接错误;

  • 最佳实践2:使用Postman/Insomnia等工具先测试端点有效性,再集成到代码中。

  • 推荐工具:Postman(可视化API测试)、curl(命令行快速验证)。