How To Connect Google Gemini to n8n

Google’s Gemini AI models have quickly become a powerful alternative to tools like ChatGPT for tasks such as natural language generation, summarization, smart content creation, and more. If you're building automation workflows using n8n, you might be wondering how to access Gemini’s capabilities directly within your workflows. Good news — it’s easier than you think.

In this guide, we’ll walk you through exactly how to connect Gemini to n8n step by step. Whether you’re using Gemini Pro via Google AI Studio or accessing it through the Vertex AI API, this tutorial will help you get started with seamless integration.

What You Need Before You Start

Before learning how to connect Gemini to n8n, make sure you’ve got the following prerequisites in place:

  • A Google Cloud account with billing enabled
  • API access to Gemini via the Google AI API (or Vertex AI)
  • An n8n instance (hosted or self-hosted)
  • Basic knowledge of using the HTTP Request node in n8n

You may also want to familiarize yourself with how to use custom headers in n8n HTTP requests if you haven't already.

Step 1: Set Up Google AI API and Get API Key

Enable the Gemini API

  1. Go to your Google Cloud Console.
  2. Create a new project (or use an existing one).
  3. Navigate to APIs & Services > Library.
  4. Search for "Gemini API", which is part of the Generative Language API in AI Studio or found under Vertex AI API for advanced usage.
  5. Enable the API.

Obtain Your API Key

  1. In the same project, head to APIs & Services > Credentials.
  2. Click on “+ Create Credentials” > API key.
  3. Copy your key and store it securely.

This key will authenticate n8n's HTTP requests to Gemini’s API.

Step 2: Understand Gemini’s API Request Format

Gemini’s text-based inference endpoint expects JSON in a specific structure. Your request body must include:

  • The model name (models/gemini-pro is currently popular)
  • An array of prompt messages
  • Optional parameters like max tokens, temperature, and topP

A basic Gemini request JSON might look like:

{
  "contents": [
    {
      "role": "user",
      "parts": [{ "text": "List three business automation ideas using n8n." }]
    }
  ]
}

The response will contain AI-generated content under a candidates array.

Step 3: Create the Workflow in n8n

Add a Trigger Node

Start by adding a simple trigger. You can use:

  • Webhook Trigger (ideal for external POSTs)
  • Cron Node (for scheduled tasks)

For testing, a Manual Trigger is great.

Add an HTTP Request Node

Now let’s configure the request to Gemini.

  1. Add an HTTP Request node and configure as follows:

Basic Fields Setup:

  • HTTP Method: POST

  • URL:

    https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=YOUR_API_KEY
    

    Replace YOUR_API_KEY with your actual key.

  • Send Body: Yes

  • Content Type: JSON

Headers:

  • Key: Content-Type, Value: application/json

Body Parameters: Use the same prompt structure as mentioned above. You can also pass variables dynamically from previous nodes.

Here’s an example JSON body using an expression:

{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Summarize the latest blog post from our site."
        }
      ]
    }
  ]
}

Optional: Parse the Gemini Response

To extract the text from the Gemini output, use a Set or Function node to access:

{{$json["candidates"][0]["content"]["parts"][0]["text"]}}

This extracts the actual return text you can pass into further steps such as email, Slack, or Notion updates.

Use Case Example: Gemini AI Email Assistant via n8n

Let’s say you want to automatically generate follow-up emails based on CRM inputs.

Workflow idea:

  1. Trigger: Form submission or CRM webhook
  2. Format prompt: “Write a follow-up email to [name] about [topic] mentioned in the CRM note”
  3. HTTP Request to Gemini
  4. Send generated email via n8n’s Gmail or Outlook node

Gemini can generate professional sounding emails that you can automate and personalize at scale.

If you're looking to build more intelligent agents, check out our guide on how to build a conversational agent using n8n.

Tips for Effective Prompts with Gemini in n8n

Writing good prompts is key to getting valuable outputs from Gemini. Here are a few tips:

  • Use clear instructions like “explain,” “summarize,” “outline,” or “write an email”
  • Include context if possible: product name, tone, target audience
  • Avoid vague or overly open-ended requests
  • Test your prompt using the Gemini playground before automating

Bonus: Use Table to Show Gemini Parameters

Here’s a useful reference for Gemini body parameters during testing:

Parameter Description Example Value
model Model identifier used models/gemini-pro
contents User prompts as array with parts [{text: "Hello"}]
temperature Creativity level (0-1) 0.7
maxOutputTokens Max token count in response 256
topP Sampling probability control 0.8

Going Further With n8n and AI

Once Gemini is connected, you can take your automations to the next level by chaining it with tools like Google Sheets, Notion, or even YouTube for content creation.

You might also consider comparing models using how to use Claude Code in n8n if you're exploring other LLM options, or build a coding agent with n8n for use cases like auto-debugging or script generation.

FAQ

Can I use Gemini for free with n8n?

Gemini offers free tier usage through Google AI Studio, but usage limits may apply. To use it with n8n long-term, a billing-enabled Google Cloud project is recommended.

Is Gemini better than ChatGPT for my workflow?

Gemini and ChatGPT both offer high-quality generative AI, but your choice may depend on prompt outcomes, latency, pricing, and privacy preferences. Try both to evaluate.

Do I need OAuth2 to connect Gemini in n8n?

No, if you're using the API key method, OAuth2 is not needed. For advanced features in Vertex AI, service accounts or OAuth might be relevant.

How do I store my Gemini API key securely in n8n?

Use n8n’s credentials manager to store and reference secrets like API keys without hardcoding them into your workflow.

Can I connect Gemini and OpenAI in the same workflow?

Absolutely. You can use both the Gemini and OpenAI HTTP nodes to compare outputs, enrich content, or apply different tones/styles in the same automated process.

Connecting Gemini to n8n unlocks a powerful blend of Google’s AI and visual automation, empowering you to build content engines, smart assistants, and scalable tools — all without writing code.

★★★★★
50+ fixes, templates & explanations
Stuck with n8n errors?
Node-by-node breakdown.
Copy-paste templates.
Beginner friendly.
Get the n8n Beginners Guide
Built by AgentForEverything.com
Comments
Join the Discussion and Share Your Opinion
Add a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Newsletter
Get The Latest Agent Templates & Guides, Straight To Your Inbox.
Join the #1 AI Automation newsletter.