{"record":{"id":"eeda78e441b776c3","repo":"Mintplex-Labs/anything-llm","slug":"no-openrouter-image-generation-model-was-set","errorCode":null,"errorMessage":"No OpenRouter image generation model was set.","messagePattern":"No OpenRouter image generation model was set\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/ImageGenerators/openRouter/index.js","lineNumber":13,"sourceCode":"const { BaseImageGenerator } = require(\"../base\");\n\nclass OpenRouterImageGenerator extends BaseImageGenerator {\n  _extractImageBuffer(dataUrl) {\n    if (!dataUrl) throw new Error(\"OpenRouter returned no image data.\");\n    return Buffer.from(dataUrl.split(\",\").pop(), \"base64\");\n  }\n\n  constructor() {\n    if (!process.env.IMAGE_GEN_OPENROUTER_API_KEY)\n      throw new Error(\"No OpenRouter image generation API key was set.\");\n    if (!process.env.IMAGE_GEN_MODEL_PREF)\n      throw new Error(\"No OpenRouter image generation model was set.\");\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    super({\n      client: new OpenAIApi({\n        baseURL: \"https://openrouter.ai/api/v1\",\n        apiKey: process.env.IMAGE_GEN_OPENROUTER_API_KEY,\n        defaultHeaders: {\n          \"HTTP-Referer\": \"https://anythingllm.com\",\n          \"X-Title\": \"AnythingLLM\",\n        },\n      }),\n      model: process.env.IMAGE_GEN_MODEL_PREF,\n      className: \"OpenRouterImageGenerator\",\n    });\n  }\n\n  // OpenRouter does not expose /images/generations. Its image models return\n  // images through chat completions with the \"image\" output modality, where the\n  // image comes back as a base64 data URL in `message.images`.","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/ImageGenerators/openRouter/index.js#L1-L31","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before (.env)\nIMAGE_GEN_OPENROUTER_API_KEY=sk-or-v1-...\n\n# after (.env)\nIMAGE_GEN_OPENROUTER_API_KEY=sk-or-v1-...\nIMAGE_GEN_MODEL_PREF=google/gemini-2.5-flash-image-preview","handlingStrategy":"validation","validationCode":"if (!process.env.IMAGE_GEN_MODEL_PREF) {\n  throw new Error('Set IMAGE_GEN_MODEL_PREF to an image-capable model before enabling the engine.');\n}","typeGuard":null,"tryCatchPattern":"try {\n  generator = new OpenRouterImageGenerator();\n} catch (err) {\n  if (err.message.includes('image generation model')) {\n    // prompt the user to pick a model in settings\n  }\n  throw err;\n}","preventionTips":["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"],"tags":["openrouter","image-generation","environment-variable","constructor"],"backgroundTag":"missing-env-var","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}