From 36278ffc7d882d5f902f3959ce3ec0294b563d66 Mon Sep 17 00:00:00 2001 From: Fsocietyhhh <1211904451@qq.com> Date: Mon, 27 Apr 2026 23:39:17 -0700 Subject: [PATCH] fix(imagegen): bump image-to-image timeout to 180s (was 60s shared with t2i) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The single 60s timeout on the main /v1/images/{generations,image2image} fetch covered both x402 retry attempts AND the actual generation. That budget is generous for text-to-image (gpt-image-1 finishes in 10–30s) but consistently insufficient for image-to-image: - gpt-image-2 is reasoning-driven; an edit easily takes 60–150s on its own - the request body carries a few MB of base64 reference image, adding measurable upload time on slower links - the timeout has to share its budget across two POSTs (the 402 round trip plus the paid one) End result: every gpt-image-2 reference-image call I tried hit AbortError before the upstream model returned, with a misleading message ("Try a simpler prompt") that made it look like a server problem. This patch: - splits the budget — image-to-image gets 180s, text-to-image keeps 60s - updates the timeout error message to mention the 180s limit and the most likely causes (image too large, model under load) when the reference-image path is taken The existing 30s timeouts on resolveReferenceImage (URL fetch) and on the result download stay unchanged — those are network-bound and shouldn't routinely be slow. --- src/tools/imagegen.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/tools/imagegen.ts b/src/tools/imagegen.ts index cf04bac..c1353ab 100644 --- a/src/tools/imagegen.ts +++ b/src/tools/imagegen.ts @@ -283,7 +283,14 @@ function buildExecute(deps: ImageGenDeps) { }; const controller = new AbortController(); - const timeout = setTimeout(() => controller.abort(), 60_000); // 60s timeout + // Reference-image mode (gpt-image-2 edits) is meaningfully slower than + // pure text-to-image: the model is reasoning-driven and the request + // body carries a few MB of base64. The shared 60s budget has to cover + // both x402 retry attempts plus the actual generation, which made + // image-to-image effectively always time out. Image-to-image gets 3 + // minutes; text-to-image keeps the original 60s. + const timeoutMs = referenceImage ? 180_000 : 60_000; + const timeout = setTimeout(() => controller.abort(), timeoutMs); try { // First request — will get 402 @@ -404,7 +411,12 @@ function buildExecute(deps: ImageGenDeps) { } catch (err) { const msg = (err as Error).message || ''; if (msg.includes('abort')) { - return { output: 'Image generation timed out (60s limit). Try a simpler prompt.', isError: true }; + return { + output: referenceImage + ? 'Image-to-image timed out (180s limit). The reference image may be too large or the model under load — try a smaller image or simpler prompt.' + : 'Image generation timed out (60s limit). Try a simpler prompt.', + isError: true, + }; } return { output: `Error: ${msg}`, isError: true }; } finally {