code: 404 - {'error': {'message': 'Invalid URL (POST /v1/responses/chat/completi...

2026年03月25日 18:08 状态: processing

🚨 错误信息

Bianxie] 图像生成 API 调用失败: Error code: 404 - {'error': {'message': 'Invalid URL (POST /v1/responses/chat/completions)', 'type': 'invalid_request_error', 'code': ''}} Traceback (most recent call last): File "D:\biosoft\AutoFigure-Edit\autofigure2.py", line 3166, in <module> result = method_to_svg( ^^^^^^^^^^^^^^ File "D:\biosoft\AutoFigure-Edit\autofigure2.py", line 2864, in method_to_svg generate_figure_from_method( File "D:\biosoft\AutoFigure-Edit\autofigure2.py", line 1024, in generate_figure_from_method img = call_llm_image_generation( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\biosoft\AutoFigure-Edit\autofigure2.py", line 215, in call_llm_image_generation return _call_bianxie_image_generation(prompt, api_key, model, base_url, reference_image) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\biosoft\AutoFigure-Edit\autofigure2.py", line 323, in _call_bianxie_image_generation completion =

🤖 AI解决方案

报错分析报告

1.错误翻译



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

2. 原因分析


  • 根本原因:调用图像生成API时使用了错误的端点路径(/v1/responses/chat/completions是聊天补全接口,非图像生成接口)。

  • 发生位置_call_bianxie_image_generation函数中发起POST请求的URL拼接错误(第323行附近)。

  • 上下文:代码意图调用图像生成API,但误将聊天补全的路径作为图像生成端点。
  • 3.解决方案


    python

    修复后的核心代码片段(修正API端点路径)


    def _call_bianxie_image_generation(prompt, api_key, model, base_url, reference_image):
    headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
    # 关键修复:将错误的聊天补全路径改为图像生成的正确路径(以官方文档为准)
    # 示例正确路径(需替换为Bianxie图像生成的实际端点,如/v1/images/generations)
    url = f"{base_url.rstrip('/')}/v1/images/generations"
    payload = {
    "model": model,
    "prompt": prompt,
    "reference_image": reference_image # 若有参考图参数需保留
    }
    response = requests.post(url, headers=headers, json=payload)
    return response.json()

    4. 预防措施


  • 核对端点文档:调用第三方API前,务必从官方文档确认正确的端点路径(如图像生成通常用/v1/images/generations而非聊天路径)。

  • 预验证工具:用Postman或curl先测试端点有效性,避免代码中硬编码错误路径。
  • ---
    :需根据Bianxie图像生成的实际官方文档调整最终端点路径(上述示例为通用图像生成接口格式)。