Skip to content

Building AI Workflows with n8n

Updated Sep 2026

verified on Ubuntu 26.04 · Aug 2026
We earn commissions when you shop through the links below. Full disclosure →

Learn 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.

Before you start
  • n8n running on a VPS (see Deploy n8n on a VPS)
  • At least one LLM backend configured (Ollama, OpenAI, etc.)
  • Basic understanding of n8n's visual workflow editor
Need a box for this guide? Kamatera's free tier lets you spin one up now.Start free on Kamatera → (opens in new tab)

Why AI + n8n?

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.

Connecting n8n to LLM backends

n8n supports several AI providers out of the box. The configuration depends on your backend:

Ollama (self-hosted, free):

  1. In n8n, go to Settings → Credentials → Add Credential
  2. Search for "Ollama"
  3. Set the base URL to your Ollama instance (e.g., http://host.docker.internal:11434)
  4. Save

OpenAI:

  1. Add an "OpenAI API" credential
  2. Enter your API key
  3. Save

Anthropic:

  1. Add an "Anthropic API" credential
  2. Enter your API key
  3. Save

Once configured, these credentials appear in any AI node you add to a workflow.

Core AI nodes

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.

Where to host itaffiliate disclosure
Hetzner Cloudrun it on
2 vCPU · 4 GB RAM · 80 GB SSD · $23.59/mo
Get Hetzner Cloud (opens in new tab)
Kamaterafree trial
1 vCPU · 1 GB RAM · 20 GB SSD · $4.00/mo
Start free on Kamatera → (opens in new tab)
DigitalOceanalso works on
1 vCPU · 1 GB RAM · 25 GB SSD · $6.00/mo
Deploy on DigitalOcean → (opens in new tab)

Paid link — we earn a commission if you shop through it.

Example: AI-powered support ticket routing

Here's a practical example: automatically route support tickets based on their content.

Workflow:

  1. Trigger: Webhook receives a support ticket (email, form submission, etc.)
  2. Text Classifier: Analyze the ticket content
  3. Categories: Billing, Technical, Feature Request, General
  4. Switch: Route to the right team based on classification
  5. AI Agent: Draft a response acknowledging the ticket
  6. Send Email: Notify the customer with the AI-drafted response

Configuration:

  • The Text Classifier node gets categories from a spreadsheet or hardcoded list
  • The AI Agent uses your Ollama or OpenAI credential
  • The response is reviewed by a human before sending (optional)

This turns a manual triage process into an automated one with AI understanding the nuance of each ticket.

Example: content generation pipeline

Generate social media content from a list of topics:

Workflow:

  1. Trigger: Schedule (runs daily)
  2. Google Sheets: Read a list of topics
  3. AI Agent: Generate a social media post for each topic
  4. Filter: Remove low-quality outputs
  5. Buffer/Social Media: Post to your channels

Configuration:

  • The AI Agent gets a prompt like "Write a engaging social media post about {topic}. Keep it under 280 characters. Include relevant hashtags."
  • Use a local Ollama model for free generation, or OpenAI for higher quality
  • The Filter node can use simple length checks or another AI call to score quality

Example: email processing with AI

Automatically process incoming emails:

Workflow:

  1. Trigger: IMAP node watches an inbox
  2. AI Agent: Analyze the email content
  3. Switch: Route based on intent (inquiry, complaint, spam, newsletter)
  4. For inquiries: Draft a response and send for review
  5. For complaints: Create a ticket in your helpdesk
  6. For spam: Delete or archive

Configuration:

  • The AI Agent uses a prompt that understands your business context
  • Include your company name and common topics in the system prompt
  • Route to different LLM models based on complexity (small model for simple routing, larger model for drafting responses)

Using Ollama for cost-free AI

If you're running Ollama on the same server as n8n, you can use it for all AI operations without API costs:

Advantages:

  • Zero per-token cost
  • Data stays on your server
  • No rate limits
  • Works offline

Limitations:

  • Slower than cloud APIs (especially on CPU)
  • Quality varies by model size
  • Requires RAM for the model

Best practices:

  • Use smaller models (3B-7B) for simple tasks like classification
  • Reserve larger models (13B+) for complex reasoning
  • Cache common responses to reduce inference load
  • Run Ollama on a GPU-equipped VPS for better performance

Error handling

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.

Backups and version control

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.

Performance tips

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.

Troubleshooting

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.

Verification + next steps

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.

Next steps

How to self-host n8n →More self-hosted workflow automation tools →Best VPS for n8n →Automatic HTTPS with Caddy →Run Claude Code with Ollama on Your Own VPS →Deploy Coolify on a VPS →How to Deploy Actual Budget on a VPS →How to Deploy AnythingLLM on a VPS →How to Deploy Appwrite on a VPS →How to Deploy Audiobookshelf on a VPS →How to Deploy Authelia on a VPS →How to Deploy authentik on a VPS →How to Deploy Baserow on a VPS →How to Deploy Beszel on a VPS →How to Deploy Bitwarden on a VPS →How to Deploy BookStack on a VPS →How to Deploy CapRover on a VPS →How to Deploy Checkmate on a VPS →How to Deploy Directus on a VPS →How to Deploy docker-mailserver on a VPS →How to Deploy Docmost on a VPS →How to Deploy Dokku on a VPS →How to Deploy Dokploy on a VPS →How to Deploy Firefly III on a VPS →How to Deploy Forgejo on a VPS →How to Deploy Gatus on a VPS →How to Deploy Ghostfolio on a VPS →How to Deploy Gitea on a VPS →How to Deploy GitLab on a VPS →How to Deploy GlitchTip on a VPS →How to Deploy Grafana on a VPS →How to Deploy Graylog on a VPS →How to Deploy Headscale on a VPS →How to Deploy Healthchecks on a VPS →How to Deploy Home Assistant on a VPS →How to Deploy Immich on a VPS →How to Deploy Jan on a VPS →How to Deploy Jellyfin on a VPS →How to Deploy Karakeep on a VPS →How to Deploy Keycloak on a VPS →How to Deploy Leantime on a VPS →How to Deploy LibreChat on a VPS →How to Deploy Linkwarden on a VPS →How to Deploy LocalAI on a VPS →How to Deploy Mailcow on a VPS →How to Deploy Mailu on a VPS →How to Deploy Matomo on a VPS →How to Deploy Mattermost on a VPS →How to Deploy Meilisearch on a VPS →How to Deploy Memos on a VPS →How to Deploy n8n on a VPS →How to Deploy Navidrome on a VPS →How to Deploy NetBird on a VPS →How to Deploy Netdata on a VPS →How to Deploy Nextcloud on a VPS →How to Deploy Next.js to a VPS →How to Deploy Nginx Proxy Manager on a VPS →How to Deploy NocoDB on a VPS →How to Deploy ntfy on a VPS →How to Deploy Ollama on a VPS →How to Deploy Open WebUI on a VPS →How to Deploy OpenHands on a VPS →How to Deploy OpenObserve on a VPS →How to Deploy OpenProject on a VPS →How to Deploy Outline on a VPS →How to Deploy Pangolin on a VPS →How to Deploy Paperless-ngx on a VPS →How to Deploy Passbolt on a VPS →How to Deploy Plane on a VPS →How to Deploy Plausible Analytics on a VPS →How to Deploy Pocket ID on a VPS →How to Deploy PocketBase on a VPS →How to Deploy Prometheus on a VPS →How to Deploy Psono on a VPS →How to Deploy Radarr on a VPS →How to Deploy Rocket.Chat on a VPS →How to Deploy SigNoz on a VPS →How to Deploy Sonarr on a VPS →How to Deploy Stalwart on a VPS →How to Deploy Stirling-PDF on a VPS →How to Deploy Supabase on a VPS →How to Deploy Synapse on a VPS →How to Deploy Taiga on a VPS →How to Deploy TeamPass on a VPS →How to Deploy Tinyauth on a VPS →How to Deploy Traefik on a VPS →How to Deploy Trilium on a VPS →How to Deploy Twenty CRM on a VPS →How to Deploy Umami on a VPS →How to Deploy Uptime Kuma on a VPS →How to Deploy Vaultwarden on a VPS →How to Deploy Vikunja on a VPS →How to Deploy wg-easy on a VPS →How to Deploy Wiki.js on a VPS →How to Deploy Zabbix on a VPS →How to Deploy Zitadel on a VPS →How to Deploy Zulip on a VPS →Docker & Compose on Ubuntu 26.04 →Install Open WebUI with Ollama →Adding AI-Powered Insights to Plausible Analytics →Building AI-Powered Apps with Supabase and pgvector →

We use analytics cookies (Google Analytics, PostHog) to see which guides are useful. No ad networks, no cross-site tracking. See our privacy policy.