Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/tools/imagegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Loading