{"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":null,"httpStatus":null,"severity":"error","filePath":"server/utils/ImageGenerators/base.js","lineNumber":168,"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":150,"sourceCodeEnd":173,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/f92433b4ea0598492a1e6645ea22addbb4dd1287/server/utils/ImageGenerators/base.js#L150-L173","documentation":"requestImage() got a 2xx from client.images.generate(), normalized string bodies through safeJsonParse (some providers like Ollama return x-ndjson, which the SDK hands back unparsed), and then found neither b64_json nor url on payload.data[0] — or no data array at all. The provider responded, but not in any recognizable OpenAI images shape.","triggerScenarios":"An OpenAI-compatible server returning a nonstandard envelope; a provider streaming NDJSON whose first JSON line lacks data[0]; an empty data array; an error body delivered with status 200; malformed JSON that safeJsonParse turns into null.","commonSituations":"Ollama's experimental OpenAI-compatible image endpoint returning ndjson; custom gateways (LM Studio, comfy bridges) with their own schemas; provider version upgrades that change the response format.","solutions":["Log the raw result from images.generate() before normalization to inspect the actual payload.","Ensure the provider returns the OpenAI images.generate shape: { data: [{ b64_json | url }] }.","Upgrade or align the provider version with the OpenAI images API contract.","Pick a different image engine whose responses this code path understands."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isUsableImageGeneratePayload(payload) {\n  const image = payload?.data?.[0];\n  return Boolean(\n    image &&\n      ((typeof image.b64_json === \"string\" && image.b64_json.length > 0) ||\n        (typeof image.url === \"string\" && image.url.length > 0))\n  );\n}","tryCatchPattern":"try {\n  const image = await generator.generateImage({ prompt, size, signal });\n} catch (err) {\n  if (err.message === \"Image provider returned no image data.\") {\n    // provider returned 2xx but no data[0].b64_json/url:\n    // inspect the raw generate result and align the provider with the OpenAI images schema\n  } else {\n    throw err;\n  }\n}","preventionTips":["Verify a provider's images.generate response shape with a curl smoke test before adopting it.","When a provider returns ndjson, confirm safeJsonParse of the first line yields { data: [...] }.","Pin provider versions whose image schema you have verified."],"tags":["image-generation","empty-response","response-shape","openai-compatible"],"backgroundTag":"empty-api-response","analyzedSha":"f92433b4ea0598492a1e6645ea22addbb4dd1287","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}