mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #24164] feat: interpolate template variables in custom connection headers #66386
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/24164
Author: @alejandroiglesias
Created: 4/27/2026
Status: 🔄 Open
Base:
dev← Head:feat/dynamic-header-template-vars📝 Commits (10+)
fe6783cMerge pull request #19030 from open-webui/devfc05e0aMerge pull request #19405 from open-webui/deve3faec6Merge pull request #19416 from open-webui/dev9899293Merge pull request #19448 from open-webui/dev140605eMerge pull request #19462 from open-webui/dev6f1486fMerge pull request #19466 from open-webui/devd95f533Merge pull request #19729 from open-webui/deva7271530.6.43 (#20093)6adde20Merge pull request #20394 from open-webui/devf9b0534Merge pull request #20522 from open-webui/dev📊 Changes
2 files changed (+15 additions, -2 deletions)
View changed files
📝
backend/open_webui/routers/openai.py(+14 -1)📝
src/lib/components/AddConnectionModal.svelte(+1 -1)📄 Description
Before submitting, make sure you've checked the following:
devbranch. PRs targetingmainwill be immediately closed.{{chat_id}}is interpolated correctly in outgoing request headers, static headers are unaffected, unknown tokens are left as-is, and non-string values are coerced to strings without error.dev.feat:prefix.Changelog Entry
Description
Admins can now use
{{chat_id}},{{message_id}},{{user_id}}, and{{user_name}}as dynamic placeholders in custom header values for OpenAI-compatible connections. This allows per-request context (like the current chat UUID) to be forwarded to upstream providers that use session-scoped headers for routing.Added
{{chat_id}},{{message_id}},{{user_id}},{{user_name}}Changed
strbefore being sent (aiohttp requires string header values)Fixed
Additional Information
The interpolation is done in
get_headers_and_cookies()inbackend/open_webui/routers/openai.py, just before custom headers are merged into the outgoing request. Themetadataanduserobjects are already available at that point — no signature changes were needed.str.replace— no template engine, no logic, no new dependencies{{...}}tokens pass through unchanged — fully backwards compatible{{foo}}) are left as-is, no error is raisedMotivation: Providers like Manifest use a session-scoped header (e.g.
x-session-key) to scope routing state to a conversation. Without dynamic header values, each message in an Open WebUI conversation is treated as a new session on the provider side, losing any routing momentum built up across turns. With this change, an admin can configure{"x-session-key": "{{chat_id}}"}and every request will automatically carry the real chat UUID.Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.