{"record":{"id":"fa2c9438fb0685b7","repo":"can1357/oh-my-pi","slug":"image-download-failed-response-status-rawt","errorCode":null,"errorMessage":"Image download failed (${response.status}): ${rawText}","messagePattern":"Image download failed \\((.+?)\\): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/image-gen.ts","lineNumber":397,"sourceCode":"\timageUrl: string,\n\tfetchImpl: FetchImpl,\n\tsignal?: AbortSignal,\n): Promise<InlineImageData> {\n\tif (imageUrl.startsWith(\"data:\")) {\n\t\tconst normalized = normalizeDataUrl(imageUrl.trim());\n\t\tif (!normalized.mimeType) {\n\t\t\tthrow new Error(\"mime_type is required when providing raw base64 data.\");\n\t\t}\n\t\tif (!normalized.data) {\n\t\t\tthrow new Error(\"Image data is empty.\");\n\t\t}\n\t\treturn { data: normalized.data, mimeType: normalized.mimeType };\n\t}\n\n\tconst response = await fetchImpl(imageUrl, { signal });\n\tif (!response.ok) {\n\t\tconst rawText = await response.text();\n\t\tthrow new Error(`Image download failed (${response.status}): ${rawText}`);\n\t}\n\tconst contentType = response.headers.get(\"content-type\")?.split(\";\")[0];\n\tif (!contentType?.startsWith(\"image/\")) {\n\t\tthrow new Error(`Unsupported image type from URL: ${imageUrl}`);\n\t}\n\tconst buffer = await response.bytes();\n\treturn { data: buffer.toBase64(), mimeType: contentType };\n}\n\nfunction collectOpenRouterResponseText(message: OpenRouterMessage | undefined): string | undefined {\n\tif (!message) return undefined;\n\tif (typeof message.content === \"string\") {\n\t\tconst trimmed = message.content.trim();\n\t\treturn trimmed.length > 0 ? trimmed : undefined;\n\t}\n\tif (Array.isArray(message.content)) {\n\t\tconst texts = message.content\n\t\t\t.filter(part => part.type === \"text\")","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/image-gen.ts#L379-L415","documentation":"The tool fetches an image from a remote URL and requires an HTTP 2xx; any non-OK response raises this error embedding the status code and the raw response body, which usually explains why the server refused (404 not found, 403 denied, 429 rate-limited, etc.). It surfaces the server's own error text so the failure cause is visible in the tool result.","triggerScenarios":"loadImageFromUrl calls fetchImpl(imageUrl) and response.ok is false — any 4xx/5xx from the remote image host, e.g. expired signed URL, wrong path, CDN auth, or rate limiting during image-gen input-image collection.","commonSituations":"Pre-signed S3/GCS URLs that expired; hotlink protection or missing auth headers on a CDN; typo'd image URLs; 429s from provider throttling; image host behind a proxy returning HTML error pages.","solutions":["Open the URL (or curl it) and read the embedded status/body message in the error to see the server's reason","For 403/404 on signed URLs, regenerate a fresh signed URL before invoking the tool","For 429, wait and retry with backoff, or host the image somewhere less rate-limited","Verify the URL is reachable from the machine running the tool (proxy/VPN/firewall may block it)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// optional pre-flight (only for critical flows)\nconst head = await fetch(imageUrl, { method: \"HEAD\" });\nif (!head.ok) throw new Error(`Pre-flight failed: ${head.status} for ${imageUrl}`);","typeGuard":null,"tryCatchPattern":"try {\n\tawait genImage({ imageUrl });\n} catch (err) {\n\tconst m = /Image download failed \\((\\d+)\\)/.exec(String(err));\n\tif (m && (m[1] === \"429\" || m[1].startsWith(\"5\"))) {\n\t\tawait Bun.sleep(2000); // retry with backoff\n\t\treturn genImage({ imageUrl });\n\t}\n\tthrow err; // 4xx: fix URL/auth, don't blind-retry\n}","preventionTips":["Generate fresh signed URLs shortly before use; they expire","Prefer stable, authenticated hosts over ad-hoc CDNs","Catch 429/5xx for retries but not 403/404","Test image URLs with curl -I from the machine running the tool"],"tags":["network","http","image-download","remote-url"],"backgroundTag":"image-download-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}