N8N: Visual Workflows with AI Nodes
You build an AI workflow in N8N that automatically processes data and executes actions.
Why this lesson matters
Custom GPTs are handy, but they only work inside ChatGPT. What if you want an agent that responds automatically to an incoming email, a form or a webhook? Then you need a workflow tool. N8N is the most powerful open-source option: free, self-hosted, and with built-in AI nodes.
In this lesson you get to know N8N and build a workflow in which AI automatically classifies emails and forwards them to the right department.
What is N8N?
N8N (pronounced "n-eight-n") is an open-source workflow automation tool. Think Zapier, but:
- Free if you host it yourself
- Visual: you build workflows by dragging and connecting nodes
- Strong: more flexibility than Zapier or Make
- AI-native: built-in nodes for OpenAI, Anthropic, and a dedicated AI Agent node
N8N also has a cloud version if you don't want to self-host. That starts at $20/month. The self-hosted version is completely free and runs on any machine with Docker.
Basic concepts
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Trigger │───→│ Node 1 │───→│ Node 2 │
│ (start) │ │(process) │ │ (action) │
└──────────┘ └──────────┘ └──────────┘| Concept | Explanation | Example |
|---|---|---|
| Node | A building block that does 1 task | Fetch an email, analyse text |
| Connection | The arrow between nodes | Data flows from left to right |
| Trigger | The start node -- what kicks off the workflow? | New email, webhook, schedule |
| Credentials | Login details for external services | Gmail password, OpenAI API key |
| Execution | One run of the workflow | Every incoming email = 1 execution |
AI nodes in N8N
N8N has dedicated nodes for AI:
OpenAI node: Send a prompt to an OpenAI model and get an answer back. Handy for classification, summaries, translation.
Anthropic node: The same, but with Claude. Often better for longer texts and analyses.
Keep reading
Leave your name and email address and you can read the rest
You get the whole lesson right away, and every other lesson stays open after that. No password, no confirmation email.
AI Agent node: This is the most powerful one. With it you build a complete agent that:
- Has a system prompt
- Can use tools (other nodes)
- Decides for itself which tool to use
- Can run through several steps
The AI Agent node in N8N is in fact the ReAct pattern from lesson 2, but visual. You attach tools (other nodes) to the agent, and it picks for itself which one to use.
Example: email classification and routing
Let's build a concrete workflow:
Goal: Automatically classify incoming emails and forward them to the right department.
┌─────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
│ Gmail │──→│ OpenAI │──→│ Switch │──→│ Slack/ │
│ Trigger │ │ Classifi-│ │ (route) │ │ Email │
│ │ │ cation │ │ │ │ Output │
└─────────┘ └──────────┘ └──────────┘ └──────────┘Step 1: Gmail Trigger
Set the trigger to "New email in inbox". The node automatically fetches the sender, subject and body.
Step 2: OpenAI classification
Send the email body to the model with this prompt:
Classify the following email into exactly one of
these categories:
- SALES (questions about products, prices, quotes)
- SUPPORT (complaints, problems, returns)
- ADMIN (invoices, contracts, administrative)
- SPAM (unwanted, not relevant)
Email:
{{$json.body}}
Answer with the category only, no explanation.Step 3: Switch node
Based on the classification (SALES, SUPPORT, ADMIN, SPAM) you route to different outputs.
Step 4: Action per category
- SALES → Slack message to #sales-team
- SUPPORT → Create a ticket in the helpdesk
- ADMIN → Forward to administratie@bedrijf.nl
- SPAM → Archive and ignore
Test your classification prompt thoroughly before you switch the workflow on. Send 20-30 test emails with different subjects and check whether the classification is right. Adjust the prompt until you're above 90% accuracy.
N8N vs Zapier vs Make
| N8N | Zapier | Make | |
|---|---|---|---|
| Price | Free (self-hosted) | From $20/month | From $9/month |
| AI nodes | Extensive (Agent node) | Basic (AI actions) | Good (OpenAI module) |
| Complexity | Medium | Low | Medium |
| Flexibility | Very high | Limited | High |
| Self-hosting | Yes | No | No |
| Number of integrations | The fewest | The most | Many |
| Writing code | Yes (JavaScript) | Limited | Limited |
Installing N8N
The fastest way to start N8N:
# With Docker (recommended):
docker run -it --rm \
--name n8n \
-p 5678:5678 \
n8nio/n8n
# Or with npm:
npx n8nThen go to http://localhost:5678 and you can start building.
What makes the AI Agent node in N8N special compared with a regular OpenAI node?
What is the biggest advantage of N8N over Zapier?
In the email classification workflow, what does the Switch node do?
Want to keep your progress, get the practice files and sign up for the free evening? Create a free account. All you do is click a link in your email.
Create a free account