Automated AI Image Creation using Gemini and External APIs - n8n Workflow

Deploy this powerful n8n workflow template to automate AI image generation from chat prompts using Google Gemini for prompt engineering and external services for image creation. This n8n node flow is highly customizable.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Marketing professionals needing quick, high-quality visual content creation.
Developers looking for robust n8n templates integrating Langchain and external AI APIs.
Automation specialists seeking advanced examples of prompt engineering within an n8n workflow.
Content creators who need a scalable, automated solution for generating custom images.

Overview

This sophisticated n8n workflow solves the challenge of turning simple, conversational text requests into detailed, high-quality images ready for deployment or storage. By leveraging Google Gemini for advanced prompt engineering, this automation ensures that the resulting image generation prompt adheres to best practices (like cinematic lighting, specific aspect ratios, and text integration), significantly boosting the quality of the final output from the external image API. This complete n8n template provides a plug-and-play solution, demonstrating how to handle user input via an n8n trigger, process complex data using code nodes, and interact with external services via the HTTP Request n8n node, making it an essential tool for any AI-driven operation.

How it Works

This n8n workflow starts with a communication-based n8n trigger, typically a chat message.


  1. Input Trigger: The process begins when a user sends a message, captured by the When chat message received n8n trigger.

  2. Configuration: The Fields - Set Values n8n node sets the desired output parameters (defaulting to 1080x1920 resolution and the 'flux' model).

  3. Prompt Engineering: The user's input is passed to the AI Agent - Create Image From Prompt (a Langchain Agent powered by the Google Gemini Chat Model). This agent uses a highly detailed system prompt to transform the simple input into a structured, optimized JSON object containing the technical image prompt.

  4. Data Cleanup: The Code - Clean Json n8n node meticulously parses the text output from the AI agent, which can often be messy, ensuring only clean, usable prompt text is extracted.

  5. Preparation: The Code - Get Prompt n8n node takes the cleaned prompts, iterates through them, and structures the final request payload, integrating the previously defined width/height parameters.

  6. Filename Generation: The Code - Set Filename n8n node generates sequential filenames (e.g., images_001.png) for the resulting image file.

  7. Image Generation: The HTTP Request - Create Image n8n node uses the optimized prompt and configured settings to call the external image generation API (Pollinations.ai), fetching the resulting image data.

  8. Output: Finally, the generated image data is sent either back to the user via the disabled Telegram Response n8n node or saved to local disk via the disabled Save Image To Disk n8n node. Users must activate their preferred output n8n node.

Installation Guide

To set up this powerful n8n workflow, follow these steps:


  1. Import: Download the provided JSON data and import it directly into your n8n instance.

  2. Credentials: Set up the required credentials for the Google Gemini Chat Model (for the AI Agent), Telegram Response (if using Telegram output), and ensure your n8n instance has access to the directory defined in the Save Image To Disk n8n node (if using local storage).

  3. API Keys: No external API keys are strictly necessary for the Pollinations.ai HTTP call based on the URL structure, but ensure you have the appropriate access configured for the Gemini model.

  4. Customization: Review the Fields - Set Values n8n node to adjust the default image width, height, or model (supported options include 'flux', 'kontext', 'turbo', 'gptimage').

  5. Output Selection: Enable either the Telegram Response n8n node or the Save Image To Disk n8n node to define where the resulting image should be delivered.

  6. Activation: Activate the n8n workflow and test by sending a prompt to the configured chat n8n trigger.

Node Details

When chat message received (n8n trigger): This is the initial n8n trigger point. It captures user input from a chat interface, acting as the dynamic starting parameter for the entire n8n workflow.
Fields - Set Values (n8n node): Defines global variables for the workflow, specifically setting image size (1080x1920) and the image generation model ('flux').
AI Agent - Create Image From Prompt (Langchain n8n node): This core step orchestrates the prompt engineering. It uses Google Gemini and a structured system prompt template to convert simple user requests into highly technical, formatted AI prompts ready for generation.
Code - Clean Json (n8n node): Executes custom JavaScript to stabilize the output from the AI agent, specifically cleaning up surrounding text to reliably extract the essential JSON structure containing the image_prompt array.
Code - Get Prompt (n8n node): Custom code that formats the clean prompt into the exact JSON structure required by the external API call, merging user-defined settings with image generation parameters.
HTTP Request - Create Image (n8n node): The action node that executes the image generation. It sends the carefully crafted prompt to the Pollinations.ai API URL, fetching the binary image data in response. This n8n node handles the crucial API communication.


  • Telegram Response / Save Image To Disk (n8n nodes): These nodes handle the final delivery of the generated image, either by sending the binary data back to a Telegram chat or writing it to the local file system using the sequential filename generated by a prior n8n node.

Related n8n Workflows

Free

Nodes: 10 Nodes
Updated: December 26 2025
View all
Created by

Agent Circle - A growing marketplace of AI agents, workflows, and toolkits — built to help teams automate smarter and scale faster

Featured*