{"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":"validation","errorClass":"Error","httpStatus":null,"severity":"critical","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/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/ImageGenerators/openRouter/index.js#L1-L31","documentation":"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.","triggerScenarios":"Instantiating new OpenRouterImageGenerator() when process.env.IMAGE_GEN_MODEL_PREF is unset or empty.","commonSituations":"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.","solutions":["Set IMAGE_GEN_MODEL_PREF to a valid OpenRouter image model id in .env.","Verify the model id exists and supports image generation on openrouter.ai/models.","Restart the server after setting the variable.","Remember IMAGE_GEN_MODEL_PREF is shared across image providers."],"exampleFix":"# before\nIMAGE_GEN_PROVIDER=openrouter\nIMAGE_GEN_OPENROUTER_API_KEY=sk-or-v1-xxxx\n# (no model)\n\n# after\nIMAGE_GEN_PROVIDER=openrouter\nIMAGE_GEN_OPENROUTER_API_KEY=sk-or-v1-xxxx\nIMAGE_GEN_MODEL_PREF=openai/gpt-image-1","handlingStrategy":"validation","validationCode":"function hasImageModel() {\n  return typeof process.env.IMAGE_GEN_MODEL_PREF === 'string'\n    && process.env.IMAGE_GEN_MODEL_PREF.trim().length > 0;\n}\nif (!hasImageModel()) {\n  throw new Error('Set IMAGE_GEN_MODEL_PREF before using OpenRouter image generation.');\n}","typeGuard":"function isImageModelSet() {\n  return !!process.env.IMAGE_GEN_MODEL_PREF && process.env.IMAGE_GEN_MODEL_PREF.trim().length > 0;\n}","tryCatchPattern":"try {\n  generator = new OpenRouterImageGenerator();\n} catch (e) {\n  if (/No OpenRouter image generation model/.test(e.message)) {\n    throw new Error('Set IMAGE_GEN_MODEL_PREF to a valid OpenRouter image model and restart.');\n  }\n  throw e;\n}","preventionTips":["Set IMAGE_GEN_MODEL_PREF to a model that exists and supports images on OpenRouter.","IMAGE_GEN_MODEL_PREF is shared across image providers.","Validate required env vars at startup.","Restart after .env changes."],"tags":["openrouter","image-generation","configuration","missing-env","constructor"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}