{"record":{"id":"972973f6d083f24c","repo":"Mintplex-Labs/anything-llm","slug":"image-edit-returned-no-image-data","errorCode":null,"errorMessage":"Image edit returned no image data.","messagePattern":"Image edit returned no image data\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/ImageGenerators/base.js","lineNumber":112,"sourceCode":"\n    if (!res.ok) {\n      const body = await res.text().catch(() => \"\");\n      throw new Error(\n        `Image edit failed (${res.status}): ${body || res.statusText}`\n      );\n    }\n\n    const payload = await res.json();\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 imgRes = await fetch(image.url, { signal: signal ?? null });\n      if (!imgRes.ok)\n        throw new Error(`Failed to fetch edited image: ${imgRes.status}`);\n      return { buffer: Buffer.from(await imgRes.arrayBuffer()) };\n    }\n    throw new Error(\"Image edit returned no image data.\");\n  }\n\n  async requestImage(prompt, size, signal) {\n    this.log(`Generating ${size} image with ${this.model}.`);\n    const result = await this.client.images.generate(\n      {\n        model: this.model,\n        prompt,\n        size,\n        n: 1,\n      },\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\");","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/ImageGenerators/base.js#L94-L130","documentation":"Thrown at the tail of editImage when the parsed JSON payload's data[0] element has neither b64_json nor a url. The provider returned HTTP 200 but the response shape does not contain an image in any recognized location, so there is nothing to return. This is a contract mismatch between the provider and the OpenAI-compatible edits schema this code expects.","triggerScenarios":"A provider returns 200 with an empty data array, a data[0] with only text/error fields (e.g. content-filtered), a different envelope (e.g. {image: ...} instead of {data:[...]}), or a successful edit that produced no image because of an internal provider issue.","commonSituations":"OpenAI-compatible providers that deviate from the {data:[{b64_json|url}]} schema; content moderation rejecting the edit but returning 200 with an explanatory object; a model that returns an error object instead of an image while still HTTP 200; partial provider implementations like some Lemonade/Ollama builds.","solutions":["Log the full parsed payload before this throw to see what shape the provider actually returned.","Confirm the provider's /images/edits response matches the OpenAI schema ({data:[{b64_json|url}]}).","If the provider uses a different envelope, extend editImage to normalize that shape (or switch providers).","Check whether content moderation filtered the edit (provider often returns a 200 with a moderation field)."],"exampleFix":"// before\nconst image = payload?.data?.[0];\nif (image?.b64_json) return { buffer: Buffer.from(image.b64_json, 'base64') };\nif (image?.url) { /* fetch url */ }\nthrow new Error('Image edit returned no image data.');\n\n// after: include the payload in the error for diagnosis\nthrow new Error(`Image edit returned no image data. Payload: ${JSON.stringify(payload).slice(0, 500)}`);","handlingStrategy":"type-guard","validationCode":"function hasEditableImage(payload) {\n  const img = payload?.data?.[0];\n  return !!(img && (img.b64_json || img.url));\n}\n// usage:\nconst payload = await res.json();\nif (!hasEditableImage(payload)) {\n  throw new Error(`Unexpected edit response: ${JSON.stringify(payload).slice(0, 300)}`);\n}","typeGuard":"/** @param {unknown} p */\nfunction isEditResponse(p) {\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.editImage({ prompt, images });\n} catch (e) {\n  if (/Image edit returned no image data/.test(e.message)) {\n    // likely provider schema mismatch or moderation — log payload upstream\n    throw new Error('Image edit succeeded but returned no image (check provider schema/moderation)');\n  }\n  throw e;\n}","preventionTips":["Confirm the provider's /images/edits response matches the OpenAI {data:[{b64_json|url}]} schema.","Log the full payload when this throws to diagnose schema drift quickly.","Watch for content-moderation fields returned with HTTP 200.","When integrating a new provider, add a shape test before relying on editImage."],"tags":["image-generation","image-edit","response-shape","provider-compat","data-integrity"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}