{"record":{"id":"059c36919c7ae293","repo":"Mintplex-Labs/anything-llm","slug":"openrouter-returned-no-image-data","errorCode":null,"errorMessage":"OpenRouter returned no image data.","messagePattern":"OpenRouter returned no image data\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/ImageGenerators/openRouter/index.js","lineNumber":5,"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      }),","sourceCodeStart":1,"sourceCodeEnd":23,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/ImageGenerators/openRouter/index.js#L1-L23","documentation":"AnythingLLM's OpenRouter image generator does not call /images/generations; it calls chat.completions.create with modalities [\"image\",\"text\"] and expects the image as a base64 data URL at choices[0].message.images[0].image_url.url. This error is thrown by _extractImageBuffer when that field is missing, so there is no data URL to decode into a Buffer.","triggerScenarios":"generateImage() or editImage() completes but the response has no message.images array — IMAGE_GEN_MODEL_PREF points to a text-only model, the routed upstream provider ignores the image modality, the model replies with plain text (e.g. a safety refusal), or images is an empty array.","commonSituations":"Setting IMAGE_GEN_MODEL_PREF to a chat model without image output support or a typo'd slug; routing to an OpenRouter provider that strips the modality flag; exhausted/invalid key returning an in-band text error instead of an image.","solutions":["Set IMAGE_GEN_MODEL_PREF to a model that supports the image output modality (e.g. google/gemini-2.5-flash-image-preview) and restart the server","Log completion.choices[0].message.content — a text refusal or error message explains why images is empty","Verify the OpenRouter key is valid and funded, and check the OpenRouter dashboard activity log for the failed request","Wrap generateImage/editImage in try-catch and surface a user-facing message instead of failing on Buffer.from"],"exampleFix":"// before (.env)\nIMAGE_GEN_MODEL_PREF=openai/gpt-4o\n\n// after (.env)\nIMAGE_GEN_MODEL_PREF=google/gemini-2.5-flash-image-preview","handlingStrategy":"validation","validationCode":"// Before generating, confirm the configured model advertises image output\nconst res = await fetch('https://openrouter.ai/api/v1/models');\nconst { data } = await res.json();\nconst model = data.find((m) => m.id === process.env.IMAGE_GEN_MODEL_PREF);\nif (!model || !model.architecture?.output_modalities?.includes('image')) {\n  throw new Error('IMAGE_GEN_MODEL_PREF does not support image output modality');\n}","typeGuard":"function hasImageDataUrl(completion) {\n  const url = completion?.choices?.[0]?.message?.images?.[0]?.image_url?.url;\n  return typeof url === 'string' && url.startsWith('data:');\n}","tryCatchPattern":"try {\n  const { buffer } = await generator.generateImage({ prompt });\n} catch (err) {\n  if (err.message === 'OpenRouter returned no image data.') {\n    // model produced text only — surface message.content or pick an image-capable model\n  }\n  throw err;\n}","preventionTips":["Validate IMAGE_GEN_MODEL_PREF against OpenRouter's /models output_modalities before enabling the engine","Log choices[0].message.content when no image arrives to distinguish refusals from misrouting","Keep image-capable model slugs in a curated allowlist in settings rather than free-text"],"tags":["openrouter","image-generation","chat-completions","modalities","base64"],"backgroundTag":"empty-api-response-field","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"}