Backend-Controlled API Flow
Backend-Controlled, UI-Compatible API Flow
This tutorial is a community contribution and is not supported by the Open WebUI team. It serves only as a demonstration on how to customize Open WebUI for your specific use case. Want to contribute? Check out the contributing tutorial.
This tutorial demonstrates how to implement server-side orchestration of Open WebUI conversations while ensuring that assistant replies appear properly in the frontend UI. This approach requires zero frontend involvement and allows complete backend control over the chat flow. This tutorial has been verified to work with Open WebUI version v0.6.15. Future versions may introduce changes in behavior or API structure.
Prerequisites
Before following this tutorial, ensure you have:
- A running Open WebUI instance
- Valid API authentication token
- Access to the Open WebUI backend APIs
- Basic understanding of REST APIs and JSON
- Command-line tools:
curl,jq(optional for JSON parsing)
Overview
This tutorial describes a comprehensive 6-step process that enables server-side orchestration of Open WebUI conversations while ensuring that assistant replies appear properly in the frontend UI.
If your goal is to have the model use tools (built-in tools, workspace tools, MCP servers or a terminal) and have Open WebUI execute them server-side, see Server-Side Tool Calling (API). It builds on the chat structures documented here and adds the fields that switch tool execution on.
Process Flow
The essential steps are:
- Create a new chat with user and assistant messages: Initialize the conversation with the user's input and an empty assistant placeholder
- Trigger the assistant completion: Generate the actual AI response (with optional knowledge integration)
- Wait for response completion: Monitor the assistant response until fully generated
- Fetch and process the final chat: Retrieve and parse the completed conversation
This enables server-side orchestration while still making replies show up in the frontend UI exactly as if they were generated through normal user interaction.
Important Concepts
Message IDs Are Caller-Generated
All message IDs (user-msg-id, assistant-msg-id) must be generated by the caller as valid UUIDs before making API calls. Open WebUI does not assign message IDs for you. Use any UUID v4 generator to create them.
Example (bash):
USER_MSG_ID=$(uuidgen || python3 -c "import uuid; print(uuid.uuid4())")
ASSISTANT_MSG_ID=$(uuidgen || python3 -c "import uuid; print(uuid.uuid4())")