Mintplex-Labs/anything-llm · error

OpenRouter returned no image data.

Error message

OpenRouter returned no image data.

What it means

AnythingLLM's OpenRouter image generator does not call /images/generations; it calls chat.completions.create with modalities ["image","text"] and expects the image as a base64 data URL at choices[0].message.images[0].image_url.url. This error is thrown by _extractImageBuffer when that field is missing, so there is no data URL to decode into a Buffer.

Solutions

  1. Set IMAGE_GEN_MODEL_PREF to a model that supports the image output modality (e.g. google/gemini-2.5-flash-image-preview) and restart the server
  2. Log completion.choices[0].message.content — a text refusal or error message explains why images is empty
  3. Verify the OpenRouter key is valid and funded, and check the OpenRouter dashboard activity log for the failed request
  4. Wrap generateImage/editImage in try-catch and surface a user-facing message instead of failing on Buffer.from

Example fix

// before (.env)
IMAGE_GEN_MODEL_PREF=openai/gpt-4o

// after (.env)
IMAGE_GEN_MODEL_PREF=google/gemini-2.5-flash-image-preview
Defensive patterns

Strategy: validation

Validate before calling

// Before generating, confirm the configured model advertises image output
const res = await fetch('https://openrouter.ai/api/v1/models');
const { data } = await res.json();
const model = data.find((m) => m.id === process.env.IMAGE_GEN_MODEL_PREF);
if (!model || !model.architecture?.output_modalities?.includes('image')) {
  throw new Error('IMAGE_GEN_MODEL_PREF does not support image output modality');
}

Type guard

function hasImageDataUrl(completion) {
  const url = completion?.choices?.[0]?.message?.images?.[0]?.image_url?.url;
  return typeof url === 'string' && url.startsWith('data:');
}

Try / catch

try {
  const { buffer } = await generator.generateImage({ prompt });
} catch (err) {
  if (err.message === 'OpenRouter returned no image data.') {
    // model produced text only — surface message.content or pick an image-capable model
  }
  throw err;
}

Prevention

When it happens

Trigger: generateImage() or editImage() completes but the response has no message.images array — IMAGE_GEN_MODEL_PREF points to a text-only model, the routed upstream provider ignores the image modality, the model replies with plain text (e.g. a safety refusal), or images is an empty array.

Common situations: Setting IMAGE_GEN_MODEL_PREF to a chat model without image output support or a typo'd slug; routing to an OpenRouter provider that strips the modality flag; exhausted/invalid key returning an in-band text error instead of an image.

Related errors


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

Appendix: 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 3aec848f28)