Error with Ollama Chat model integrating with AI Agent Node

I am trying to use the Email Triage Agent as the template for what I want to do. Instead of using ChatGPT, I want to use Ollama. However, whenever I run it, I get the error fetch failed. I’ve tried the workflow by using Google’s Gemini and it worked. I’ve also tried using the Ollama model with the Basic Langchain node and that works.

Hey there @Kelvin_Kang

The “fetch failed” error usually means n8n can’t actually reach your local Ollama endpoint, not that the model or node is broken. Since Gemini works, and the Basic LangChain node also works with Ollama, the issue is almost certainly with the Email Triage Agent’s AI Model node configuration.

Here’s what you can try:

  1. Use an OpenAI-compatible credential

    • Go to Credentials → OpenAI (compatible).

    • Base URL: http://localhost:11434/v1 (or http://host.docker.internal:11434/v1 if n8n runs in Docker).

    • API Key: just type anything (e.g. ollama).

  2. Select that credential in the AI Model node

    • Open the “AI Model” or “Agent” node inside the Email Triage Agent template.

    • Pick your new Ollama credential.

    • Set the Model name exactly as it appears in Ollama (llama3:8b-instruct, qwen2.5:7b-instruct, etc.).

  3. Optional checks

    • Test with streaming off first.

    • Try a small input prompt to rule out timeouts.

    • Run this from your terminal to confirm connectivity:

      curl http://localhost:11434/v1/chat/completions \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer ollama" \
        -d '{"model":"llama3:8b-instruct","messages":[{"role":"user","content":"Hello"}]}'
      
      

      If that works, n8n will too once the Base URL matches.

Most often it’s just the missing /v1 or wrong hostname inside Docker causing “fetch failed”. Give that a try and it should fix it.

Hi there! Thank you for the response. I’ve tried to update the base URL with v1 and I get the following error:

However, when I remove the V1, it works

When I try typing the curl command, it looks like it works

➜  ~ curl http://ollama.coburgcrescent.lan:11434/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ollama" \
  -d '{"model":"llama3.1:8b","messages":[{"role":"user","content":"Hello"}]}'
{"id":"chatcmpl-300","object":"chat.completion","created":1759783973,"model":"llama3.1:8b","system_fingerprint":"fp_ollama","choices":[{"index":0,"message":{"role":"assistant","content":"Hello! How can I assist you today?"},"finish_reason":"stop"}],"usage":{"prompt_tokens":11,"completion_tokens":10,"total_tokens":21}}

What’s really fascinating, is that when used in the Basic Lang node and the Ollama node, it works fine there. I’m including that flow for context.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.