Automating AI Workflows with n8n and Gemini API
Adding AI to an existing process usually means writing glue code, then maintaining it forever. n8n sidesteps that: an open-source workflow automation platform, self-hostable, with connectors for more than 400 services. Paired with Google's Gemini API, it becomes a place to run practical AI workflows without a codebase to babysit.
What we'll set up:
- How to set up n8n locally with Docker
- Calling the Gemini API using HTTP Request nodes
- Using AI Agent nodes for more advanced automation
- Real-world use cases: email summarization, scheduled reports
- Common errors and how to fix them
This guide is ideal for developers who want to add AI capabilities to their workflows without heavy coding, or anyone coming from Zapier/Make looking for a more flexible, self-hostable alternative.
What is n8n? — Why It's Worth Your Attention
n8n (short for "nodemation") is an open-source automation platform originally from Germany. While it sits in the same category as Zapier or Make, it stands out in several key ways:
- Self-hostable: Your data stays on your own server or laptop
- Code-friendly: JavaScript/Python Code nodes for complex logic
- Built-in AI nodes: Native support for LLMs like Gemini, OpenAI, Claude
- Free to start: Self-hosted version is completely free
As of 2026, n8n ships with a full suite of AI-oriented nodes — AI Agent, Memory, Vector Store, and more — making it possible to build RAG pipelines entirely through a visual interface, no coding required.
Setting Up Your Environment
Running n8n Locally with Docker
# Requires Docker to be installed first
docker run -it --rm \
--name n8n \
-p 5678:5678 \
-v ~/.n8n:/home/node/.n8n \
n8nio/n8nOpen http://localhost:5678 in your browser to reach the setup screen. You'll be prompted to create an admin account on first run.
Getting a Gemini API Key
- Go to Google AI Studio and sign in
- Click Get API key in the left sidebar
- Hit Create API key to generate a new key
- Copy it somewhere safe — we'll refer to it as
YOUR_GEMINI_API_KEY
API keys are free with any Google account. The free tier allows up to 15 requests per minute and 1,500 requests per day with Gemini 2.5 Flash.
For a more in-depth setup walkthrough, check out the Gemini API Quickstart Guide.
The Basics: Calling Gemini API with an HTTP Request Node
The simplest way to integrate Gemini into n8n is via the HTTP Request node. Since Gemini's API is a standard REST API, any HTTP client — including n8n's built-in node — can call it directly.
Step-by-Step Workflow Setup
Step 1: Create a new workflow
In the n8n dashboard, click New Workflow and give it a name (e.g., Gemini Test).
Step 2: Add a Manual Trigger node
Click +, search for Manual Trigger, and add it. This lets you start the workflow by clicking a button.
Step 3: Add and configure an HTTP Request node
Click + to the right of the trigger node and add an HTTP Request node. Configure it as follows:
Method: POST
URL: https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=YOUR_GEMINI_API_KEY
Body Content Type: JSON
Body:
{
"contents": [
{
"parts": [
{
"text": "Explain the future of AI in 100 words."
}
]
}
]
}
Step 4: Run a test
Click Test workflow. You should receive a response from Gemini that looks like this:
// Example response
{
"candidates": [
{
"content": {
"parts": [
{
"text": "The future of AI is deeply collaborative. As models become more capable, they'll take on complex tasks in healthcare, climate science, and education — while humans retain creative direction and emotional judgment. The most transformative shift will be AI systems that reason, adapt, and explain themselves transparently."
}
],
"role": "model"
}
}
]
}Step 5: Extract the text from the response
To use the generated text in downstream nodes, use this expression in n8n's expression editor:
// n8n expression syntax
{{ $json.candidates[0].content.parts[0].text }}Going Further: Using the AI Agent Node with Gemini
With n8n 1.0+, the AI Agent node lets you treat LLMs as high-level reasoning components. You can attach tools (like web search, code execution, or API calls) and let the agent decide when and how to use them.
Setting Up the Gemini Chat Model Node
- Click + and browse to the AI category
- Search for and add Google Gemini Chat Model
- Under Credentials, create a new Google Gemini(PaLM) Api credential
- Paste your API key and save
We recommend gemini-2.5-flash for cost-effective workflows. Switch to gemini-2.5-pro when you need higher reasoning quality.
Real-World Example: Auto-Summarize Emails to Slack
Here's a practical workflow that watches for new emails, summarizes them with Gemini, and posts to Slack:
Gmail Trigger (new email arrives)
↓
AI Agent (Gemini 2.5 Flash)
"Summarize this email in 3 bullet points: {{ $json.snippet }}"
↓
Slack (post summary to #notifications)
Set the AI Agent's System Message to:
You are a business email assistant.
Summarize the email body in no more than 3 bullet points.
If there are action items, add a final line starting with "Action needed:".
Reply in the same language as the email.
This simple workflow can save hours of inbox time each week.
Practical Example: Scheduled AI Reports
Using a Cron trigger, you can have Gemini analyze data from Google Sheets every morning and email you a summary.
Cron (every day at 8:00 AM)
↓
Google Sheets (fetch yesterday's data)
↓
Code node (format data as readable text)
↓
HTTP Request (Gemini API — analyze and summarize)
↓
Gmail (send report to your inbox)
In the HTTP Request body, pass the data like this:
{
"contents": [
{
"parts": [
{
"text": "Analyze the following dataset and identify 3 key trends with recommended actions:\n\n{{ $json.sheetData }}"
}
]
}
],
"generationConfig": {
"temperature": 0.3,
"maxOutputTokens": 1024
}
}A lower temperature value (like 0.3) produces more consistent, fact-based outputs — ideal for analytical reports.
For more advanced automation patterns including CI/CD integration, see Automating Business Workflows with Gemini API — CI/CD Integration and Prompt Tuning Techniques.
Common Errors and Fixes
401 Unauthorized
Your API key is missing, invalid, or expired. Regenerate it in Google AI Studio and update the credential in n8n. For better security, store the key in n8n's credential manager rather than hard-coding it in the URL.
429 Too Many Requests
You've exceeded the free tier rate limit (15 req/min). Add a Wait node between API calls:
HTTP Request → Wait (5 seconds) → Next node
Alternatively, upgrade to a paid Gemini API plan for higher limits.
Empty or Undefined Response
Usually caused by a typo in the model name. Valid model identifiers include gemini-2.5-flash and gemini-2.5-pro. Some models require a -preview suffix — always verify the latest model IDs in Google AI Studio.
Expression Returns Nothing
Make sure the JSON path matches the actual response structure. Use n8n's built-in JSON output view after running a test to inspect the exact structure before writing your expression.
Looking back
The workflow you now have connects n8n to the Gemini API:
- Using HTTP Request nodes to call Gemini directly via REST
- Configuring the AI Agent node for higher-level reasoning tasks
- Practical workflows: email summarization, scheduled reports
- Fixing common errors (401, 429, empty responses)
n8n's strength lies in its ability to keep code minimal while letting you compose complex AI logic visually. Combined with Gemini API's breadth of features — multimodal input, Function Calling, long-context windows — you can automate a wide range of business tasks with relatively little effort.
Start by running n8n locally with Docker, grab a free Gemini API key, and try building a simple test workflow. For more day-to-day automation ideas, the Gemini API Daily Task Automation Guide is full of practical examples to get you started.