How to Connect n8n to Ollama (Local LLM) for Private AI Automations — Step-by-Step (2026)

If you like the idea of “AI automations” but don’t love the idea of sending every customer message, internal doc, or business process to a third-party API, you’re going to love this setup:

  • Ollama runs an LLM locally (on your PC/server).
  • n8n orchestrates the workflow (webhooks, schedules, integrations, routing).
  • You get private, repeatable AI workflows you can run 24/7—often without paying per token.

This guide shows you exactly how to connect n8n to Ollama, build a working webhook workflow, avoid the most common connection errors, and structure the post in a way that plays nicely with Rank Math SEO (headings, FAQs, internal links, and snippet settings).


Table of Contents

What you’ll build (3 practical examples)

By the end, you’ll be able to run workflows like:

  1. Webhook → AI reply generator
    Send text to an n8n webhook, have Ollama draft a response, then return the response as JSON.
  2. Helpdesk triage (local)
    Ingest a ticket, classify urgency + topic, then route to the right queue—all without cloud LLM calls.
  3. Content assistant (local)
    Turn a rough blog idea into an outline, FAQ section, and SEO-friendly summary.

Even if you only build the first example today, you’ll have the foundation for everything else.


Prerequisites (keep it simple)

You’ll need:

  • Ollama installed and running on the machine you want to use as the “LLM server.”
  • n8n running (cloud, desktop, or self-hosted).
  • A basic understanding of n8n nodes (Trigger → Processing → Output).

Important “reality check” about hosting

  • If your n8n is cloud-hosted, it cannot reach your localhost Ollama unless you expose Ollama to the internet (not recommended) or put everything behind a secure network/tunnel.
  • The easiest path is: Ollama + n8n on the same machine (or same LAN / same Docker network).

Step 1: Confirm Ollama is running (and test the API)

Ollama runs a local API endpoint you can call from other apps.

1) Check the base URL

Ollama’s API is typically available at:

texthttp://localhost:11434/api

2) Test with a simple generate request

Run this from a terminal:

Bashcurl http://localhost:11434/api/generate -d '{
  "model": "gemma3",
  "prompt": "Write one sentence explaining what Ollama is."
}'

If you get a JSON response back, you’re good. If you get “connection refused,” fix Ollama first before touching n8n.

3) Know the endpoint you’ll use most

For “chat style” workflows, you’ll usually use:

textPOST http://localhost:11434/api/chat

Step 2: Decide how you’ll connect n8n to Ollama (2 options)

There are two common ways to do this:

If your n8n version includes Ollama-related credentials/nodes, this is usually the cleanest setup.

What you gain:

  • Less manual JSON
  • Better maintainability
  • Faster iteration

Option B (universal): Use the HTTP Request node to call Ollama’s API directly

This works on basically any n8n setup because it’s just an HTTP call.

What you gain:

  • Full control over request/response format
  • Works even if you don’t want to use AI-specific nodes

In this post I’ll show Option B as the “always works” baseline, and I’ll also explain where Option A fits.


Step 3: Create the Ollama credential in n8n (and avoid the most common error)

If you’re using n8n’s Ollama credentials:

  1. Go to Credentials → New
  2. Search: Ollama
  3. Set Base URL

Use this first:

texthttp://localhost:11434

If you get ECONNREFUSED ::1:11434, use this instead:

texthttp://127.0.0.1:11434

That one change fixes a surprising number of “it works in my browser but not in n8n” problems, because localhost can resolve to IPv6 on some systems.

If you’re routing through Open WebUI or another authenticated proxy

Some setups place Ollama behind a proxy that requires auth. In that case you may need to set an API key (Bearer token) in the credential, and the base URL would be whatever your proxy endpoint is.


Step 4: Build your first workflow (Webhook → Ollama → Respond)

This is the simplest “proof of life” workflow and it’s incredibly useful. You’ll end up with your own mini API endpoint that returns AI output.

Workflow overview

  1. Webhook (Trigger) – receives input text
  2. HTTP Request (to Ollama) – sends text to the local model
  3. Respond to Webhook – returns the AI output

4.1 Add the Webhook trigger node

Create a new workflow and add:

  • Node: Webhook
  • HTTP Method: POST
  • Path: something like local-ai-reply

In the Webhook node settings, configure it so it responds using the dedicated response node:

  • Respond: “Using ‘Respond to Webhook’ node” (wording may vary by version)

This makes your workflow behave like a proper API endpoint.

Tip: n8n gives you a Test URL and a Production URL. Use the Test URL while building, then switch to Production when you activate the workflow.


4.2 Add the HTTP Request node (call Ollama /api/chat)

Add:

  • Node: HTTP Request
  • Method: POST
  • URL:texthttp://127.0.0.1:11434/api/chat(If localhost works for you, you can use that—127.0.0.1 is just safer.)

Now set up the body:

  • Send Body: ON
  • Body Content Type: JSON
  • Specify Body: “Using JSON” (recommended)

Paste this JSON:

JSON{
  "model": "gemma3",
  "messages": [
    {
      "role": "user",
      "content": "={{$json.body.text}}"
    }
  ]
}

What input should your webhook receive?

We’re expecting a request body like:

JSON{
  "text": "Write a polite reply asking for more details about the issue."
}

So the webhook’s incoming JSON becomes available as $json.body.text.

If your incoming payload structure differs (for example it comes in as $json.text), update the expression accordingly.


4.3 Extract the assistant message cleanly

Ollama’s /api/chat response includes a message object with role and content.

In many n8n setups, the HTTP Request node will output the response JSON as fields you can reference like:

  • {{$json.message.content}}

So add a Set node (optional, but makes output clean):

  • Node: Set
  • Create field:
    • reply = {{$json.message.content}}

Now your workflow output is a simple { "reply": "..." }.


4.4 Add “Respond to Webhook”

Add:

  • Node: Respond to Webhook
  • Respond With: “First Entry JSON” (or similar)
  • Ensure it returns the JSON from your Set node (the { reply: ... })

Now test it:

Bashcurl -X POST "YOUR_TEST_WEBHOOK_URL" \
  -H "Content-Type: application/json" \
  -d '{"text":"Summarize this in one sentence: I want a private AI workflow using Ollama + n8n."}'

You should get a JSON response back that includes your model’s answer.


Step 5: Upgrade your workflow (make it reliable, not just “cool”)

A workflow that “sometimes works” isn’t automation—it’s a demo. Here’s how to harden it.

Add timeouts + retries (lightly)

  • Set a reasonable timeout on the HTTP request.
  • If you see occasional failures, add a simple retry or fallback path.

Force structured outputs for downstream apps

If your next step is “save to Google Sheets / Notion / Airtable,” don’t ask the model for a paragraph. Ask for JSON.

Example prompt:

Return valid JSON only with keys: categorypriorityone_sentence_summary.

Then validate it (even lightly) before inserting into a database.

Log the raw request + raw response

When something breaks, logs save hours.

A practical pattern:

  • Save input_textmodel_nametimestamp, and raw_response into a simple “Logs” table (Airtable/Sheets/DB).

Step 6: Fix common n8n ↔ Ollama connection problems

Problem: “Couldn’t connect” / ECONNREFUSED

Try these in order:

  1. Replace localhost with:text127.0.0.1
  2. Confirm Ollama is running and listening on port 11434.
  3. If you’re using Docker, understand networking:
    • n8n inside Docker cannot always reach host services via localhost.
    • You may need Docker-specific host addressing or to put both services on the same Docker network.

Problem: Webhook works in “Test” but not “Production”

This is usually because:

  • You didn’t activate the workflow, or
  • You’re still calling the Test URL after switching modes.

n8n treats test and production webhooks differently; production requires the workflow to be active.

Problem: 400 Bad Request / “could not parse JSON body”

This often happens when the request body becomes a string instead of JSON.

Fixes:

  • In the HTTP Request node, use Body Content Type: JSON and Specify Body: Using JSON
  • Avoid passing a “JSON-like string.” Make sure you’re sending actual JSON.

Step 7: Security & privacy (don’t skip this)

A local AI workflow is only “private” if you keep the endpoints protected.

Protect your webhook endpoint

At minimum:

  • Use a secret path (not security by itself, but helps)
  • Add authentication (header token, basic auth, etc.)
  • Restrict who can call it

n8n’s Webhook node includes options like IP whitelisting and CORS configuration, which are useful if you know your caller’s IP ranges.

Don’t expose Ollama directly to the public internet

If you need remote access, do it properly:

  • put it behind a VPN
  • use a secure reverse proxy with auth
  • limit origins and ports

Step 8: On-page SEO tips (Rank Math friendly)

Here’s how to structure this post so Rank Math typically scores it well and Google understands it clearly.

1) Use your focus keyword in the right places

Include “connect n8n to ollama” in:

  • SEO title
  • first paragraph (naturally)
  • one H2 (or H1) + a couple of H3s
  • the slug/permalink

Internal links help Google crawl and help users discover more content.

In this post, add internal links to:

  • your Ollama/Local LLM install guide
  • your Make vs Zapier vs n8n comparison
  • your “best local LLM GPU” or “best AI productivity tools” post

Rank Math can show internal/external link counts and incoming links so you can keep your site structure healthy.

3) Add an FAQ section (good for long-tail)

Even though FAQ rich results are shown less often today, FAQs still help you:

  • capture long-tail queries
  • improve readability
  • increase time on page

If you use Rank Math’s FAQ block, keep questions short and match the words people actually type into Google.


FAQs (copy into Rank Math FAQ block)

How do I connect n8n to Ollama on localhost?

Run Ollama locally, confirm the API works on port 11434, then use either n8n’s Ollama credentials/nodes or an HTTP Request node calling /api/chat with a JSON body.

Why does n8n show ECONNREFUSED ::1:11434 for Ollama?

This often happens when localhost resolves to IPv6 (::1). Change the base URL to http://127.0.0.1:11434 to force IPv4.

Can n8n cloud connect to my local Ollama?

Not directly—cloud n8n can’t reach your local machine’s localhost unless you securely expose it (VPN/tunnel/proxy). The easiest approach is running n8n and Ollama on the same machine or network.

Do I need an API key for Ollama in n8n?

Usually no for local Ollama. You may need a key if you connect through an authenticated proxy service (for example, a proxy in front of Ollama).

What’s the best Ollama endpoint for chat workflows in n8n?

Use POST /api/chat and pass a messages array. It matches “assistant chat” style interactions and returns a structured response with the assistant’s message content.


Final thoughts

If you’ve been waiting to build “AI automations” until you can afford more API calls—or until you’re comfortable sending data to third parties—this Ollama + n8n setup is the unlock.

Start with the simplest webhook workflow, then graduate to:

  • ticket classification,
  • content pipelines,
  • lead scoring,
  • and structured JSON outputs for your apps.

Once it’s working locally, you can decide if (and how) to scale it to a server.

Newsletter Updates