{"record":{"id":"a36c46ebb8666d73","repo":"Mintplex-Labs/anything-llm","slug":"image-provider-returned-no-image-data","errorCode":null,"errorMessage":"Image provider returned no image data.","messagePattern":"Image provider returned no image data\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/ImageGenerators/base.js","lineNumber":141,"sourceCode":"      },\n      { signal: signal ?? undefined }\n    );\n\n    // Some OpenAI-compatible providers (e.g. Ollama) return the body with a\n    // non-JSON content-type (`application/x-ndjson`), so the SDK hands back the\n    // raw string unparsed. Normalize to an object before reading the image.\n    const { safeJsonParse } = require(\"../http\");\n    const payload = typeof result === \"string\" ? safeJsonParse(result) : result;\n    const image = payload?.data?.[0];\n    if (image?.b64_json)\n      return { buffer: Buffer.from(image.b64_json, \"base64\") };\n    if (image?.url) {\n      const res = await fetch(image.url, { signal: signal ?? null });\n      if (!res.ok)\n        throw new Error(`Failed to fetch generated image: ${res.status}`);\n      return { buffer: Buffer.from(await res.arrayBuffer()) };\n    }\n    throw new Error(\"Image provider returned no image data.\");\n  }\n}\n\nmodule.exports = { BaseImageGenerator };\n","sourceCodeStart":123,"sourceCodeEnd":146,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/ImageGenerators/base.js#L123-L146","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nthrow new Error('Image provider returned no image data.');\n\n// after: capture the payload for debugging\nconsole.error('[image-gen] unexpected payload:', JSON.stringify(payload));\nthrow new Error(`Image provider returned no image data. Got: ${JSON.stringify(payload?.data ?? payload).slice(0, 300)}`);","handlingStrategy":"type-guard","validationCode":"const { safeJsonParse } = require('../http');\nfunction hasGeneratedImage(result) {\n  const payload = typeof result === 'string' ? safeJsonParse(result) : result;\n  const img = payload?.data?.[0];\n  return !!(img && (img.b64_json || img.url));\n}","typeGuard":"/** @param {unknown} r */\nfunction isGenerateResponse(r) {\n  const p = typeof r === 'string' ? (() => { try { return JSON.parse(r); } catch { return null; } })() : r;\n  const img = p && typeof p === 'object' && Array.isArray(p.data) ? p.data[0] : null;\n  return !!img && typeof img === 'object' && (typeof img.b64_json === 'string' || typeof img.url === 'string');\n}","tryCatchPattern":"try {\n  return await generator.requestImage(prompt, size, signal);\n} catch (e) {\n  if (/Image provider returned no image data/.test(e.message)) {\n    throw new Error('Provider returned no image — verify IMAGE_GEN_MODEL_PREF is an image model and check moderation');\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["image-generation","response-shape","provider-compat","data-integrity","ollama"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}