Mintplex-Labs/anything-llm · error · Error

Image edit returned no image data.

Error message

Image edit returned no image data.

What it means

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.

Source

Thrown at server/utils/ImageGenerators/base.js:112

    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 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");

View on GitHub (pinned to 526360e320)

Solutions

  1. Log the full parsed payload before this throw to see what shape the provider actually returned.
  2. Confirm the provider's /images/edits response matches the OpenAI schema ({data:[{b64_json|url}]}).
  3. If the provider uses a different envelope, extend editImage to normalize that shape (or switch providers).
  4. Check whether content moderation filtered the edit (provider often returns a 200 with a moderation field).

Example fix

// before
const image = payload?.data?.[0];
if (image?.b64_json) return { buffer: Buffer.from(image.b64_json, 'base64') };
if (image?.url) { /* fetch url */ }
throw new Error('Image edit returned no image data.');

// after: include the payload in the error for diagnosis
throw new Error(`Image edit returned no image data. Payload: ${JSON.stringify(payload).slice(0, 500)}`);
Defensive patterns

Strategy: type-guard

Validate before calling

function hasEditableImage(payload) {
  const img = payload?.data?.[0];
  return !!(img && (img.b64_json || img.url));
}
// usage:
const payload = await res.json();
if (!hasEditableImage(payload)) {
  throw new Error(`Unexpected edit response: ${JSON.stringify(payload).slice(0, 300)}`);
}

Type guard

/** @param {unknown} p */
function isEditResponse(p) {
  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.editImage({ prompt, images });
} catch (e) {
  if (/Image edit returned no image data/.test(e.message)) {
    // likely provider schema mismatch or moderation — log payload upstream
    throw new Error('Image edit succeeded but returned no image (check provider schema/moderation)');
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/972973f6d083f24c. Report an issue: GitHub.