code: 404 - {'error': {'message': 'Invalid URL (POST /v1/responses/chat/completi...
🚨 错误信息
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. 原因分析
/v1/responses/chat/completions是聊天补全接口,非图像生成接口)。_call_bianxie_image_generation函数中发起POST请求的URL拼接错误(第323行附近)。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. 预防措施
/v1/images/generations而非聊天路径)。---
注:需根据Bianxie图像生成的实际官方文档调整最终端点路径(上述示例为通用图像生成接口格式)。