Mintplex-Labs/anything-llm · error

No Ollama image generation model was set.

Error message

No Ollama image generation model was set.

What it means

The OllamaImageGenerator constructor throws immediately when IMAGE_GEN_MODEL_PREF is unset or empty. There is no default model for Ollama image generation, so the shared IMAGE_GEN_MODEL_PREF must hold the model tag exposed by the Ollama instance; it is passed as `model` to every images.generate call. Fails fast at instantiation.

Solutions

  1. Set IMAGE_GEN_MODEL_PREF to an image-capable model tag available in your Ollama build.
  2. Confirm the model id with `ollama list` / the Ollama API before configuring.
  3. Restart the server / recreate the container after saving.
  4. Remember the variable is shared across image engines — keep it valid for whichever engine is active.

Example fix

# .env — before
IMAGE_GEN_ENGINE=ollama
IMAGE_GEN_OLLAMA_BASE_PATH=http://localhost:11434

# .env — after
IMAGE_GEN_ENGINE=ollama
IMAGE_GEN_OLLAMA_BASE_PATH=http://localhost:11434
IMAGE_GEN_MODEL_PREF=<ollama-image-model-tag>
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.IMAGE_GEN_MODEL_PREF) {
  throw new Error(
    "Ollama image engine selected but IMAGE_GEN_MODEL_PREF is missing."
  );
}
const { OllamaImageGenerator } = require("server/utils/ImageGenerators/ollama");
const generator = new OllamaImageGenerator();

Type guard

function hasImageModelPref(env = process.env) {
  return (
    typeof env.IMAGE_GEN_MODEL_PREF === "string" &&
    env.IMAGE_GEN_MODEL_PREF.length > 0
  );
}

Try / catch

try {
  new OllamaImageGenerator();
} catch (err) {
  if (err.message.includes("Ollama image generation model")) {
    // prompt the user to select an image model available in their Ollama build
  }
}

Prevention

When it happens

Trigger: Selecting the Ollama image engine without setting IMAGE_GEN_MODEL_PREF; the variable was cleared when switching image engines (it is shared across engines); .env edited but the process not restarted.

Common situations: Users who configured only IMAGE_GEN_OLLAMA_BASE_PATH; switching engines and leaving IMAGE_GEN_MODEL_PREF empty because the previous engine had its own default.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@20f6d3546c (2026-08-18). Data as JSON: /api/errors/bb119c8a2288befb. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/ImageGenerators/ollama/index.js:8

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

class OllamaImageGenerator extends BaseImageGenerator {
  constructor() {
    if (!process.env.IMAGE_GEN_OLLAMA_BASE_PATH)
      throw new Error("No Ollama image generation base path was set.");
    if (!process.env.IMAGE_GEN_MODEL_PREF)
      throw new Error("No Ollama image generation model was set.");
    const { OpenAI: OpenAIApi } = require("openai");
    // Ollama serves image generation through its OpenAI-compatible `/v1`
    // endpoint (experimental, macOS only).
    const basePath = process.env.IMAGE_GEN_OLLAMA_BASE_PATH.replace(/\/+$/, "");
    super({
      client: new OpenAIApi({
        baseURL: `${basePath}/v1`,
        apiKey: process.env.IMAGE_GEN_OLLAMA_AUTH_TOKEN || "ollama",
      }),
      model: process.env.IMAGE_GEN_MODEL_PREF,
      className: "OllamaImageGenerator",
    });
  }

  /**
   * Ollama's OpenAI-compatible image endpoint does not implement image editing
   * or accept reference images in any form, so there is nothing we can do with
   * them - we surface a descriptive error instead of silently dropping them and

View on GitHub (pinned to 20f6d3546c)