mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #21381] [CLOSED] feat: LLM proxy user sync and budget enforcement #26058
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/21381
Author: @jpaodev
Created: 2/13/2026
Status: ❌ Closed
Base:
dev← Head:feat-sync-users📝 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
4 files changed (+401 additions, -0 deletions)
View changed files
📝
backend/open_webui/env.py(+63 -0)➕
backend/open_webui/utils/llm_proxy_budget.py(+214 -0)➕
backend/open_webui/utils/llm_proxy_sync.py(+113 -0)📝
backend/open_webui/utils/middleware.py(+11 -0)📄 Description
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions to discuss your idea/fix with the community before creating a pull request, and describe your changes before submitting a pull request.
This is to ensure large feature PRs are discussed with the community first, before working on it and submitting the PR. If the community does not want this feature or it is not relevant for Open WebUI as a project, it can be identified in the discussion before working on the feature and submitting the PR.
Before submitting, make sure you've checked the following:
devbranch. PRs targetingmainwill be immediately closed.requestswhich is standard)devto ensure no unrelated commits (e.g. frommain) are included. Push updates to the existing PR branch instead of closing and reopening.feat: Add LLM Proxy User Sync and Budget Enforcement
Description
This pull request introduces comprehensive integration with external LLM proxies (e.g., LiteLLM) to enhance user management and introduce usage budget enforcement. It allows Open WebUI to automatically synchronize user data to the proxy and block chat requests for users who have exceeded their configured budget. This feature is configurable via new environment variables, providing fine-grained control over user syncing and budget enforcement policies.
The core functionality involves:
Both features are opt-in and controlled by environment variables. They are designed to be resilient, with user sync being non-blocking on failure, and budget enforcement failing open (not blocking a user) if the proxy cannot be reached or returns an invalid response.
Why not just use a function / filter / pipe?
I deliberately wanted to not use that, but rather integrate that, as users might want to disable functions/filters and similar in high-security deployments. In addition this doesn't introduce any dependencies, hence I think this is reasonable to integrate and useful to users, especially considering this bug: https://github.com/BerriAI/litellm/issues/11083
Changelog Entry
Description
Added
LLM_PROXY_SYNC_USERS(enable/disable),LLM_PROXY_API_BASE_URL,LLM_PROXY_API_KEY,LLM_PROXY_SYNC_USER_ALIAS(control syncing user alias/name),LLM_PROXY_SYNC_TIMEOUT,LLM_PROXY_SYNC_ENDPOINT, and custom keys for user payload fields (LLM_PROXY_SYNC_KEY_USER_ID,LLM_PROXY_SYNC_KEY_USER_EMAIL,LLM_PROXY_SYNC_KEY_USER_ALIAS).backend/open_webui/utils/llm_proxy_sync.py) handling user data synchronization to the proxy via HTTP POST.process_chat_payloadmiddleware (backend/open_webui/utils/middleware.py) to automatically sync user information on chat requests. This process is fully isolated and non-blocking, logging any failures without affecting the chat flow.LLM_PROXY_BUDGET_ENFORCE(enable/disable),LLM_PROXY_BUDGET_ENDPOINT,LLM_PROXY_BUDGET_HTTP_METHOD(GET/POST),LLM_PROXY_BUDGET_TIMEOUT,LLM_PROXY_BUDGET_CACHE_TTL(cache duration for budget checks),LLM_PROXY_BUDGET_JSON_PATH_SPEND,LLM_PROXY_BUDGET_JSON_PATH_MAX_BUDGET,LLM_PROXY_BUDGET_JSON_PATH_BUDGET_RESET_AT(JSON paths for parsing proxy response),LLM_PROXY_BUDGET_QUERY_PARAM,LLM_PROXY_BUDGET_AUTH_HEADER,LLM_PROXY_BUDGET_EXCEEDED_MSG(custom message for exceeding budget), andLLM_PROXY_BUDGET_BLOCK_ADMINS(option to include/exclude admin users).backend/open_webui/utils/llm_proxy_budget.py) to fetch user budget information from the proxy, resolve JSON paths in the response, and determine if the budget is exceeded._budget_cache) for budget checks to reduce the load on the LLM proxy and improve response times.process_chat_payloadmiddleware to check user budgets and block requests with an appropriate message if the budget is exceeded. This check is performed before the chat request is processed.Changed
Deprecated
Removed
Fixed
Security
Breaking Changes
Additional Information
budget_reset_attimestamps to intelligently handle scenarios where a budget might have reset but thespendvalue from the proxy hasn't updated yet.asyncio.to_threadto ensure the main event loop is not stalled.Screenshots or Videos
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.