n8n is the most popular way to build AI automations without writing a full app, and Ollama is the easiest way to run a language model on your own GPU.
Put them together and you get AI agents that read emails, summarise documents, call APIs and answer questions without sending a single token to a cloud provider and without paying per request. In this guide I show you how to self-host n8n with Docker, connect it to Ollama (including the base URL that trips up almost everyone), build a working AI Agent with memory and tools, and pick an Ollama model that is actually good at tool calling. Everything here is based on n8n’s 2.x releases from autumn 2026.
- Install: run Ollama on your PC, then run n8n in Docker with
docker run -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8nand openhttp://localhost:5678. - The URL that matters: in n8n’s Ollama credential use
http://host.docker.internal:11434when n8n runs in Docker and Ollama runs on the host. Usehttp://localhost:11434only if both run outside Docker. - Agent recipe: Chat Trigger, then AI Agent node with an Ollama Chat Model, Simple Memory and at least one tool (Calculator, HTTP Request, Code).
- Model: use a model trained for tool calling (Qwen, Llama, Mistral, Gemma families). Small models get sums wrong without a tool but right with the Calculator tool.
- Version: n8n 2.47 is the current 2.x release (November 4, 2026); 3.x builds started appearing on October 27. Pin a version in Docker instead of using
latest.
Why Run n8n With Ollama?
- Zero per-token cost. Once the model is downloaded, every run is free. Automations that call an LLM hundreds of times a day get expensive on cloud APIs.
- Privacy. Emails, invoices, customer data and internal documents never leave your machine.
- No rate limits and no surprise model deprecations: the model you tested is the model that runs.
- Free self-hosting. n8n’s Community Edition is free to self-host under its Sustainable Use License (source-available; you cannot resell n8n itself as a hosted service, but you can use it for your own and your company’s automations).
The trade-off is quality.
A 7B to 14B model on a consumer GPU is fine for classification, extraction, summaries and simple tool use, but it is not as smart as a frontier cloud model on long multi-step reasoning. n8n makes it easy to mix: use Ollama for the bulk work and a cloud model only for the hard steps.
What You Need
| Item | Minimum | Recommended |
|---|---|---|
| GPU | None (CPU works, slowly) or 6 to 8 GB VRAM | 12 to 16 GB VRAM (RTX 3060 12 GB, 4070, 5080) |
| RAM | 16 GB | 32 GB or more |
| Software | Docker Desktop (Windows/Mac) or Docker Engine (Linux), Ollama | Same, plus Postgres for production |
| n8n itself | About 512 MB RAM | 1 to 2 GB |
Step 1: Install Ollama and Pull a Model
Install Ollama from ollama.com for Windows, macOS or Linux. If you have never done it, follow my Ollama install guide, which also fixes the common “Ollama not using GPU” problem. Then pull a model that supports tool calling:
ollama pull qwen3:8b
ollama run qwen3:8b "Say hello in one sentence"
Any tool-capable model in the Ollama library works; I list good picks for each VRAM size in the models section. Check that the API is up by opening http://localhost:11434 in a browser. It should say “Ollama is running”.
Important for Docker on Linux: by default Ollama only listens on 127.0.0.1.
If n8n runs in a container, make Ollama listen on all interfaces by setting the environment variable OLLAMA_HOST=0.0.0.0 (for the systemd service: sudo systemctl edit ollama, add Environment="OLLAMA_HOST=0.0.0.0" under [Service], then restart). Do not expose port 11434 to the internet. My Ollama commands cheat sheet lists all the environment variables.
Step 2: Self-Host n8n With Docker
The quickest way, good for testing on your own PC:
docker volume create n8n_data
docker run -it --rm --name n8n -p 5678:5678 \
-v n8n_data:/home/node/.n8n \
--add-host=host.docker.internal:host-gateway \
docker.n8n.io/n8nio/n8n
The --add-host line makes host.docker.internal work on Linux (Docker Desktop on Windows and Mac already has it). Open http://localhost:5678, create the owner account, and you are in.
For something you will keep running, use Docker Compose with Postgres and a pinned version. A minimal docker-compose.yml:
services:
postgres:
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_USER: n8n
POSTGRES_PASSWORD: change-me
POSTGRES_DB: n8n
volumes:
- postgres_storage:/var/lib/postgresql/data
n8n:
image: docker.n8n.io/n8nio/n8n:2.47.2
restart: unless-stopped
ports:
- "5678:5678"
environment:
DB_TYPE: postgresdb
DB_POSTGRESDB_HOST: postgres
DB_POSTGRESDB_DATABASE: n8n
DB_POSTGRESDB_USER: n8n
DB_POSTGRESDB_PASSWORD: change-me
N8N_ENCRYPTION_KEY: paste-a-long-random-string
N8N_DIAGNOSTICS_ENABLED: "false"
EXECUTIONS_DATA_PRUNE: "true"
EXECUTIONS_DATA_MAX_AGE: "168"
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- n8n_storage:/home/node/.n8n
depends_on:
- postgres
volumes:
n8n_storage:
postgres_storage:
Generate the encryption key with openssl rand -hex 32 and keep it safe: it encrypts your saved credentials. Start with docker compose up -d. If you later put n8n behind a domain, also set WEBHOOK_URL to your public URL so webhook triggers work.
Version note: n8n ships very often. As of November 4, 2026 the 2.x line is at 2.47.x, and the first 3.x builds appeared on October 27, so check the release notes before jumping a major version.
Option: The Self-Hosted AI Starter Kit
n8n maintains an official Docker Compose bundle that runs n8n, Ollama, Postgres and the Qdrant vector database together:
git clone https://github.com/n8n-io/self-hosted-ai-starter-kit.git
cd self-hosted-ai-starter-kit
cp .env.example .env # set passwords and the two secret keys
docker compose --profile gpu-nvidia up -d # or: --profile gpu-amd / --profile cpu
On a Mac (Apple Silicon), run Ollama natively for GPU speed, set OLLAMA_HOST=host.docker.internal:11434 in .env and start with plain docker compose up -d. In the starter kit, n8n reaches Ollama at http://ollama:11434 because both are on the same Docker network. Note the kit uses the latest n8n image, so pin it once things work.
Step 3: Connect n8n to Ollama
- In n8n go to Credentials, Add credential, search for Ollama.
- Set Base URL to the right address for your setup (see the table).
- Click Save. n8n tests the connection; a green message means it can see Ollama.
| Where n8n runs | Where Ollama runs | Base URL |
|---|---|---|
| Docker | Host PC (Windows/Mac/Linux) | http://host.docker.internal:11434 |
| Docker | Docker, same Compose file | http://ollama:11434 |
| npm / desktop (no Docker) | Host PC | http://localhost:11434 or http://127.0.0.1:11434 |
| Any | Another PC on your LAN | http://192.168.x.x:11434 (set OLLAMA_HOST=0.0.0.0 there) |
The classic mistake is using localhost inside a container: inside Docker, localhost means the container itself, not your PC, so you get “connection refused”.
Step 4: Build Your First Local AI Agent
- Create a new workflow and add a Chat Trigger (“When chat message received”). This gives you a chat box to test with.
- Add an AI Agent node after it.
- Under Chat Model, click + and choose Ollama Chat Model. Pick your Ollama credential and the model (for example
qwen3:8b). Set temperature low (0.1 to 0.3) for reliable tool use. - Under Memory, add Simple Memory (window buffer) so the agent remembers the last few messages. For production use Postgres Chat Memory.
- Under Tool, add at least one tool. The AI Agent node needs one. Start with Calculator, then add HTTP Request or Code. Give every tool a clear name and description; the model reads them to decide when to call it.
- Write a short system message, for example: “You are a helpful assistant. Use the calculator for any arithmetic. If you do not know something, say so.”
- Click Open chat and test.
Why the tool matters: in a public test from October 2026, a small 1.5B Qwen model answered 1234 x 56 wrongly on its own, but with the Calculator tool attached it returned the correct answers and Simple Memory carried context between messages. Tools make small local models far more reliable.
AI Agent Node vs the New Agents Feature
n8n now has two ways to build agents:
- AI Agent node (the classic way): an agent inside a workflow, triggered like any other node. Fully supports the Ollama Chat Model sub-node. This is what I recommend for local models.
- Agents (Preview): standalone assistants built in an Agent Builder, separate from workflows. n8n’s docs list them on all plans from version 2.32.3, including the free self-hosted edition, and they are on by default (owners can turn them off in Settings, Agents). Queue mode is not supported yet.
As of late October 2026, Ollama is not one of the built-in providers in Agents. A community workaround uses the OpenAI credential with base URL http://host.docker.internal:11434/v1 (Ollama’s OpenAI-compatible endpoint) and any dummy API key; it worked for plain chat in testing but is undocumented, so stick with the AI Agent node for anything important.
Best Ollama Models for n8n Agents
For agents, tool-calling reliability matters more than raw benchmark scores. In the Ollama library, look for the tools tag on the model page.
| Your GPU | Good starting models | Use for |
|---|---|---|
| CPU only / 4 to 6 GB | Qwen3 4B, Llama 3.2 3B, Gemma small models | Classification, short extraction, simple routing |
| 8 GB | Qwen3 8B, Llama 3.1 8B, Xiaomi MiMo-V2.6 9B | Most agent tasks with 1 to 3 tools |
| 12 to 16 GB | Qwen3 14B, Mistral Small, Gemma mid-size | Multi-tool agents, summaries of long documents |
| 24 GB+ or lots of RAM | Qwen3 30B-A3B and bigger MoE models | Harder reasoning, RAG over large knowledge bases |
For a ranked, up-to-date list with VRAM numbers, see my best Ollama models in 2026 guide and the MiMo-V2.6 9B setup for a strong 8 GB option. Pick a Q4_K_M or Q5_K_M quantization (my GGUF guide explains why).
Two settings help a lot: raise the context window in the Ollama Chat Model options (Ollama’s default is small, and agents with memory and tool results overflow it quickly), and keep temperature low.
5 Useful Local Workflow Ideas
- Email triage: Gmail or IMAP trigger, then an Ollama model classifies each email (urgent, invoice, newsletter, spam) and applies a label or posts to Slack.
- Private document Q&A (RAG): load PDFs into Qdrant with an Ollama embedding model (such as
nomic-embed-text), then chat with them through the AI Agent node and a vector store tool. - Invoice and receipt extraction: read a file, ask the model for structured JSON with a Structured Output Parser, write rows to Google Sheets or Postgres.
- RSS or news digest: a schedule trigger pulls feeds every morning, the model summarises each item in two lines, and n8n emails you a digest.
- MCP tools for your agent: n8n has MCP Client Tool and MCP Server Trigger nodes, so your local agent can use the servers in my best MCP servers list, or expose your n8n workflows as tools to Claude, Cursor or Cline.
Fix Common n8n + Ollama Errors
| Error | Cause | Fix |
|---|---|---|
| ECONNREFUSED 127.0.0.1:11434 | n8n in Docker using localhost | Use http://host.docker.internal:11434 and add host-gateway on Linux |
| Connection refused even with host.docker.internal (Linux) | Ollama listening on 127.0.0.1 only | Set OLLAMA_HOST=0.0.0.0 and restart Ollama; check your firewall |
| Model not found | Name differs from what you pulled | Run ollama list and use the exact name and tag |
| Agent never calls the tool | Model without tool support, or vague tool description | Use a tools-tagged model, lower temperature, write a clear tool description and mention the tool in the system message |
| Agent forgets or loops | Context window too small | Increase context length in the model options; reduce memory window |
| Very slow replies | Model running on CPU | Check ollama ps; use a smaller model or quant that fits your VRAM |
Frequently Asked Questions
Is n8n free to self-host?
Yes. The Community Edition is free to self-host under n8n’s Sustainable Use License. The restriction is that you cannot sell n8n itself as a hosted service to others. n8n Cloud is the paid hosted option; check n8n.io/pricing for current plans.
Can n8n use Ollama without Docker?
Yes. Install n8n with npm (it needs a recent Node.js; n8n’s 2.4x releases were tested on Node.js 24) using npx n8n, and use http://localhost:11434 as the Ollama base URL.
What is the best Ollama model for n8n?
For an 8 GB GPU, an 8B to 9B tool-calling model like Qwen3 8B or MiMo-V2.6 9B is the sweet spot. With 16 GB, step up to a 14B model. Always pick models tagged with tools support.
Can I use LM Studio or llama.cpp instead of Ollama?
Yes, through their OpenAI-compatible servers. Use n8n’s OpenAI Chat Model with the base URL set to LM Studio (http://host.docker.internal:1234/v1) or llama.cpp’s server. See Ollama vs LM Studio vs llama.cpp to choose.
Does a local agent work as well as GPT or Claude in n8n?
For classification, extraction and simple tool use, a good 8B to 14B model is often enough. For long multi-step reasoning, frontier cloud models are still clearly better. Many people route easy steps to Ollama and only hard steps to a cloud model.
Final Thoughts
n8n plus Ollama is one of the best free AI stacks you can run at home in 2026. Get the base URL right (host.docker.internal from Docker), give your agent at least one tool, choose a tools-capable model that fits your VRAM, and raise the context window. From there you can build email triage, document chat and daily digests that cost nothing to run and keep your data private. If you want to hand your agent more tools, browse my best MCP servers list next.
Sources
- DEV: n8n AI Agent tutorial 2026, Agents feature vs AI Agent node (tested October 20, 2026)
- DEV: How to self-host n8n with Docker (2026)
- n8n release index (versions to November 4, 2026)
- n8n docs: Release notes 2.x
- GitHub: n8n-io/self-hosted-ai-starter-kit
- Centron: n8n with Ollama on an Ubuntu GPU server




