Skip to content

fix: parse streamed Responses image events#9

Open
ss7777q wants to merge 1 commit intoCookSleep:mainfrom
ss7777q:fix/responses-stream-image-events
Open

fix: parse streamed Responses image events#9
ss7777q wants to merge 1 commit intoCookSleep:mainfrom
ss7777q:fix/responses-stream-image-events

Conversation

@ss7777q
Copy link
Copy Markdown

@ss7777q ss7777q commented Apr 27, 2026

背景

关联 #7

长时间图片生成失败通常有两类场景:

  1. 自建 Nginx/OpenResty/1Panel 反代时,Images API 非流式请求可能因为 proxy_read_timeout 等配置较短,在 60 秒左右返回 504。这个场景仍然应优先通过提高反代超时解决。

  2. 使用第三方 OpenAI 兼容中转时,调用方无法修改对方网关配置。复杂图片生成可能超过代理层空闲超时,非流式请求会在最终 JSON 返回前被断开。

本 PR 主要补充第二类场景的前端兼容方案:在 Responses API 下支持流式响应,并从 SSE 事件中提取图片数据。

改动

  • 为 Responses API 增加“流式生图响应”设置项
    • 默认开启
    • 可在设置中关闭,以兼容不支持流式响应的中转
  • Responses API 流式开启时,请求体增加 stream: true
  • 流式文生图时,请求 partial_images: 1
  • 新增 SSE 事件解析逻辑
  • 支持从以下事件/字段中提取图片 base64:
    • response.output_item.done
    • response.image_generation_call.partial_image
    • response.completed
    • result
    • partial_image_b64
    • b64_json
  • 优先使用最终图片结果
  • 如果没有最终图片,但流中出现过 partial image,则将 partial image 作为 fallback
  • 保留非流式 Responses API 的原有 JSON 解析路径

行为说明

这个 PR 不改变 Images API /v1/images/generations 的行为。

对于 Images API 的 504 问题,仍然需要调整网关超时,例如:

proxy_connect_timeout 300s;
proxy_send_timeout    300s;
proxy_read_timeout    600s;
send_timeout          600s;

@ss7777q ss7777q force-pushed the fix/responses-stream-image-events branch from c030806 to 5be822b Compare April 27, 2026 13:01
@CookSleep
Copy link
Copy Markdown
Owner

CookSleep commented Apr 27, 2026

其实主要是流式要多扣钱……

我先把遮罩那个改完再看看这个

@ss7777q ss7777q force-pushed the fix/responses-stream-image-events branch from 5be822b to f15c664 Compare April 27, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants