How to Generate AI Images with Google Nano Banana 2 in n8n
This guide walks you through setting up an automated AI image generation workflow in your Awesomate n8n instance using Google’s Nano Banana 2 model (Gemini 3.1 Flash Image). By the end, you’ll have a working workflow that can generate images from text prompts — and you’ll know how to extend it for your own use cases.
What is Nano Banana 2?
Nano Banana 2 is Google’s latest AI image generation model (officially called Gemini 3.1 Flash Image). You give it a text description (called a “prompt”) and it creates a high-quality image — anything from photorealistic scenes to illustrations, product mockups, infographics, icons, and more.
It can also edit existing images — you upload a photo and tell it what to change using plain English.
The name “Nano Banana” is Google’s internal codename for Gemini’s native image generation capabilities. There are three models in the family:
| Model | ID | Best For |
|---|---|---|
| Nano Banana 2 (newest) | gemini-3.1-flash-image-preview |
Best value — Pro-level quality at Flash speed (~$0.07/image) |
| Nano Banana Pro | gemini-3-pro-image-preview |
Highest quality — best text rendering, 4K, complex compositions (~$0.13/image) |
| Nano Banana (original) | gemini-2.5-flash-image |
Fastest & cheapest — great for quick drafts and thumbnails (~$0.04/image) |
Why Use It in n8n?
By connecting Nano Banana to your n8n workflows inside Awesomate, you can automate image creation as part of a larger process. For example:
- Automatically generate product images when a new item is added to your store
- Create social media graphics on a schedule
- Generate blog post hero images from article titles
- Build a workflow where a client fills in a form and receives a custom image
- Auto-generate icons, thumbnails, or marketing assets in bulk
What You’ll Need Before You Start
- A Google account (any Gmail account works)
- Access to your Awesomate n8n instance
- About 15 minutes to set everything up
💰 Costs — Good News
Unlike video generation, Nano Banana 2 has a free tier for the original Nano Banana model (
gemini-2.5-flash-image). For the newer models, a paid API key is required.Current pricing per image at standard 1024×1024 resolution:
- Nano Banana (original): ~$0.039/image (has free tier!)
- Nano Banana 2: ~$0.067/image (paid tier required)
- Nano Banana Pro: ~$0.134/image (paid tier required)
Higher resolutions cost more — 4K images are ~$0.15 each. The free tier for the original model allows hundreds of images per day, making it perfect for testing.
Part 1: Get Your Google Gemini API Key
The Nano Banana models are accessed through Google’s Gemini API. You need an API key to use them.
Step-by-Step: Create Your API Key
- Go to Google AI Studio. Open your browser and navigate to
aistudio.google.com. - Sign in with your Google account.
- Find the API Key section. Look for “Get API key” in the left-hand sidebar or top navigation.
- Create a new key. Click “Create API key in new project”. Google will create a new cloud project for you automatically.
- Copy your API key. It starts with
AIza. Save it somewhere safe — you’ll need it shortly.
🔒 Security Tip: Treat your API key like a password. Never share it publicly, post it in forums, or commit it to public code repositories. Anyone with your key can generate images and you’ll be charged.
Part 2: Enable Billing (Optional but Recommended)
The original Nano Banana model (gemini-2.5-flash-image) works on the free tier — you can start generating images immediately.
To use Nano Banana 2 (gemini-3.1-flash-image-preview) or Nano Banana Pro (gemini-3-pro-image-preview), you need to enable billing.
Step-by-Step: Set Up Billing
- Go to Google Cloud Console at
console.cloud.google.com. - Select your project from the top dropdown — find the project created when you made your API key.
- Navigate to Billing in the left sidebar. If prompted, click “Link a billing account”.
- Create a billing account by following the prompts to add your card details. Google may offer $300 in free credits for new accounts.
- Confirm billing is linked. Your project should now show as linked to a billing account.
💡 Tip: If you just want to test and learn, start with the original Nano Banana model on the free tier. You can upgrade to Nano Banana 2 later once you’re comfortable with how it all works.
Part 3: Build the Image Generation Workflow in n8n
Unlike video generation (which takes minutes and requires polling), image generation with Nano Banana is fast and simple — you send a request and get the image back immediately. This makes the workflow much simpler.
The process is:
- Send your image prompt to Google
- Receive the image data back in the response (as base64-encoded data)
- Convert and save the image
Node 1: Trigger
You can start this workflow however suits your use case:
- Manual Trigger — for testing, just click “Execute Workflow”
- Webhook Trigger — so another system can call it with a prompt
- Schedule Trigger — to generate images on a timed schedule
- Form Trigger — so someone can type in a prompt via a web form
For testing, use the Manual Trigger node. Simply add it to your canvas.
Node 2: Set Node — Define Your Prompt
Add a Set node after your trigger. Configure it with these two fields:
Field 1 — prompt (String)
Your image description. Be descriptive! Example:
A professional product photo of a handmade ceramic coffee mug on a wooden table, morning light streaming through a window, shallow depth of field, warm tones, lifestyle photography style.
Field 2 — model (String)
Set this to one of the following:
| Model Name | Cost | Best For |
|---|---|---|
gemini-2.5-flash-image |
~$0.039/image (free tier available) | Testing, quick drafts, thumbnails |
gemini-3.1-flash-image-preview |
~$0.067/image (paid only) | Best value for quality — recommended |
gemini-3-pro-image-preview |
~$0.134/image (paid only) | Highest quality, best text in images |
💡 Recommendation: Start with
gemini-2.5-flash-imagewhile testing (it’s free!). Once you’re happy with your prompts, switch togemini-3.1-flash-image-previewfor the best quality-to-cost ratio.
Node 3: HTTP Request — Generate the Image
Add an HTTP Request node. This sends your prompt to Google and receives the image back.
Configure the HTTP Request node:
- Method:
POST URL:
https://generativelanguage.googleapis.com/v1beta/models/{{ $json.model }}:generateContent(This uses an expression to pull in the model name from your Set node.)
Authentication: None (we’ll pass the key as a query parameter)
Send Query Parameters: ON
- Name:
key| Value:YOUR_API_KEY_HERE
- Name:
Send Headers: ON
- Name:
Content-Type| Value:application/json
- Name:
Send Body: ON | Body Content Type: JSON | Specify Body: Using JSON
Paste this as the JSON body:
{
"contents": [
{
"parts": [
{
"text": "{{ $json.prompt }}"
}
]
}
],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"]
}
}
ℹ️ Key Detail: The
responseModalitiesfield is critical — it tells Google you want an image back, not just text. Without it, you’ll only get a text response.⚡ Speed: Unlike video generation, this returns almost immediately — typically within 4–10 seconds. No polling loop needed!
Node 4: Code Node — Extract the Image
The response from Google contains the image as base64-encoded data inside a JSON structure. We need to extract it and convert it to a usable image file.
Add a Code node after the HTTP Request. Set the Language to JavaScript and paste this code:
// Find the image part in the response
const parts = $input.first().json.candidates[0].content.parts;
let imageData = null;
let textResponse = '';
for (const part of parts) {
if (part.inlineData) {
imageData = part.inlineData.data;
}
if (part.text) {
textResponse = part.text;
}
}
if (imageData) {
// Convert base64 to binary buffer
const binaryData = Buffer.from(imageData, 'base64');
return [{
json: {
success: true,
textResponse: textResponse,
mimeType: 'image/png',
fileName: 'generated-image.png'
},
binary: {
data: await this.helpers.prepareBinaryData(binaryData, 'generated-image.png', 'image/png')
}
}];
} else {
return [{
json: {
success: false,
textResponse: textResponse,
error: 'No image was returned in the response'
}
}];
}
What this does: This code digs into Google’s response, finds the image data, converts it from base64 into an actual image file, and passes it along as a binary file that other n8n nodes can work with — save to disk, email, upload, and more.
Node 5: What to Do With the Image
After the Code node, the generated image is available as a binary file called data. Connect any of these nodes next:
- Write Binary File — Save it to your server
- Google Drive — Upload it to a specific folder
- Send Email — Attach it to an automated email
- Slack / Discord — Post it to a channel
- HTTP Request — Upload it to any API (WordPress, social media, etc.)
- Respond to Webhook — Return it as a response if you started with a Webhook trigger
Complete Workflow Summary
[Trigger]
↓
[Set Node] — Define prompt + model name
↓
[HTTP Request] — POST to generate image (returns in ~5 seconds)
↓
[Code Node] — Extract base64 image → binary file
↓
[Next steps: Save, email, upload, etc.]
That’s it — much simpler than video generation because there’s no waiting or polling loop.
Import the Starter Workflow
Instead of building this from scratch, you can import a ready-made starter workflow directly into your n8n instance.
How to import:
- Copy the entire JSON block below
- Open your n8n instance and create a new workflow
- Press
Ctrl+V(orCmd+Von Mac) to paste it onto the canvas - All nodes and connections will appear automatically
- Replace
YOUR_GEMINI_API_KEY_HEREin the HTTP Request node with your actual API key
⚠️ Important: You MUST replace the placeholder API key before running the workflow.
{
"name": "Nano Banana 2 - Generate AI Image",
"nodes": [
{
"parameters": {},
"id": "b1c2d3e4-0001-4000-8000-000000000001",
"name": "Manual Trigger",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [0, 0]
},
{
"parameters": {
"mode": "manual",
"duplicateItem": false,
"assignments": {
"assignments": [
{
"id": "prompt-field",
"name": "prompt",
"value": "A professional product photo of a handmade ceramic coffee mug on a wooden table, morning light streaming through a window, shallow depth of field, warm tones, lifestyle photography style.",
"type": "string"
},
{
"id": "model-field",
"name": "model",
"value": "gemini-2.5-flash-image",
"type": "string"
}
]
}
},
"id": "b1c2d3e4-0002-4000-8000-000000000002",
"name": "Set Prompt & Model",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [220, 0],
"notesInFlow": true,
"notes": "Edit the prompt and model here. Use gemini-2.5-flash-image (free) or gemini-3.1-flash-image-preview (best quality, paid)."
},
{
"parameters": {
"method": "POST",
"url": "=https://generativelanguage.googleapis.com/v1beta/models/{{ $json.model }}:generateContent",
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "key",
"value": "YOUR_GEMINI_API_KEY_HERE"
}
]
},
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"contents\": [\n {\n \"parts\": [\n {\n \"text\": \"{{ $json.prompt }}\"\n }\n ]\n }\n ],\n \"generationConfig\": {\n \"responseModalities\": [\"TEXT\", \"IMAGE\"]\n }\n}",
"options": {}
},
"id": "b1c2d3e4-0003-4000-8000-000000000003",
"name": "Generate Image",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [440, 0],
"notesInFlow": true,
"notes": "Sends the prompt to Google Gemini. Returns the image as base64 data in ~5 seconds."
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Extract the image from Google's response\nconst parts = $input.item.json.candidates[0].content.parts;\nlet imageData = null;\nlet textResponse = '';\n\nfor (const part of parts) {\n if (part.inlineData) {\n imageData = part.inlineData.data;\n }\n if (part.text) {\n textResponse = part.text;\n }\n}\n\nif (imageData) {\n const binaryData = Buffer.from(imageData, 'base64');\n \n return [{\n json: {\n success: true,\n textResponse: textResponse,\n mimeType: 'image/png',\n fileName: 'generated-image.png'\n },\n binary: {\n data: await this.helpers.prepareBinaryData(binaryData, 'generated-image.png', 'image/png')\n }\n }];\n} else {\n return [{\n json: {\n success: false,\n textResponse: textResponse,\n error: 'No image was returned in the response'\n }\n }];\n}"
},
"id": "b1c2d3e4-0004-4000-8000-000000000004",
"name": "Extract Image",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [660, 0],
"notesInFlow": true,
"notes": "Converts the base64 image data into a binary file you can save, email, or upload."
}
],
"connections": {
"Manual Trigger": {
"main": [[{"node": "Set Prompt & Model", "type": "main", "index": 0}]]
},
"Set Prompt & Model": {
"main": [[{"node": "Generate Image", "type": "main", "index": 0}]]
},
"Generate Image": {
"main": [[{"node": "Extract Image", "type": "main", "index": 0}]]
}
},
"settings": {"executionOrder": "v1"},
"pinData": {}
}
💡 After importing: The workflow comes with a sample prompt and the free-tier model. Edit the “Set Prompt & Model” node to change the prompt. To use Nano Banana 2 (requires billing), change the model value from
gemini-2.5-flash-imagetogemini-3.1-flash-image-preview.
Optional Settings You Can Customise
Aspect Ratio
By default, images are generated at approximately 1024×1024 (square). Request different aspect ratios by adding an imageConfig section to your generationConfig:
{
"contents": [{"parts": [{"text": "{{ $json.prompt }}"}]}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"],
"imageConfig": {
"aspectRatio": "16:9"
}
}
}
Supported aspect ratios:
| Ratio | Use Case |
|---|---|
1:1 |
Instagram feed posts, profile pictures |
16:9 |
Website headers, YouTube thumbnails |
9:16 |
Instagram Stories, TikTok |
4:3 / 3:4 |
General landscape/portrait |
4:1 / 1:4 |
Ultra-wide banners |
Resolution (Nano Banana 2 and Pro only)
Nano Banana 2 supports resolutions from 512px up to 4K. The default (1024px) is great for most use cases. For print or large displays, add a resolution field:
"imageConfig": {
"aspectRatio": "16:9",
"outputOptions": {
"outputImageResolution": "RESOLUTION_2048"
}
}
Options: RESOLUTION_512, RESOLUTION_1024 (default), RESOLUTION_2048, RESOLUTION_4096.
Number of Images
Request multiple variations in a single call:
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"],
"candidateCount": 4
}
This generates up to 4 different images from the same prompt — useful for picking the best option. Note: you’re charged for each image generated.
Image Editing (Upload + Edit)
One of the most powerful features of Nano Banana is the ability to edit existing images. You upload an image along with text instructions and it modifies the image accordingly.
The JSON body for editing looks like this:
{
"contents": [
{
"parts": [
{
"text": "Change the background to a tropical beach at sunset"
},
{
"inlineData": {
"mimeType": "image/png",
"data": "BASE64_IMAGE_DATA_HERE"
}
}
]
}
],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"]
}
}
This is an advanced use case — if you’d like help building an image editing workflow, reach out to the Awesomate team.
Tips for Writing Great Image Prompts
- Be specific about the subject. Instead of “a dog”, say “a golden retriever puppy sitting in a field of wildflowers.”
- Describe the style. Use terms like “photorealistic”, “watercolour painting”, “flat illustration”, “3D render”, “pencil sketch”, “minimalist icon”.
- Mention lighting and mood. Words like “golden hour”, “dramatic lighting”, “soft natural light”, “moody”, “bright and airy” make a big difference.
- Specify the composition. Use terms like “close-up”, “wide shot”, “aerial view”, “portrait orientation”, “centred”, “rule of thirds”.
- Include quality cues. Phrases like “high resolution”, “professional photography”, “shallow depth of field”, “studio lighting” help push quality up.
- Say what you don’t want. Add phrases like “no text”, “no watermark”, “no people” to avoid unwanted elements.
- Nano Banana excels at text in images. If you need text rendered in the image (logos, signs, posters), it handles this exceptionally well — just include the exact text in your prompt.
Example — social media graphic:
A modern, clean Instagram post design for a coffee shop called “Bean & Brew”. The background is a warm beige with subtle coffee bean illustrations. Large bold text reads “FRESHLY ROASTED” in a dark brown serif font. Below that in smaller text: “Every morning. Every cup.” Professional graphic design style, 1:1 aspect ratio.
Example — product photo:
A premium flat lay photo of a skincare product bottle with a minimalist white label on a marble surface. Surrounded by small green leaves and water droplets. Soft, diffused natural light from above. Clean, luxurious aesthetic. Professional product photography.
Storing Your API Key Securely in n8n
Rather than pasting your API key directly into each HTTP Request node, store it as a reusable credential:
- Go to Credentials in the n8n left sidebar and click “Add Credential.”
- Choose “Header Auth” as the credential type.
- Set the Name to
x-goog-api-keyand the Value to your Gemini API key. - In each HTTP Request node, set Authentication to “Generic Credential Type” → “Header Auth” and select your saved credential.
If you use this method, remove the key query parameter from the HTTP Request node — the key will be sent as a header automatically.
Troubleshooting
Error: “403 Forbidden” or “Permission Denied”
If you’re using Nano Banana 2 or Pro, billing needs to be enabled. If you’re using the original Nano Banana model, this usually means your API key is invalid — try regenerating it.
Error: “400 Bad Request”
Check your JSON body for syntax errors. The most common issue is a missing responseModalities field — without it, the model won’t return an image.
Error: “429 Too Many Requests”
You’ve hit a rate limit. The free tier allows around 10 requests per minute. Wait a moment and try again, or upgrade to the paid tier for higher limits.
No image in the response (only text)
Make sure "responseModalities": ["TEXT", "IMAGE"] is included in your generationConfig.
Image quality is poor or doesn’t match prompt
Try being more specific in your prompt. Adding style cues like “professional photography”, “8K”, “detailed” can help. Also consider upgrading to Nano Banana 2 for better quality.
API key not valid / Invalid API key
Make sure you copied the full key including the AIza prefix. Trailing spaces can also cause issues. Try regenerating a new key in Google AI Studio.
Error: “The model does not support image generation”
You may have the model name wrong. Double-check you’re using one of: gemini-2.5-flash-image, gemini-3.1-flash-image-preview, or gemini-3-pro-image-preview.
Managing Costs
- Start with the free tier using
gemini-2.5-flash-image— it’s genuinely free and great for learning - Nano Banana 2 at ~$0.067/image means 100 images costs about $6.70 — very affordable for most use cases
- Use the default 1024px resolution unless you specifically need high-res — 4K images cost 2–3× more
- Perfect your prompts in Google AI Studio before automating them in n8n to avoid wasting money on bad prompts
- Set up budget alerts at
console.cloud.google.comunder Billing → Budgets & Alerts - For bulk generation, consider the Batch API for a 50% discount (at the expense of slower delivery)
What to Do Next
Once you have the basic workflow running, here are some ideas for extending it:
- Save to Google Drive — Automatically save each image to a specific folder
- Post to social media — Upload directly to Instagram, Facebook, or LinkedIn
- AI-powered prompts — Use an AI node to write image prompts based on your blog posts or product descriptions
- Bulk generation — Loop through a spreadsheet of prompts to batch-generate dozens of images
- Image editing pipeline — Upload customer photos and automatically apply edits
- Email marketing — Generate unique hero images for each email campaign
- Combine with Veo 3 — Generate a still image first, then use it as the starting frame for a Veo 3 video
Need Help?
If you get stuck at any point:
- Join the Awesomate weekly n8n webinar for live Q&A — recordings available at
awesomate.helpdocsite.com/webinars - Reach out to the Awesomate support team via your member portal
- Check the Google Gemini API documentation at
ai.google.dev/gemini-api/docs/image-generation
Happy automating! 🎨