{"record":{"id":"e16906a0cfe7eeb6","repo":"n8n-io/n8n","slug":"no-image-data-returned-from-gemini-api","errorCode":null,"errorMessage":"No image data returned from Gemini API","messagePattern":"No image data returned from Gemini API","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/vendors/GoogleGemini/actions/image/edit.operation.ts","lineNumber":215,"sourceCode":"\tconst response: unknown = await apiRequest.call(\n\t\tthis,\n\t\t'POST',\n\t\t`/v1beta/${model}:generateContent`,\n\t\t{\n\t\t\tbody,\n\t\t},\n\t);\n\n\tif (!isGenerateContentResponse(response)) {\n\t\tthrow new Error('Invalid response format from Gemini API');\n\t}\n\n\tconst promises = response.candidates.map(async (candidate) => {\n\t\tconst imagePart = candidate.content.parts.find((part) => 'inlineData' in part);\n\n\t\t// Check if imagePart exists and has inlineData with actual data\n\t\tif (!imagePart?.inlineData?.data) {\n\t\t\tthrow new Error('No image data returned from Gemini API');\n\t\t}\n\n\t\tconst mimeType = imagePart.inlineData.mimeType;\n\t\tconst fileName = getFilenameFromMimeType(mimeType, 'image', 'png');\n\t\tconst bufferOut = Buffer.from(imagePart.inlineData.data, 'base64');\n\t\tconst binaryOut = await this.helpers.prepareBinaryData(bufferOut, fileName, mimeType);\n\t\treturn {\n\t\t\tbinary: {\n\t\t\t\t[outputKey]: binaryOut,\n\t\t\t},\n\t\t\tjson: {\n\t\t\t\t...binaryOut,\n\t\t\t\tdata: undefined,\n\t\t\t},\n\t\t\tpairedItem: { item: i },\n\t\t};\n\t});\n","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/vendors/GoogleGemini/actions/image/edit.operation.ts#L197-L233","documentation":"Thrown by the GoogleGemini image edit operation when the API response passes the shape check (has candidates with content.parts) but no part contains inlineData with actual base64 image data. This means the model processed the request but did not produce an image output — the candidate parts contain only text or other non-image content.","triggerScenarios":"The Gemini model returns a response with valid candidates but the parts array has no element with 'inlineData' or the inlineData.data field is empty/falsy. This occurs when the model responds with text instead of an image (e.g. explaining why it can't edit the image), when the model returns a refusal, or when the model version doesn't support image output modalities.","commonSituations":"Using a text-only Gemini model instead of an image-capable model (gemini-2.5-flash-image-preview); the edit prompt is ambiguous and the model responds with text clarification instead of an image; content safety filter causes the model to refuse image generation; API issue where the image data is stripped from the response.","solutions":["Verify the model ID supports image output — the default fallback is 'models/gemini-2.5-flash-image-preview', but an explicitly selected model may be text-only.","Inspect the response parts — the model may have returned text explaining the issue. Log candidate.content.parts to see what the model actually said.","Refine the edit prompt to be a clear, actionable image editing instruction.","If the content is being safety-filtered, adjust the prompt or input images to comply with Gemini's content policies."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function hasImageData(candidate: { content: { parts: Array<Record<string, unknown>> } }): boolean {\n  const imagePart = candidate.content.parts.find(part => 'inlineData' in part);\n  return Boolean(imagePart && (imagePart as { inlineData?: { data?: string } }).inlineData?.data);\n}","tryCatchPattern":"try {\n  // ... process Gemini response ...\n} catch (error) {\n  if (error instanceof Error && error.message === 'No image data returned from Gemini API') {\n    // The model may have returned text instead of an image — check candidate parts\n    console.warn('No image data. Model may have returned a text response or refusal.');\n    // retry with a clearer prompt or different model\n  }\n  throw error;\n}","preventionTips":["Use an image-capable Gemini model (gemini-2.5-flash-image-preview) rather than a text-only model.","Write clear, unambiguous image editing instructions to avoid the model responding with text instead.","Inspect the response parts during development to understand when the model returns text vs. image.","Adjust prompts that may trigger content safety filters, which can cause the model to refuse image generation."],"tags":["api-response","google-gemini","image-edit","empty-output","model-selection"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}