Skip to main content
Open WebUI integration with Openlayer Open WebUI is a self-hosted AI chat platform that works with Ollama and OpenAI-compatible APIs. Openlayer connects to it through a Filter Function, Open WebUI’s built-in plugin system, so there is nothing extra to deploy. Every chat turn becomes a trace in Openlayer with:
  • The prompt and response, model, latency, token usage, and cost
  • A step for each tool call, including MCP tools and Open WebUI’s built-in tools such as web search and image generation
  • A retrieval step with the knowledge and web search sources the answer used
  • The Open WebUI user and chat, so you can follow users and sessions
  • Custom models, sub-agents, and Automations, each tagged with how the turn started
  • Optionally, the images, documents, and audio in the conversation, and your users’ ratings
Requests sent to Open WebUI’s API are traced the same way as chats in the UI.

Prerequisites

  • Open WebUI 0.11 or later, and an admin account
  • An Openlayer API key
  • A data source in your Openlayer project to receive the traces
To find your data source ID in Openlayer, open your project and copy the ID from the data source settings. The function calls it the inference pipeline ID.

Step 1: Set your Openlayer credentials

The function reads your credentials from environment variables on the Open WebUI server. Add them to the command you run Open WebUI with:
For self-hosted Openlayer, also set OPENLAYER_BASE_URL (for example, https://openlayer.example.com/v1).
You can enter the API key in the function’s valves instead (Step 3), but Open WebUI shows valve values in plain text to every admin. Environment variables keep the key out of the UI.

Step 2: Add the Openlayer function

  1. In Open WebUI, open the user menu and go to Admin Panel → Functions, then click Create.
  2. Name the function Openlayer Tracing, replace the contents of the editor with the code below, and click Save & Create.
Open WebUI installs the openlayer package listed in the function’s requirements the first time it loads the function. If your deployment sets ENABLE_PIP_INSTALL_FRONTMATTER_REQUIREMENTS=false, install openlayer in your Open WebUI image instead.
Functions run arbitrary code on your Open WebUI server. Only install functions from sources you trust.

Step 3: Turn the function on

  1. On the Functions page, switch the Openlayer Tracing toggle on.
  2. Open the function’s ⋯ menu and select Global, so it runs for every model.
The function’s valves (the gear icon) control what it captures. To change one, switch it from Default to Custom and save.

Step 4: Enable usage reporting

Go to Admin Panel → Settings → Models, open each model you want to track, and enable the Usage capability. Without it, chats streamed in the UI arrive in Openlayer without token counts or cost.

View traces in Openlayer

Send a message in Open WebUI, then open your data source in Openlayer. Each chat turn is one trace:
  • Open WebUI chat turn: the root step, with the conversation as its prompt and the reply as its output
  • Knowledge retrieval: when the answer used knowledge, attached files, or web search
  • LLM chat completion: the model, provider, and token usage for the whole turn, including every model call in a tool loop
  • One step per tool call, with its arguments and result
The trace’s session is the Open WebUI chat, its user is the Open WebUI user’s email, and its inference ID is the Open WebUI message ID. Its metadata records how the turn started in run_type: ui, api, automation, or subagent. An Open WebUI chat turn in Openlayer: the trace tree with the LLM chat completion and two tool steps, and the receipt image the user attached shown in the prompt

Agents and sub-agents

The function also traces the agents your users build in Open WebUI:
  • Custom models (Workspace → Models) are traced like any other model. The trace keeps the custom model’s ID in its metadata, and the LLM step uses the base model, so cost is calculated from the base model’s pricing.
  • Sub-agents that a model starts with Open WebUI’s delegate_task tool produce two traces. The parent turn has a delegate_task step with the sub-agent’s result. The sub-agent’s own run is a separate trace with its own tool calls and token usage, in the parent chat’s session, with run_type: subagent, parent_chat_id, and parent_message_id (the parent turn’s inference ID) in its metadata.
  • Automations are traced with run_type: automation and their automation_id.
  • Pipe Functions that run their own agent logic appear as a single turn with the Pipe’s final answer. The function doesn’t see the model calls inside a Pipe. To trace those, instrument the Pipe’s code with the Openlayer SDK. Its steps are published as their own trace.

Send agents to their own data sources

By default, every turn goes to one data source. To send some turns somewhere else, such as all sub-agent runs or one agent’s turns, set the Routes valve to a JSON object that maps a model ID or a run type to a data source ID:
The function sends each turn to the first match, in this order:
  1. The run type subagent or automation
  2. The model ID, such as a custom model’s ID
  3. The run type ui or api
  4. The default data source
Each trace goes to a single data source, so a delegate_task step stays in the parent turn’s trace. A sub-agent run routed elsewhere stays linked to its parent through its parent_chat_id and parent_message_id metadata. Every route uses the function’s API key, so each data source must be one that key can write to. If you capture user feedback, set the same value in the Openlayer Feedback function’s Routes valve.

Log images, files, and audio

Turn on the Upload Attachments valve to add the media in each chat turn to its trace:
  • Images in the user’s message, shown inside the prompt
  • Documents and audio files the user attached in that turn
  • Files a tool produced, such as a generated image, on that tool’s step
Openlayer shows images inline, PDFs in a page viewer, and audio in a player. See Trace multimodal data for how attachments work.
Uploading attachments sends your users’ files to your Openlayer workspace storage, so enable it only when your privacy requirements allow it. On self-hosted Openlayer, attachment uploads require Amazon S3 storage.

Capture user feedback

When users rate a response in Open WebUI (thumbs up or down, with an optional score, reason, and comment), an Event Function can add the rating to that response’s trace:
  1. Go to Admin Panel → Functions and click Create. Name the function Openlayer Feedback, replace the contents of the editor with the code below, and click Save & Create.
  2. Switch its toggle on. Event functions handle every event, so they don’t need Global.
The rating is added to the trace as user_rating (1 or -1), along with user_rating_reason, user_rating_comment, and user_rating_details (the optional 1–10 score). The function uses the same environment variables as the tracing function and finds the trace by its message ID. If you use routes, set the same value in this function’s Routes valve so ratings reach traces in any of those data sources. See Update existing traces.

Limitations

  • Background tasks, such as title, tag, and follow-up generation, search query generation, and autocomplete, don’t pass through filters, so they aren’t traced.
  • Requests to Open WebUI’s direct provider routes (/openai/... and /ollama/...) skip filters and aren’t traced. Requests to /api/chat/completions are traced unless ENABLE_API_OUTLET_FILTERS is set to false.
  • Tool steps don’t have individual timings, because Open WebUI reports one duration for the whole turn.

Troubleshooting

Traces don’t appear in Openlayer

  1. Check that the function is switched on and set to Global.
  2. Check the API key and data source ID, in the environment variables or the valves.
  3. Turn on the Debug valve and check the Open WebUI logs (docker logs open-webui). Each traced turn logs Openlayer: traced message, and errors log Openlayer: failed to trace chat turn.
  4. Make sure the Open WebUI server can reach api.openlayer.com, or your OPENLAYER_BASE_URL.

Token counts and cost are missing

Enable the Usage capability for the model (Step 4).

Each turn is traced twice

If you set up an earlier version of this integration that used Open WebUI Pipelines, remove that pipeline in Admin Panel → Settings → Pipelines.

Learn more