Mintplex-Labs/anything-llm · error · Error

OpenRouter returned no image data.

Error message

OpenRouter returned no image data.

What it means

Thrown by OpenRouterImageGenerator._extractImageBuffer when the dataUrl argument is falsy. _extractImageBuffer splits a data-URL (data:image/png;base64,...) on the comma and base64-decodes the tail, so a missing/empty dataUrl means there is nothing to decode. This is the OpenRouter-specific image extraction path, separate from the BaseImageGenerator b64/url handling.

Source

Thrown at server/utils/ImageGenerators/openRouter/index.js:5

const { BaseImageGenerator } = require("../base");

class OpenRouterImageGenerator extends BaseImageGenerator {
  _extractImageBuffer(dataUrl) {
    if (!dataUrl) throw new Error("OpenRouter returned no image data.");
    return Buffer.from(dataUrl.split(",").pop(), "base64");
  }

  constructor() {
    if (!process.env.IMAGE_GEN_OPENROUTER_API_KEY)
      throw new Error("No OpenRouter image generation API key was set.");
    if (!process.env.IMAGE_GEN_MODEL_PREF)
      throw new Error("No OpenRouter image generation model was set.");
    const { OpenAI: OpenAIApi } = require("openai");
    super({
      client: new OpenAIApi({
        baseURL: "https://openrouter.ai/api/v1",
        apiKey: process.env.IMAGE_GEN_OPENROUTER_API_KEY,
        defaultHeaders: {
          "HTTP-Referer": "https://anythingllm.com",
          "X-Title": "AnythingLLM",
        },
      }),

View on GitHub (pinned to 526360e320)

Solutions

  1. Inspect the full OpenRouter image-generation response object before calling _extractImageBuffer to confirm the data-URL field exists.
  2. Confirm IMAGE_GEN_MODEL_PREF is an image-capable model on OpenRouter.
  3. Check for content-moderation fields in the response that suppressed the image.
  4. Handle the missing field upstream and surface the provider's error message instead of calling _extractImageBuffer.

Example fix

// before
_extractImageBuffer(resp?.data?.[0]?.url)

// after: guard before extracting
const dataUrl = resp?.data?.[0]?.url;
if (!dataUrl) {
  throw new Error(`OpenRouter returned no image data. Response: ${JSON.stringify(resp?.data ?? resp).slice(0, 300)}`);
}
return _extractImageBuffer(dataUrl);
Defensive patterns

Strategy: type-guard

Validate before calling

function hasDataUrl(resp) {
  const url = resp?.data?.[0]?.url || resp?.data?.[0]?.b64_json;
  return typeof url === 'string' && url.length > 0;
}
const resp = await callOpenRouterImage();
if (!hasDataUrl(resp)) {
  throw new Error(`OpenRouter returned no image. Full response: ${JSON.stringify(resp).slice(0, 300)}`);
}

Type guard

/** @param {unknown} r */
function isOpenRouterImageResponse(r) {
  const img = r && typeof r === 'object' && Array.isArray(r.data) ? r.data[0] : null;
  return !!img && typeof img === 'object' && (typeof img.url === 'string' || typeof img.b64_json === 'string');
}

Try / catch

try {
  return generator._extractImageBuffer(dataUrl);
} catch (e) {
  if (/OpenRouter returned no image data/.test(e.message)) {
    throw new Error('OpenRouter produced no image — check IMAGE_GEN_MODEL_PREF and moderation status');
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling _extractImageBuffer with undefined/null/'' when the OpenRouter image-generation response did not include the expected data-URL image field — e.g. the provider returned an error envelope, an empty data array, content moderation, or a different response shape than expected.

Common situations: OpenRouter routing to a backing model that failed silently; content policy filtering the image; response shape change in the OpenRouter image API; the model selected (IMAGE_GEN_MODEL_PREF) not actually being an image model.

Related errors


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