n8n-io/n8n · error · Error
No image data returned from Gemini API
Error message
No image data returned from Gemini API
What it means
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.
Source
Thrown at packages/@n8n/nodes-langchain/nodes/vendors/GoogleGemini/actions/image/edit.operation.ts:215
const response: unknown = await apiRequest.call(
this,
'POST',
`/v1beta/${model}:generateContent`,
{
body,
},
);
if (!isGenerateContentResponse(response)) {
throw new Error('Invalid response format from Gemini API');
}
const promises = response.candidates.map(async (candidate) => {
const imagePart = candidate.content.parts.find((part) => 'inlineData' in part);
// Check if imagePart exists and has inlineData with actual data
if (!imagePart?.inlineData?.data) {
throw new Error('No image data returned from Gemini API');
}
const mimeType = imagePart.inlineData.mimeType;
const fileName = getFilenameFromMimeType(mimeType, 'image', 'png');
const bufferOut = Buffer.from(imagePart.inlineData.data, 'base64');
const binaryOut = await this.helpers.prepareBinaryData(bufferOut, fileName, mimeType);
return {
binary: {
[outputKey]: binaryOut,
},
json: {
...binaryOut,
data: undefined,
},
pairedItem: { item: i },
};
});
View on GitHub (pinned to 5ac6606e81)
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.
Defensive patterns
Strategy: type-guard
Type guard
function hasImageData(candidate: { content: { parts: Array<Record<string, unknown>> } }): boolean {
const imagePart = candidate.content.parts.find(part => 'inlineData' in part);
return Boolean(imagePart && (imagePart as { inlineData?: { data?: string } }).inlineData?.data);
} Try / catch
try {
// ... process Gemini response ...
} catch (error) {
if (error instanceof Error && error.message === 'No image data returned from Gemini API') {
// The model may have returned text instead of an image — check candidate parts
console.warn('No image data. Model may have returned a text response or refusal.');
// retry with a clearer prompt or different model
}
throw error;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid response format from Gemini API
- A non-empty prompt is required.
- Invalid images parameter format
- There was an error: "The workflow did not return a response"
- There was an error: "The workflow did not return a response"
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/e16906a0cfe7eeb6.
Report an issue: GitHub.