n8n and Ollama: Building AI Automation Workflows

If you’ve been hanging around the self-hosting community for any amount of time, you’ve probably heard the buzzwords flying around: “AI automation,” “local LLMs,” “workflow orchestration.” It all sounds very impressive and very expensive. But here’s the thing — you can build genuinely powerful AI-powered automations on your own hardware, with your own data, without sending a single token to a third-party API.

Two tools make this possible: n8n for workflow automation and Ollama for running large language models locally. Together, they form a surprisingly capable stack that rivals commercial offerings, and the best part is that you own every piece of it.

Let’s walk through how these two tools work together, why you’d want to combine them, and how to build your first AI automation workflow from scratch.

Why n8n and Ollama?

Before we get our hands dirty, let’s talk about why this particular combination is worth your time.

n8n is a self-hostable workflow automation tool. Think of it as an open-source alternative to Zapier or Make, but with a node-based visual editor that gives you far more control over logic and data flow. You can connect hundreds of services, write custom JavaScript in function nodes, and build complex branching workflows. It’s licensed under a fair-code model, which means you can self-host it freely for personal use and most business use cases.

Ollama is a tool for running large language models locally. It’s like Docker, but for LLMs. You pull a model with a single command, and Ollama handles the rest — quantization, inference server, API compatibility. It exposes an OpenAI-compatible API endpoint by default, which is the key that makes integration with n8n trivial.

When you put them together, you get a workflow engine that can call a local LLM at any step. That means you can:

  • Summarize incoming emails and route them based on content
  • Generate draft responses to customer tickets
  • Extract structured data from unstructured text
  • Classify and tag content automatically
  • Build custom chatbots that pull from your own documents

All of this runs on your hardware. No API costs, no data leaving your network, no rate limits to worry about.

Prerequisites and Setup

You’ll need a machine with decent resources. Running an LLM locally is the heavy part here. As a rough guide:

  • Minimum: 8GB RAM for small models like Llama 3.2 3B or Phi-3 Mini
  • Comfortable: 16-32GB RAM for 7-8B parameter models like Llama 3.1 8B or Mistral
  • Serious: 32GB+ RAM or a GPU with 12GB+ VRAM for larger models

If you have a spare GPU, Ollama will use it automatically. If not, CPU inference works fine for smaller models — it’s just slower.

Installing Ollama

On Linux, installation is a one-liner:

1
curl -fsSL https://ollama.com/install.sh | sh

On macOS or Windows, grab the installer from ollama.com. Once installed, pull a model:

1
ollama pull llama3.1:8b

This downloads a quantized version of Llama 3.1 8B, which is a great general-purpose model for automation tasks. It’s about 4.7GB on disk and runs comfortably on machines with 16GB of RAM.

Verify Ollama is serving by hitting its API:

1
curl http://localhost:11434/api/tags

You should see a JSON response listing your available models.

Installing n8n

The cleanest way to run n8n is with Docker. Create a docker-compose.yml file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
version: '3.8'

services:
  n8n:
    image: n8nio/n8n:latest
    restart: unless-stopped
    ports:
      - "5678:5678"
    environment:
      - N8N_HOST=localhost
      - N8N_PORT=5678
      - N8N_PROTOCOL=http
      - NODE_ENV=production
      - GENERIC_TIMEZONE=America/New_York
    volumes:
      - n8n_data:/home/node/.n8n

volumes:
  n8n_data:

Bring it up:

1
docker compose up -d

Open your browser to http://localhost:5678 and create your owner account. You’re now ready to build workflows.

Connecting the Two

Here’s an important detail: if n8n is running in Docker and Ollama is running on your host, localhost from inside the n8n container refers to the container itself, not your host machine. You have a few options:

  1. Use host.docker.internal as the Ollama URL (works on Docker Desktop)
  2. Use your host’s LAN IP (e.g., http://192.168.1.100:11434)
  3. Add Ollama to the same Docker network and reference it by service name
  4. Run Ollama in Docker too and link them via a shared network

The simplest approach for a homelab is option 2 — just point n8n at your host’s LAN IP. Make sure Ollama is listening on that interface by setting the host before starting it:

1
OLLAMA_HOST=0.0.0.0:11434 ollama serve

Building Your First AI Workflow: Email Summarizer

Let’s build something practical. We’ll create a workflow that:

  1. Triggers when a new email arrives (via IMAP)
  2. Sends the email body to Ollama for summarization
  3. Saves the summary to a Notion database (or any output you prefer)

This is a classic automation pattern that immediately demonstrates the value of local AI.

Step 1: The IMAP Trigger

Open n8n and click “Add Workflow.” Add a new node and search for “Email Trigger (IMAP).” Configure it with your email server details:

  • Host: imap.gmail.com (or your provider)
  • Port: 993
  • SSL: enabled
  • Username: your email address
  • Password: an app-specific password (not your regular password if you’re using Gmail)

Set the polling interval to something reasonable — every 10 minutes is fine for testing. You can tighten it later.

When you test the trigger, n8n will fetch the most recent email and show you the data structure. Take note of the fields — you’ll need textHtml or textPlain for the email body.

Step 2: The Ollama Node

Add a new node and search for “Ollama.” n8n has a native Ollama integration node, which makes this straightforward. If you don’t see it, make sure your n8n version is recent — the node was added in late 2024.

Configure the node:

  • Base URL: http://192.168.1.100:11434 (your host IP)
  • Model: llama3.1:8b
  • Operation: Chat or Completion (chat is preferred for most use cases)
  • Prompt: See below

For the prompt, use n8n’s expression syntax to inject the email content:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
You are an assistant that summarizes emails concisely. 

Summarize the following email in 2-3 bullet points, then suggest a one-line reply.

Email subject: {{ $json.subject }}
Email body: {{ $json.textPlain }}

Format your response as:
SUMMARY:
- bullet 1
- bullet 2
- bullet 3

SUGGESTED REPLY:
[one line]

The {{ $json.textPlain }} expression pulls the plain text body from the previous IMAP node’s output. n8n handles the variable injection automatically.

If you prefer using the OpenAI node instead (which also works with Ollama since it’s API-compatible), set the base URL to http://your-host-ip:11434/v1 and use any dummy API key — Ollama ignores it.

Step 3: Parsing the Response

The Ollama node will return the model’s response as a single string. To make it useful, add a “Code” node to parse it into structured fields:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
const response = $input.first().json.message.content;

const summaryMatch = response.match(/SUMMARY:\n([\s\S]*?)\n\nSUGGESTED REPLY:/);
const replyMatch = response.match(/SUGGESTED REPLY:\n(.*)/);

return {
  summary: summaryMatch ? summaryMatch[1].trim() : response,
  suggestedReply: replyMatch ? replyMatch[1].trim() : '',
  rawResponse: response
};

This extracts the summary and suggested reply into separate fields that downstream nodes can use independently.

Step 4: Output to Your Preferred Destination

Now you can send this structured data anywhere. Some common options:

  • Notion node: Create a new page in a database with the summary
  • Slack node: Post the summary to a channel
  • HTTP Request node: Send it to a webhook on another service
  • Telegram node: Send yourself a notification
  • Write to file: Save it locally for archival

For this example, let’s send it to Slack. Add a Slack node, configure your credentials, and set the message text:

1
2
3
4
New email summary:
{{ $json.summary }}

Suggested reply: {{ $json.suggestedReply }}

Step 5: Test and Activate

Test each node individually first. Click “Execute Node” on the Ollama node to make sure it can reach your local model. If you get a connection error, double-check:

  • Is Ollama running? (ollama serve or check the service)
  • Is the URL correct from inside the container?
  • Is the model name spelled correctly?
  • Is Ollama listening on the right interface?

Once everything works, click “Active” in the top right to enable the workflow. n8n will now poll your inbox on the schedule you set and process new emails automatically.

Going Further: More Workflow Ideas

The email summarizer is just the beginning. Once you understand the pattern — trigger → Ollama → parse → output — you can build all sorts of automations:

RSS Feed Classifier

Pull articles from RSS feeds, ask the LLM to classify them by topic, and route them to different Notion databases or Slack channels based on the category. Great for building a personalized news pipeline.

GitHub Issue Triage

Trigger on new GitHub issues, ask the LLM to suggest labels and priority based on the issue text, and automatically apply them via the GitHub API. This is genuinely useful for open-source maintainers.

Meeting Notes Processor

Take raw transcripts (from Whisper or any transcription tool), pass them to Ollama for action item extraction, and create tasks in your task manager of choice.

Document Q&A Chatbot

Build a Telegram or Discord bot that accepts questions, retrieves relevant documents from a local vector store (n8n has vector store nodes), and passes them to Ollama as context. This is essentially a self-hosted ChatGPT with access to your own files.

Log Analysis

Feed server logs or application errors to the LLM for natural-language analysis. “What’s going wrong with this error?” is a surprisingly effective prompt when you’re debugging at 2 AM.

Tips for Better Results

A few practical lessons from building these workflows:

Choose the right model for the task. Llama 3.1 8B is a great generalist, but for specific tasks you might do better with specialized models. For coding tasks, try Qwen2.5 Coder. For reasoning-heavy tasks, consider a larger model if your hardware can handle it. Ollama makes switching models trivial — just pull a new one and update the node config.

Be explicit in your prompts. Local models are less capable than GPT-4, so they need more guidance. Specify the exact format you want. Give examples if possible. The more structure you provide, the more reliable the output.

Handle parsing failures gracefully. LLMs don’t always follow instructions perfectly. Your code nodes should have fallback logic — if the regex doesn’t match, return the raw response rather than crashing the workflow.

Watch your context length. Smaller models often have limited context windows. If you’re passing large documents, you may hit limits. Ollama will truncate or error out. Consider chunking large inputs or using a model with a larger context window.

Monitor resource usage. Running an LLM is CPU/GPU intensive. If you’re processing high volumes, you may need to queue requests or scale your hardware. Ollama handles one request at a time by default — concurrent requests will queue.

Security Considerations

Running this stack locally is inherently more private than using cloud APIs, but keep a few things in mind:

  • n8n credentials are stored in its database. Make sure your n8n instance is not exposed to the public internet without authentication. Enable basic auth or put it behind a reverse proxy with auth.
  • Ollama has no authentication by default. If your machine is on a network with other users, bind Ollama to localhost only or put it behind a firewall.
  • Model outputs can contain hallucinations. Don’t use LLM-generated content for critical decisions without human review, especially in automated pipelines where errors can cascade.
  • Keep your models and tools updated. Both n8n and Ollama receive regular updates with security fixes and improvements.

Performance Expectations

Let’s set realistic expectations. On a modern machine with no GPU:

  • Llama 3.2 3B: ~20-40 tokens per second on CPU
  • Llama 3.1 8B: ~8-15 tokens per second on CPU
  • With a GPU (RTX 3060+): 40-80+ tokens per second for 8B models

For a workflow that processes one email at a time, even 10 tokens per second is fine — a summary takes a few seconds. For high-throughput pipelines processing hundreds of items, you’ll want a GPU or a smaller model.

Compare this to cloud API costs: at GPT-4 pricing, processing 1,000 emails with summaries might cost $5-15. With local inference, it costs you nothing but electricity. If you’re processing high volumes, the hardware pays for itself.

Summary

n8n and Ollama together give you a self-hosted AI automation platform that’s genuinely useful and completely under your control. The setup is straightforward — Ollama serves models via an API, n8n orchestrates workflows and calls that API at any step. The combination replaces expensive cloud services with something you can run on a homelab machine.

The email summarizer we built is a starting point, not an endpoint. The same pattern — trigger, LLM processing, structured output, delivery — applies to hundreds of automation scenarios. Start simple, iterate, and let your specific needs guide what you build next.

If you build something cool with this stack, share it with the community. The self-hosting world moves fast, and real-world use cases are how we all learn what works and what doesn’t.

Ready to build? Fire up Ollama, spin up n8n, and start automating. Your data stays on your hardware, your costs stay at zero, and your workflows stay yours. That’s what self-hosting is all about.