Mintplex-Labs/anything-llm · error · Error
Image provider returned no image data.
Error message
Image provider returned no image data.
What it means
Thrown at the tail of requestImage when the generation result's data[0] has neither b64_json nor url. The provider returned a result (after safeJsonParse normalization for non-JSON content-types) but no recognizable image field exists. This guards against silently returning undefined when the provider's response shape does not match the OpenAI images schema.
Source
Thrown at server/utils/ImageGenerators/base.js:141
},
{ signal: signal ?? undefined }
);
// Some OpenAI-compatible providers (e.g. Ollama) return the body with a
// non-JSON content-type (`application/x-ndjson`), so the SDK hands back the
// raw string unparsed. Normalize to an object before reading the image.
const { safeJsonParse } = require("../http");
const payload = typeof result === "string" ? safeJsonParse(result) : result;
const image = payload?.data?.[0];
if (image?.b64_json)
return { buffer: Buffer.from(image.b64_json, "base64") };
if (image?.url) {
const res = await fetch(image.url, { signal: signal ?? null });
if (!res.ok)
throw new Error(`Failed to fetch generated image: ${res.status}`);
return { buffer: Buffer.from(await res.arrayBuffer()) };
}
throw new Error("Image provider returned no image data.");
}
}
module.exports = { BaseImageGenerator };
View on GitHub (pinned to 526360e320)
Solutions
- Log the normalized payload (after safeJsonParse) right before the throw to inspect the actual shape.
- Verify IMAGE_GEN_MODEL_PREF is an image-generation model, not a text model, on the provider.
- If using Ollama, confirm the model supports the images.generate endpoint and returns valid JSON/ndjson.
- Extend requestImage to handle the provider's custom envelope, or switch to a provider matching the OpenAI schema.
Example fix
// before
throw new Error('Image provider returned no image data.');
// after: capture the payload for debugging
console.error('[image-gen] unexpected payload:', JSON.stringify(payload));
throw new Error(`Image provider returned no image data. Got: ${JSON.stringify(payload?.data ?? payload).slice(0, 300)}`); Defensive patterns
Strategy: type-guard
Validate before calling
const { safeJsonParse } = require('../http');
function hasGeneratedImage(result) {
const payload = typeof result === 'string' ? safeJsonParse(result) : result;
const img = payload?.data?.[0];
return !!(img && (img.b64_json || img.url));
} Type guard
/** @param {unknown} r */
function isGenerateResponse(r) {
const p = typeof r === 'string' ? (() => { try { return JSON.parse(r); } catch { return null; } })() : r;
const img = p && typeof p === 'object' && Array.isArray(p.data) ? p.data[0] : null;
return !!img && typeof img === 'object' && (typeof img.b64_json === 'string' || typeof img.url === 'string');
} Try / catch
try {
return await generator.requestImage(prompt, size, signal);
} catch (e) {
if (/Image provider returned no image data/.test(e.message)) {
throw new Error('Provider returned no image — verify IMAGE_GEN_MODEL_PREF is an image model and check moderation');
}
throw e;
} Prevention
- Verify IMAGE_GEN_MODEL_PREF is an image-generation model on the provider.
- For Ollama, confirm valid JSON/ndjson is returned for the image model.
- Log the normalized payload to catch schema drift early.
- Test new providers with a shape assertion before production use.
When it happens
Trigger: images.generate returns 200/OK with an empty data array, a data[0] containing only an error/revised_prompt/moderation field, a non-OpenAI envelope, or content filtering that suppressed the image. For Ollama/ndjson providers the result is string-parsed first, so a malformed JSON body also lands here.
Common situations: Content policy rejection returning 200 without an image; provider returning a different schema than {data:[{b64_json|url}]}; Ollama returning unparsable ndjson that safeJsonParse turns into a non-conforming object; a model that returns a text description instead of an image.
Related errors
- Image edit returned no image data.
- OpenRouter returned no image data.
- No Ollama image generation base path was set.
- No Ollama image generation model was set.
- Failed to fetch image
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/a36c46ebb8666d73.
Report an issue: GitHub.