Mintplex-Labs/anything-llm · error · Error
Failed to fetch edited image: ${imgRes.status}
Error message
Failed to fetch edited image: ${imgRes.status} What it means
Thrown in editImage after a successful /images/edits call that returned a URL instead of base64. The code fetches that image URL (passing through the AbortSignal) and, if the fetch is not ok, throws only the numeric HTTP status. This is the download stage: the edit succeeded but the hosted result image could not be retrieved.
Source
Thrown at server/utils/ImageGenerators/base.js:109
body: formData,
signal: signal ?? null,
});
if (!res.ok) {
const body = await res.text().catch(() => "");
throw new Error(
`Image edit failed (${res.status}): ${body || res.statusText}`
);
}
const payload = await res.json();
const image = payload?.data?.[0];
if (image?.b64_json)
return { buffer: Buffer.from(image.b64_json, "base64") };
if (image?.url) {
const imgRes = await fetch(image.url, { signal: signal ?? null });
if (!imgRes.ok)
throw new Error(`Failed to fetch edited image: ${imgRes.status}`);
return { buffer: Buffer.from(await imgRes.arrayBuffer()) };
}
throw new Error("Image edit returned no image data.");
}
async requestImage(prompt, size, signal) {
this.log(`Generating ${size} image with ${this.model}.`);
const result = await this.client.images.generate(
{
model: this.model,
prompt,
size,
n: 1,
},
{ signal: signal ?? undefined }
);
// Some OpenAI-compatible providers (e.g. Ollama) return the body with aView on GitHub (pinned to 526360e320)
Solutions
- Retry the edit/download — short-lived URL expiry is often transient.
- Check the deployment's network egress allows the image-hosting domain returned by the provider.
- If the provider supports response_format=b64_json, prefer it to avoid the second fetch entirely.
- Increase the request timeout / avoid aborting the signal before the download completes.
Example fix
// before
const imgRes = await fetch(image.url, { signal: signal ?? null });
if (!imgRes.ok) throw new Error(`Failed to fetch edited image: ${imgRes.status}`);
// after: retry with backoff for transient download failures
async function fetchWithRetry(url, signal, tries = 3) {
for (let i = 0; i < tries; i++) {
const r = await fetch(url, { signal: signal ?? null });
if (r.ok) return r;
if (r.status < 500 || i === tries - 1) throw new Error(`Failed to fetch edited image: ${r.status}`);
await new Promise(res => setTimeout(res, 500 * (i + 1)));
}
} Defensive patterns
Strategy: retry
Validate before calling
// Cannot validate a remote URL's availability before the edit returns it,
// but you can ensure network egress is allowed:
async function canReachHost(urlString) {
try { return new URL(urlString).hostname.length > 0; } catch { return false; }
} Type guard
/** @param {unknown} e */
function isEditedImageFetchError(e) {
return e instanceof Error && /^Failed to fetch edited image: \d+$/.test(e.message);
} Try / catch
// Retry transient (5xx) download failures with backoff
async function downloadEditedImage(url, signal) {
for (let i = 0; i < 3; i++) {
const r = await fetch(url, { signal: signal ?? null });
if (r.ok) return Buffer.from(await r.arrayBuffer());
if (r.status < 500) throw new Error(`Failed to fetch edited image: ${r.status}`);
await new Promise(res => setTimeout(res, 500 * (i + 1)));
}
throw new Error('Edited image download failed after retries');
} Prevention
- Prefer providers that return b64_json to skip the download step entirely.
- Allow egress to the provider's image-hosting domain in your network policy.
- Avoid aborting the signal before the download completes.
- Retry 5xx download failures; surface 4xx as permanent.
When it happens
Trigger: The provider returns a signed/temporary URL for the edited image, but fetching it returns non-2xx: expired pre-signed URL, provider CDN outage, region-restricted storage, 403 because the URL's token expired, or the signal aborted but surfaced as a status error.
Common situations: Providers that return URLs (not base64) where the link is short-lived and expires between edit completion and download; network egress restrictions in the deployment blocking the image-hosting domain; the download fetch raced with a timeout/abort.
Related errors
- Failed to fetch generated image: ${res.status}
- Image edit failed (${res.status}): ${body || res.statusText}
- HTTP ${res.status}: ${res.statusText}
- Failed to fetch image
- Image edit returned no image data.
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/f5d54c42207bacfa.
Report an issue: GitHub.