Analytics cookies only (Google Analytics, PostHog). No ad networks, no cross-site tracking. See our privacy policy.
Updated Sep 2026
verified on Ubuntu 26.04 · Aug 2026Learn how to build AI-powered automations with n8n — connect Ollama, OpenAI, and other LLMs to create intelligent workflows that process data, generate content, and make decisions.
n8n is a workflow automation tool, and adding AI to it turns simple automations into intelligent ones. Instead of rigid if-then logic, your workflows can understand text, classify data, generate responses, and make decisions based on context. The appeal is automation without rules — AI can handle edge cases that would require dozens of if-else branches.
This guide assumes you already have n8n running. If not, start with Deploy n8n on a VPS to get the base setup. Once n8n is live, come back here to add AI capabilities.
n8n supports several AI providers out of the box. The configuration depends on your backend:
Ollama (self-hosted, free):
http://host.docker.internal:11434)OpenAI:
Anthropic:
Once configured, these credentials appear in any AI node you add to a workflow.
n8n has several AI-specific nodes:
AI Agent: The most powerful node. It takes a prompt, connects to an LLM, and can use tools (web search, code execution, API calls) to complete tasks. Think of it as an autonomous worker that can research, reason, and act.
LLM Chain: Sends a prompt to an LLM and returns the response. Simple but useful for classification, summarization, or generation tasks.
Text Classifier: Uses an LLM to classify text into categories you define. Useful for routing support tickets, categorizing feedback, or filtering content.
Summarizer: Takes long text and produces a concise summary. Good for processing articles, reports, or conversation logs.
QA Chain: Answers questions based on provided context. Useful for building a knowledge base where you supply the documents and the AI answers questions about them.
Paid link — we earn a commission if you shop through it.
Here's a practical example: automatically route support tickets based on their content.
Workflow:
Configuration:
This turns a manual triage process into an automated one with AI understanding the nuance of each ticket.
Generate social media content from a list of topics:
Workflow:
Configuration:
Automatically process incoming emails:
Workflow:
Configuration:
If you're running Ollama on the same server as n8n, you can use it for all AI operations without API costs:
Advantages:
Limitations:
Best practices:
AI nodes can fail for several reasons. Add error handling to your workflows:
Rate limiting: If using cloud APIs, add a Wait node between AI calls to avoid rate limits. For Ollama, this isn't an issue.
Timeout: Large models can be slow. Set appropriate timeouts in the HTTP Request node if you're making custom API calls.
Invalid responses: LLMs sometimes return unexpected formats. Use the IF node to validate responses before passing them downstream.
Fallback models: Configure a fallback credential in case your primary model is unavailable. The AI Agent node supports this natively.
n8n workflows are stored in the database. Back them up regularly:
docker compose exec -T postgres pg_dump -U n8n n8n | gzip > n8n-workflows-$(date +%F).sql.gz
For version control, export workflows as JSON from the n8n UI and commit them to Git. This lets you track changes and roll back if needed.
Use webhooks, not polling: Webhooks trigger instantly; polling adds delay. For real-time AI processing, webhooks are essential.
Batch processing: If you're processing many items, use the Split In Batches node to avoid overwhelming your LLM backend. Process 5-10 items at a time with a small delay between batches.
Cache common responses: If you're asking the same question repeatedly, cache the response in a database or file. The AI node can check the cache first and only call the LLM if the response isn't cached.
Choose the right model: Not every task needs GPT-4. Use smaller, faster models for simple classification and larger models for complex reasoning. The cost difference is significant.
AI node returns empty responses. Check the credential configuration and verify the LLM backend is running. For Ollama, confirm a model is pulled and the base URL is correct.
Workflow is slow. AI inference takes time, especially on CPU. Consider using a GPU-equipped VPS, smaller models, or caching frequent responses.
Token limit errors. LLMs have context windows. If your input is too long, split it into chunks or use a model with a larger context window.
Webhook not triggering. Check that n8n is accessible from the internet and the webhook URL is correct. For production use, add authentication to your webhooks.
You're done when you can: create a workflow with an AI node, connect it to your LLM backend, and process data through it. Test with a simple classification task, then build more complex workflows.
From here, explore n8n's AI features like memory (keeping conversation context), tools (letting AI call APIs), and retrieval-augmented generation (RAG) for knowledge-based workflows. For the base n8n setup, see Deploy n8n on a VPS. For document-based AI, see AnythingLLM. A 2 vCPU / 4 GB VPS handles n8n with Ollama; for heavier AI workloads, consider 4 vCPU / 8 GB or a GPU instance. See Best VPS for AI & ML Workloads for the ranked picks.
We estimate about 50 minutes of hands-on time for "Building AI Workflows with n8n"; this is an editorial estimate, not a measurement.
The "Building AI Workflows with n8n" guide was verified end-to-end on Ubuntu 26.04 (Aug 2026).