Mintplex-Labs/anything-llm · critical · Error

No OpenRouter image generation model was set.

Error message

No OpenRouter image generation model was set.

What it means

Thrown synchronously in the OpenRouterImageGenerator constructor after the API-key check. IMAGE_GEN_MODEL_PREF selects which OpenRouter-hosted model to call for image generation; OpenRouter has no default here. This variable is shared across all image providers.

Source

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

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",
        },
      }),
      model: process.env.IMAGE_GEN_MODEL_PREF,
      className: "OpenRouterImageGenerator",
    });
  }

  // OpenRouter does not expose /images/generations. Its image models return
  // images through chat completions with the "image" output modality, where the
  // image comes back as a base64 data URL in `message.images`.

View on GitHub (pinned to 526360e320)

Solutions

  1. Set IMAGE_GEN_MODEL_PREF to a valid OpenRouter image model id in .env.
  2. Verify the model id exists and supports image generation on openrouter.ai/models.
  3. Restart the server after setting the variable.
  4. Remember IMAGE_GEN_MODEL_PREF is shared across image providers.

Example fix

# before
IMAGE_GEN_PROVIDER=openrouter
IMAGE_GEN_OPENROUTER_API_KEY=sk-or-v1-xxxx
# (no model)

# after
IMAGE_GEN_PROVIDER=openrouter
IMAGE_GEN_OPENROUTER_API_KEY=sk-or-v1-xxxx
IMAGE_GEN_MODEL_PREF=openai/gpt-image-1
Defensive patterns

Strategy: validation

Validate before calling

function hasImageModel() {
  return typeof process.env.IMAGE_GEN_MODEL_PREF === 'string'
    && process.env.IMAGE_GEN_MODEL_PREF.trim().length > 0;
}
if (!hasImageModel()) {
  throw new Error('Set IMAGE_GEN_MODEL_PREF before using OpenRouter image generation.');
}

Type guard

function isImageModelSet() {
  return !!process.env.IMAGE_GEN_MODEL_PREF && process.env.IMAGE_GEN_MODEL_PREF.trim().length > 0;
}

Try / catch

try {
  generator = new OpenRouterImageGenerator();
} catch (e) {
  if (/No OpenRouter image generation model/.test(e.message)) {
    throw new Error('Set IMAGE_GEN_MODEL_PREF to a valid OpenRouter image model and restart.');
  }
  throw e;
}

Prevention

When it happens

Trigger: Instantiating new OpenRouterImageGenerator() when process.env.IMAGE_GEN_MODEL_PREF is unset or empty.

Common situations: Selecting OpenRouter image generation without naming a model; using a model id that is not an image model on OpenRouter; switching providers and leaving the model field blank; container env missing IMAGE_GEN_MODEL_PREF.

Related errors


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