Mintplex-Labs/anything-llm · error
No OpenRouter image generation model was set.
Error message
No OpenRouter image generation model was set.
What it means
OpenRouterImageGenerator's constructor throws when process.env.IMAGE_GEN_MODEL_PREF is unset or empty. Unlike the API key, this variable is shared across image generation providers, so it must be set even though it is not OpenRouter-specific.
Solutions
- Set IMAGE_GEN_MODEL_PREF to an image-capable OpenRouter model slug in .env and restart
- Pick the model via the app's image generation settings UI so the variable is persisted
- Confirm the variable is non-empty at runtime (console.log(process.env.IMAGE_GEN_MODEL_PREF))
- For Docker, pass the variable into the container environment
Example fix
# before (.env) IMAGE_GEN_OPENROUTER_API_KEY=sk-or-v1-... # after (.env) IMAGE_GEN_OPENROUTER_API_KEY=sk-or-v1-... IMAGE_GEN_MODEL_PREF=google/gemini-2.5-flash-image-preview
Defensive patterns
Strategy: validation
Validate before calling
if (!process.env.IMAGE_GEN_MODEL_PREF) {
throw new Error('Set IMAGE_GEN_MODEL_PREF to an image-capable model before enabling the engine.');
} Try / catch
try {
generator = new OpenRouterImageGenerator();
} catch (err) {
if (err.message.includes('image generation model')) {
// prompt the user to pick a model in settings
}
throw err;
} Prevention
- Enforce model selection in the settings UI before the engine can be saved as active
- Remember IMAGE_GEN_MODEL_PREF is shared across image providers — always re-set it when switching engines
- Validate env at boot and report all missing image-gen variables together
When it happens
Trigger: OpenRouter image engine selected but IMAGE_GEN_MODEL_PREF was never set in the environment; the variable was cleared when switching from a different image provider that also uses it.
Common situations: User set the OpenRouter key but never chose a model; .env edited while server running (stale env); deployment pipeline dropping the variable; empty string value after a settings save.
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
- No OpenRouter image generation API key was set.
- No Deepgram API key was set.
- No Groq API key was set.
- No Lemonade base path was set.
- OpenRouter returned no image data.
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/eeda78e441b776c3.
Report an issue: GitHub.
Appendix: 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 3aec848f28)