n8n and AI: Build Your First Real Automation
A practical walkthrough of wiring an AI model into an n8n workflow — the node structure, the prompt that makes it reliable, and three automations worth building first.
n8n is an open-source workflow automation tool. Combined with an AI model it becomes a way to build genuinely useful automation without writing an application — and it is the fastest path from "I have an idea" to "it runs on a schedule."
The basic shape
Almost every AI workflow follows the same five steps:
Trigger → Format input → Call AI → Parse output → Take actionTrigger — a schedule, a webhook, a new email, a new row in a sheet. Format input — extract the fields the prompt needs. Call AI — a dedicated node or a generic HTTP Request. Parse output — pull structured fields from the response. Take action — send, post, save, notify.
The two steps people skip are formatting and parsing, and skipping them is the most common cause of fragile workflows.
Connecting a model
Two options. Dedicated nodes (OpenAI, Anthropic and community nodes) handle authentication and response shape for you — start here. The generic HTTP Request node works with any provider's API and is the fallback when no node exists.
For HTTP Request, a minimal chat completion body looks like:
{
"model": "your-model",
"messages": [
{ "role": "system", "content": "You summarise support tickets in one sentence." },
{ "role": "user", "content": "{{ $json.ticket_body }}" }
]
}The {{ }} syntax is an n8n expression pulling a value from the previous node.
Make the output structured
This is the difference between a workflow that runs for a year and one that breaks next week.
Do not ask for prose and then parse it with string matching. Ask for JSON with an explicit schema:
Classify this email into exactly one category: "support",
"sales_lead", "spam", or "urgent". Then draft a two-sentence
acknowledgement matching that category's tone.
Return valid JSON only, no markdown:
{"category": string, "draft_reply": string, "confidence": number}
Email: {{ $json.email_body }}Then add a Set node immediately after to extract just the fields you need. Never pass a raw API response downstream — when the response shape changes, everything after it breaks at once.
Three worth building first
1. Content repurposing. Trigger on a new blog post (RSS or webhook). Ask the model to produce a thread, a LinkedIn post and an email blurb as JSON. Route each field to its channel. High value for anyone publishing regularly, and a clean introduction to structured output.
2. Email triage. Trigger on new mail. Classify intent and confidence. Branch: auto-acknowledge routine mail, alert a human channel for urgent items, queue anything low-confidence for review. This teaches conditional routing and the confidence-gating pattern you will reuse constantly.
3. Scheduled research digest. Run daily. Search a few sources, summarise findings, deliver one message. Simple, and immediately useful.
Things that will bite you
No error branch. APIs fail. Rate limits happen. Without error handling a failed run vanishes silently. Add an error path that notifies you.
No confidence gate. Fully automated classification will occasionally be confidently wrong. Route low-confidence items to a human. Never let a fully automated flow send the final word on anything high-stakes.
Unbounded loops. If a workflow includes an agent or a retry loop, cap the iterations. This is the standard cause of surprising bills.
Prompt drift. A prompt that works on today's inputs may not on next month's. Log inputs and outputs so you can diagnose degradation rather than guess.
Testing on happy paths only. Test with the empty input, the malformed input, the enormous input, and the input in another language. Real data contains all of these.
Cost control
Workflows run unattended, which means costs accumulate unattended.
Use a small model for classification and routing — they are entirely adequate and often 10-20x cheaper. Reserve the expensive model for genuine generation. Cap output length. And check your token usage against real volume before turning on a high-frequency schedule: our cost calculator will tell you what a per-minute trigger actually costs per month.
Where to go deeper
Our AI Automation with n8n course walks through node configuration, the workflow templates above, and the error handling that makes them production-worthy. If you want the agent patterns behind the AI Agent node, Loop & Agentic Engineering covers those.
Keep reading
Want to go deeper?
Nine free course tracks, 85 tested prompts, and free tools that run entirely in your browser.