{"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":"Error","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/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/ImageGenerators/openRouter/index.js#L1-L23","documentation":"Thrown by OpenRouterImageGenerator._extractImageBuffer when the dataUrl argument is falsy. _extractImageBuffer splits a data-URL (data:image/png;base64,...) on the comma and base64-decodes the tail, so a missing/empty dataUrl means there is nothing to decode. This is the OpenRouter-specific image extraction path, separate from the BaseImageGenerator b64/url handling.","triggerScenarios":"Calling _extractImageBuffer with undefined/null/'' when the OpenRouter image-generation response did not include the expected data-URL image field — e.g. the provider returned an error envelope, an empty data array, content moderation, or a different response shape than expected.","commonSituations":"OpenRouter routing to a backing model that failed silently; content policy filtering the image; response shape change in the OpenRouter image API; the model selected (IMAGE_GEN_MODEL_PREF) not actually being an image model.","solutions":["Inspect the full OpenRouter image-generation response object before calling _extractImageBuffer to confirm the data-URL field exists.","Confirm IMAGE_GEN_MODEL_PREF is an image-capable model on OpenRouter.","Check for content-moderation fields in the response that suppressed the image.","Handle the missing field upstream and surface the provider's error message instead of calling _extractImageBuffer."],"exampleFix":"// before\n_extractImageBuffer(resp?.data?.[0]?.url)\n\n// after: guard before extracting\nconst dataUrl = resp?.data?.[0]?.url;\nif (!dataUrl) {\n  throw new Error(`OpenRouter returned no image data. Response: ${JSON.stringify(resp?.data ?? resp).slice(0, 300)}`);\n}\nreturn _extractImageBuffer(dataUrl);","handlingStrategy":"type-guard","validationCode":"function hasDataUrl(resp) {\n  const url = resp?.data?.[0]?.url || resp?.data?.[0]?.b64_json;\n  return typeof url === 'string' && url.length > 0;\n}\nconst resp = await callOpenRouterImage();\nif (!hasDataUrl(resp)) {\n  throw new Error(`OpenRouter returned no image. Full response: ${JSON.stringify(resp).slice(0, 300)}`);\n}","typeGuard":"/** @param {unknown} r */\nfunction isOpenRouterImageResponse(r) {\n  const img = r && typeof r === 'object' && Array.isArray(r.data) ? r.data[0] : null;\n  return !!img && typeof img === 'object' && (typeof img.url === 'string' || typeof img.b64_json === 'string');\n}","tryCatchPattern":"try {\n  return generator._extractImageBuffer(dataUrl);\n} catch (e) {\n  if (/OpenRouter returned no image data/.test(e.message)) {\n    throw new Error('OpenRouter produced no image — check IMAGE_GEN_MODEL_PREF and moderation status');\n  }\n  throw e;\n}","preventionTips":["Inspect the full OpenRouter image response before extracting the buffer.","Confirm IMAGE_GEN_MODEL_PREF is an image model on OpenRouter.","Check for content-moderation fields that suppress the image.","Guard with a type check so the error carries the actual response for diagnosis."],"tags":["openrouter","image-generation","response-shape","data-integrity","provider-compat"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}