Integrating n8n with Open WebUI: Building advanced AI chatbots and workflows

Andreas Nigg
Andreas Nigg · Co-Founder, Pondhouse Data
Published Updated 10 min read
Integrating n8n with Open WebUI: Building advanced AI chatbots and workflows
On this page

You can add almost any feature to Open WebUI by connecting it to n8n. The setup has two parts: an n8n workflow that starts with a webhook, and an Open WebUI pipe function that sends each chat message to that webhook and shows the workflow's answer in the chat. This guide walks through both, with the full pipe code.

Why bother? AI chatbots like ChatGPT deliver real productivity gains, but as we outlined in our post about Open WebUI, hosted solutions have their limitations. Privacy is a valid concern, and you are limited to the features the provider has built. These are the main reasons to use open source, self-hosted solutions like Open WebUI or LibreChat.

n8n is an open-source workflow automation tool. With its low-code interface you can build complex workflows that automate tasks, connect to APIs and transform data. Hooking it up to Open WebUI gives your chat interface access to all of that.

The sections below cover the setup on both sides, practical use cases and the code you need for your own n8n and Open WebUI integration.

Understanding n8n and Open WebUI

What is Open WebUI?

Open WebUI is a self-hosted, open-source alternative to ChatGPT with a user-friendly interface for working with large language models. It has advanced features like document RAG (Retrieval Augmented Generation), custom model creation and an extensible pipeline system.

Its main features:

  • Support for multiple LLM providers (OpenAI, Ollama, etc.)
  • Built-in RAG capabilities for document interaction
  • Python code execution directly in the browser
  • Extensible pipeline system for custom functionality

For a full introduction, see our detailed guide on Open WebUI.

What is n8n?

n8n is an open-source workflow automation platform for building complex workflows in a visual, low-code interface. It connects different services and APIs, which makes it a good fit for automated processes that would otherwise need a lot of code.

What n8n offers:

  • Visual workflow builder with drag-and-drop interface
  • Hundreds of pre-built integrations with various services
  • AI agent nodes for LLM integration
  • Custom code nodes for extending functionality
  • Webhook support for triggering workflows

To learn more about n8n and how to build AI agents with it, see our guide on building AI agents with n8n.

Setting up the integration between n8n and Open WebUI

Before you start, make sure you have a running Open WebUI instance and a running n8n instance. You can find setup instructions for Open WebUI in our Open WebUI guide and for n8n in our n8n guide.

How does the n8n and Open WebUI integration work?

The integration creates a two-way communication channel between n8n and Open WebUI. It has two components:

  1. Open WebUI function: Open WebUI has a function system that runs custom code when certain events occur. We'll create a function that runs whenever a user sends a message in the chat interface.

  2. n8n webhook trigger: On the n8n side, we set up a workflow that starts with a webhook trigger. Our Open WebUI function calls this webhook, so n8n can process the message and return a response.

The basic flow:

  1. User sends a message in Open WebUI
  2. Open WebUI function intercepts the message
  3. Function makes an HTTP request to the n8n webhook
  4. n8n processes the message through its workflow
  5. n8n returns a response to Open WebUI function
  6. Open WebUI displays the response to the user

This way you get n8n's workflow capabilities behind Open WebUI's chat interface. You can process messages, call external services and transform data without the user ever leaving the chat.

Benefits of this integration approach

  • Your chatbot can use any of n8n's integrations.
  • A simple chat message can trigger a complex, multi-step process.
  • The UI stays clean while the complex logic lives in n8n.
  • You build sophisticated workflows without much programming.

The next sections set up both sides of the integration, starting with the n8n webhook workflow and then the Open WebUI function that calls it.

Creating the n8n webhook workflow

The n8n webhook workflow is quick to set up:

  1. Create a new workflow: In your n8n instance, create a new workflow and add a "Webhook" node as the starting point.

  2. Configure the webhook node:

    • Set the HTTP method to "POST" and copy the generated webhook URL. The Open WebUI function uses this URL to send messages to n8n.
    • Set "Respond" to "Using 'Respond to Webhook' Node", so that n8n responds to the webhook request after the workflow has finished.
    • Set "Authentication" to "Header Auth".
    • Create a new credential for the webhook node. Note down the key you used for the credential.

    n8n Webhook node with POST method, Header Auth and Respond to Webhook setting

  3. Create your workflow: Connect whatever workflow you want to the webhook node. For example, you can use the "OpenAI" node to process the incoming message and generate a response.

  4. Finally, add a "Respond to Webhook" node: This node sends the response back to Open WebUI. Connect it to the last node in your workflow. In the node settings, choose Respond with: "First incoming item".

A simple flow might look like this:

n8n workflow: Webhook, Edit Fields, AI Agent with tools, Respond to Webhook

Tip: Testing your n8n workflow

Testing a workflow that only has a webhook trigger is cumbersome. Add a "When chat message received" trigger next to your webhook trigger and connect both triggers to an "Edit Fields" node, which merges them into one workflow. In the "Edit Fields" node, select "JSON mode" and add the following JSON:

1{
2 "chatInput": {{ JSON.stringify($json.body?.chatInput ?? $json.chatInput) }},
3 "sessionId": "{{ $json.body?.sessionId ?? $json.sessionId }}",
4 "user": {{ "\"" +$json.body?.user.name + "\"" ?? "" }}
5}

The node takes either the webhook input or the chat message input and creates a unified input for the rest of the workflow.

Chat message trigger and webhook trigger both connected to an Edit Fields node

To test your workflow, click the "Open chat" button and enter a message.

Creating the Open WebUI function

With the n8n webhook workflow in place, the next step is an Open WebUI pipe function.

What are Open WebUI functions?

Open WebUI has an extension system called "functions" for customizing and extending the platform. One of the most useful function types is the "Pipe" function, which lets you create custom "models" or "agents" within Open WebUI.

Think of Pipes as custom processing pathways: they intercept messages, process them however you like, and return responses. For the n8n integration, we create a Pipe function that sends user messages to our n8n webhook and displays the responses.

Basic structure of a Pipe function

A Pipe function in Open WebUI follows this basic structure:

Note: This is just a simplified example for understanding pipes. The real example is shown further below.

1from pydantic import BaseModel, Field
2import requests
3
4class Pipe:
5 # Configuration options (Valves)
6 class Valves(BaseModel):
7 WEBHOOK_URL: str = Field(
8 default="",
9 description="The n8n webhook URL to send messages to"
10 )
11 AUTH_KEY: str = Field(
12 default="",
13 description="Authentication key for the webhook"
14 )
15
16 # Initialize the Pipe
17 def __init__(self):
18 self.valves = self.Valves()
19
20 # Define the pipe function that processes messages
21 def pipe(self, body: dict, __user__: dict = None):
22 try:
23 message = extract_user_message()
24 payload = prepare_payload(message, __user__)
25 result = send_to_n8n(payload)
26 return format_response(result)
27
28 except Exception as e:
29 return {"error": str(e)}

The main components:

  1. Valves: configuration options that users can set when using your Pipe. Here, we need the n8n webhook URL and an authentication key.

  2. __init__ method: initializes the Pipe and sets up the Valves.

  3. pipe method: this is where the work happens. It receives the user's message, processes it and returns a response. In our integration:

    • We extract the user's message from the input
    • We prepare a payload for n8n with the message and user information
    • We send a request to the n8n webhook
    • We format the response from n8n to match what Open WebUI expects

With this structure, the Pipe acts as a bridge between Open WebUI and n8n.

Implementing the n8n integration pipe

With the basic structure of a pipe clear and the n8n webhook ready, here is the actual implementation.

Note: We took heavy inspiration from this community pipe by Cole Medin (coleam). We adjusted the session handling and the user handling to make it more robust and easier to use. We also changed the request handling to allow async status messages. Nothing you need to worry about, dear reader, but we want to acknowledge that we built on top of Cole's work.

  1. Fill out the name and description of your pipe function. You can use whatever you like, but we recommend something like "n8n Assistant" and "Pipe to call n8n workflows" to follow this tutorial.

  2. Create the function code:

    1"""
    2title: n8n Pipe Function
    3author: Cole Medin / Andreas Nigg (Pondhouse Data GmbH)
    4version: 0.2.0
    5
    6This module defines a Pipe class that utilizes an N8N workflow for an Agent
    7"""
    8
    9from typing import Optional, Callable, Awaitable
    10from pydantic import BaseModel, Field
    11import os
    12import time
    13import aiohttp
    14import asyncio
    15
    16
    17class Pipe:
    18 class Valves(BaseModel):
    19 n8n_url: str = Field(
    20 default="https://n8n.[your domain].com/webhook/[your webhook URL]"
    21 )
    22 n8n_bearer_token: str = Field(default="...")
    23 input_field: str = Field(default="chatInput")
    24 response_field: str = Field(default="output")
    25 emit_interval: float = Field(
    26 default=2.0, description="Interval in seconds between status emissions"
    27 )
    28 enable_status_indicator: bool = Field(
    29 default=True, description="Enable or disable status indicator emissions"
    30 )
    31
    32 def __init__(self):
    33 self.type = "pipe"
    34 self.id = "n8n_pipe"
    35 self.name = "N8N Pipe"
    36 self.valves = self.Valves()
    37 self.last_emit_time = 0
    38
    39 async def emit_status(
    40 self,
    41 __event_emitter__: Callable[[dict], Awaitable[None]],
    42 level: str,
    43 message: str,
    44 done: bool,
    45 ):
    46 current_time = time.time()
    47 if (
    48 __event_emitter__
    49 and self.valves.enable_status_indicator
    50 and (
    51 current_time - self.last_emit_time >= self.valves.emit_interval or done
    52 )
    53 ):
    54 await __event_emitter__(
    55 {
    56 "type": "status",
    57 "data": {
    58 "status": "complete" if done else "in_progress",
    59 "level": level,
    60 "description": message,
    61 "done": done,
    62 },
    63 }
    64 )
    65 self.last_emit_time = current_time
    66
    67 async def make_n8n_request(self, payload: dict) -> dict:
    68 """Separate async function to handle the N8N API request"""
    69 headers = {
    70 "Authorization": f"Bearer {self.valves.n8n_bearer_token}",
    71 "Content-Type": "application/json",
    72 }
    73
    74 async with aiohttp.ClientSession() as session:
    75 async with session.post(
    76 self.valves.n8n_url, json=payload, headers=headers
    77 ) as response:
    78 if response.status == 200:
    79 response_data = await response.json()
    80 return response_data[self.valves.response_field]
    81 else:
    82 error_text = await response.text()
    83 raise Exception(f"Error: {response.status} - {error_text}")
    84
    85 async def pipe(
    86 self,
    87 body: dict,
    88 __user__: Optional[dict] = None,
    89 __metadata__: Optional[dict] = None,
    90 __event_emitter__: Callable[[dict], Awaitable[None]] = None,
    91 __event_call__: Callable[[dict], Awaitable[dict]] = None,
    92 ) -> Optional[dict]:
    93 n8n_response = None
    94
    95 try:
    96 await self.emit_status(
    97 __event_emitter__, "info", "Calling N8N Workflow...", False
    98 )
    99
    100 messages = body.get("messages", [])
    101
    102 # Verify a message is available
    103 if messages:
    104 question = messages[-1]["content"]
    105 if "Prompt: " in question:
    106 question = question.split("Prompt: ")[-1]
    107
    108 await self.emit_status(
    109 __event_emitter__, "info", "Processing request...", False
    110 )
    111
    112 # Prepare payload
    113 payload = {"sessionId": __metadata__["chat_id"]}
    114 payload[self.valves.input_field] = question
    115 payload["user"] = __user__
    116
    117 # Make the API request
    118 n8n_response = await self.make_n8n_request(payload)
    119
    120 # Set assistant message with chain reply
    121 body["messages"].append({"role": "assistant", "content": n8n_response})
    122
    123 await self.emit_status(
    124 __event_emitter__, "info", "Processing response...", False
    125 )
    126
    127 else:
    128 await self.emit_status(
    129 __event_emitter__,
    130 "error",
    131 "No messages found in the request body",
    132 True,
    133 )
    134 body["messages"].append(
    135 {
    136 "role": "assistant",
    137 "content": "No messages found in the request body",
    138 }
    139 )
    140 return "No messages found in the request body"
    141
    142 except Exception as e:
    143 error_message = f"Error: {str(e)}"
    144 await self.emit_status(
    145 __event_emitter__,
    146 "error",
    147 error_message,
    148 True,
    149 )
    150 body["messages"].append({"role": "assistant", "content": error_message})
    151 return {"error": error_message}
    152
    153 finally:
    154 await self.emit_status(__event_emitter__, "info", "Complete", True)
    155
    156 return n8n_response
  3. Click "Save" to create your pipe function

Configuring the n8n pipe in Open WebUI

After creating the pipe, configure it with your n8n webhook URL and authentication key:

  1. Go to the Admin Panel - Functions tab in your Open WebUI instance.
  2. Find and select your "n8n Assistant" function
  3. Click on the settings icon next to the model name
  4. Enter the fields as described
  5. Click "Save"

Valves settings of the n8n pipe in Open WebUI

How the n8n pipe works

Here's how the n8n integration pipe works in detail:

  1. Configuration through Valves:

    • n8n_url: The webhook URL from your n8n workflow
    • n8n_bearer_token: The authentication token you set up in n8n
    • input_field: The field name where the user's message will be sent (default: "chatInput")
    • response_field: The field name where n8n's response is expected (default: "output")
    • emit_interval and enable_status_indicator: Control status updates during processing
  2. Initialization:

    • The __init__ method sets up the pipe with a unique ID and name
    • It initializes the valves with default values that the user can override
  3. Status updates:

    • The emit_status method gives the user real-time feedback during processing
    • It shows "in_progress" indicators while waiting for n8n to respond
    • The user can see that something is happening
  4. Making the n8n request:

    • The make_n8n_request method handles the HTTP communication with n8n
    • It sends the user's message and session information to the webhook
    • It includes the authentication headers and handles the response
  5. The main pipe logic:

    • Extracts the latest user message from the conversation
    • Creates a payload with the message, session ID, and user information
    • Makes an asynchronous request to the n8n webhook
    • Processes the response and adds it to the conversation
    • Handles errors gracefully, showing error messages in the chat if something goes wrong
  6. Response handling:

    • The pipe appends the n8n response to the messages array with the role "assistant"
    • That's all Open WebUI needs to display the response in the chat interface

The Open WebUI side stays simple. All the complex logic lives in your n8n workflow, and the pipe just passes messages between the two systems.

Use cases for the n8n and Open WebUI integration

With the integration set up, here are some practical use cases.

1. Database-powered chatbot

Connect your chatbot to your company database to answer questions about inventory, customer data, or sales metrics:

  • User asks: "How many products do we have in stock?"
  • Open WebUI sends the question to n8n
  • n8n workflow queries your database
  • Results are formatted and sent back to the user

2. Multi-API orchestration

Combine multiple APIs in one workflow to answer a single question:

  • User asks: "What's the weather forecast for my upcoming trip to Berlin?"
  • n8n workflow checks the user's calendar for trip dates
  • Then queries a weather API for the forecast
  • Combines the information into a single, coherent response

3. Document processing and generation

Build workflows that generate and process documents:

  • User requests: "Create a sales report for Q1"
  • n8n workflow pulls data from your CRM
  • Generates a PDF report
  • Uploads it to cloud storage
  • Returns a download link to the user

The same pattern works in the other direction: a workflow that reads incoming documents and returns structured data. Our guide to document extraction with LLMs shows the extraction step.

4. Multi-model orchestration

Use different AI models for different tasks:

  • User uploads an image with text
  • n8n workflow uses a vision model to extract text
  • Then uses a language model to analyze the content
  • Finally, uses a specialized model to generate a response

Conclusion

Connecting n8n and Open WebUI takes two pieces: an n8n workflow that starts with a webhook node and ends with a "Respond to Webhook" node, and an Open WebUI pipe function that forwards chat messages to that webhook. Together they give you a chat interface that can do more than either tool alone.

This approach gives you:

  • Complete control over your data and workflows
  • Extensibility through n8n's integrations
  • Low-code development that speeds up implementation
  • Self-hosted infrastructure for privacy and security

A good next step is to swap the simple OpenAI node for your own workflow, for example one of the use cases above. If you build something useful, share it with the community.

If you want a self-hosted chat setup like this connected to your company's systems, our AI consulting team sets them up with clients.

Further reading

Interested in building high-quality AI agent systems?

We prepared a comprehensive guide based on cutting-edge research for how to build robust, reliable AI agent systems that actually work in production. This guide covers:

  • Understanding the 14 systematic failure modes in multi-agent systems
  • Evidence-based best practices for agent design
  • Structured communication protocols and verification mechanisms
Andreas Nigg

About the author

Andreas Nigg

Co-Founder, Pondhouse Data

Andreas has spent more than eight years building data applications. At Pondhouse Data he designs and ships AI systems and integrates them into complex, real-world environments.