Skip to main content

Overview

Open WebUI provides several extensibility mechanisms to add custom functionality:
  1. Pipelines - Python-based middleware for LLM interactions
  2. Functions/Tools - Native Python functions with code editor
  3. MCP Servers - Model Context Protocol integration

Pipelines Plugin Framework

Pipelines allow you to inject custom logic and Python libraries into Open WebUI’s request/response flow.

What Are Pipelines?

Pipelines act as middleware between Open WebUI and LLM providers, enabling:
  • Rate limiting and usage controls
  • Request/response filtering and modification
  • Custom authentication and authorization
  • Integration with monitoring tools (Langfuse, etc.)
  • Translation services
  • Content moderation and toxic message filtering
  • Custom model routing logic

Repository

Pipelines are maintained in a separate repository: https://github.com/open-webui/pipelines

Getting Started with Pipelines

1. Clone the Pipelines Repository

2. Install Dependencies

3. Run Pipelines Server

The server starts on http://localhost:9099 by default.

4. Connect to Open WebUI

In Open WebUI settings:
  1. Go to Admin SettingsConnections
  2. Set OpenAI API URL to: http://localhost:9099
  3. Pipelines will now intercept requests

Creating a Custom Pipeline

Pipelines are Python classes that inherit from base pipeline types.

Basic Pipeline Structure

Save Your Pipeline

Save the file in the pipelines/ directory:
Restart the pipelines server to load your pipeline.

Pipeline Examples

Explore real-world examples in the repository: Rate Limiting:
Translation:
Content Filtering:
Usage Monitoring:
Function Calling:

Pipeline Methods

Core Methods

  • __init__() - Initialize pipeline and valves
  • on_startup() - Setup code (load models, connect to services)
  • on_shutdown() - Cleanup code
  • inlet(body, user) - Intercept and modify requests
  • outlet(body, user) - Intercept and modify responses

Advanced Methods

  • pipe() - Full control over request/response cycle
  • on_valves_updated() - React to configuration changes

Valves (Configuration)

Valves are pipeline settings that can be modified through the UI:
Users can update these values without modifying code.

Native Python Functions/Tools

Open WebUI includes a built-in code editor for creating Python functions that LLMs can call.

Creating a Function

  1. Navigate to WorkspaceTools
  2. Click Create New Tool
  3. Write your Python function
  4. Save and enable

Function Structure

Function Features

  • Type Hints: Use Python type hints for LLM parameter understanding
  • Docstrings: Provide clear descriptions for the LLM
  • User Context: Access __user__ parameter for user information
  • Dependencies: Import standard library or installed packages
  • Error Handling: Implement proper error handling

Installing Dependencies

Functions can use any Python package installed in the Open WebUI environment:
Or add to pyproject.toml for permanent installation.

Function Security

Safe Mode: Enable safe mode to deactivate all functions:
RestrictedPython: Functions run in a restricted environment to prevent dangerous operations.

MCP (Model Context Protocol) Servers

MCP servers provide standardized context to LLMs through a protocol.

Configuring MCP Servers

Available MCP Servers

  • Filesystem: File system access
  • Git: Repository interaction
  • GitHub: GitHub API integration
  • Slack: Slack workspace integration
  • PostgreSQL: Database queries
  • Brave Search: Web search
See MCP Documentation for more servers.

Tool/Terminal Servers

Connect external tool servers to Open WebUI.

Configuration

Terminal Server

Provide terminal access for code execution:

Development Best Practices

Testing

  1. Test locally before deploying
  2. Use the dev environment for iteration
  3. Test with various LLM providers
  4. Validate error handling

Error Handling

Logging

Performance

  • Use async/await for I/O operations
  • Cache expensive computations
  • Avoid blocking operations in pipelines
  • Consider rate limiting for external APIs

Security

  • Validate all user inputs
  • Use environment variables for secrets
  • Implement proper authentication
  • Sanitize outputs before returning
  • Be cautious with code execution

Deployment

Production Pipelines

For production deployments:

Environment Variables

Examples and Templates

Complete Pipeline Example

See the Pipelines Examples Directory for:
  • Authentication pipelines
  • Rate limiting
  • Content filtering
  • Custom model routing
  • Monitoring integrations
  • Translation services

Function Examples

Check the Open WebUI community for shared functions:

Troubleshooting

Pipeline Not Loading

  1. Check pipeline file syntax
  2. Ensure class is named Pipeline
  3. Verify no import errors
  4. Check pipelines server logs

Function Not Executing

  1. Verify function is enabled
  2. Check for syntax errors in code editor
  3. Ensure dependencies are installed
  4. Review function logs

Performance Issues

  1. Profile slow pipelines
  2. Use async operations
  3. Implement caching
  4. Consider moving logic to background tasks

Resources

Next Steps