mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #23600] [CLOSED] feat: per-group token usage limits with enforcement #42902
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/23600
Author: @smorello87
Created: 4/11/2026
Status: ❌ Closed
Base:
dev← Head:feat/usage-limits📝 Commits (1)
3e4197bfeat: per-group token usage limits with enforcement📊 Changes
13 files changed (+760 additions, -12 deletions)
View changed files
📝
backend/open_webui/main.py(+2 -0)➕
backend/open_webui/migrations/versions/c3d4e5f6a7b8_add_usage_ledger_table.py(+102 -0)📝
backend/open_webui/models/chat_messages.py(+1 -1)📝
backend/open_webui/models/chats.py(+22 -8)📝
backend/open_webui/models/groups.py(+20 -0)➕
backend/open_webui/models/usage_ledger.py(+144 -0)➕
backend/open_webui/routers/usage_limits.py(+151 -0)📝
backend/open_webui/utils/chat.py(+17 -1)📝
backend/open_webui/utils/middleware.py(+60 -0)➕
backend/open_webui/utils/usage_limits.py(+153 -0)📝
src/lib/components/admin/Users/Groups/EditGroupModal.svelte(+2 -1)📝
src/lib/components/admin/Users/Groups/Permissions.svelte(+81 -0)📝
src/lib/components/chat/Chat.svelte(+5 -1)📄 Description
devfeat:Changelog Entry
Added
Description
Adds per-group token usage limits that enforce daily or monthly caps on non-admin users. Full design discussion in #23558.
How it works:
generate_chat_completionquerieschat_messagefor the user's token usage in the current period. If over the group's limit, returns 429. Background tasks (title/tag/follow-up generation) are skipped viametadata.taskcheck.chat_messagehas a FK tochat(which doesn't exist for these), usage is written to a smallusage_ledgertable. Enforcement sums both tables.permissionsJSON field. Admin UI added to the Permissions tab in group settings.Testing
Tested on an ECS Fargate deployment (CUNY AI Lab, PostgreSQL 16.3) with:
pg_constraintquery)POST /api/chat/completionswith JWT, nochat_id,stream: false) — both enforced and trackedTesting
Tested on an ECS Fargate deployment (CUNY AI Lab, PostgreSQL 16.3) with:
pg_constraintquery)POST /api/chat/completionswith JWT, nochat_id,stream: false) — both enforced and trackedTesting
Tested on an ECS Fargate deployment (CUNY AI Lab, PostgreSQL 16.3) with:
pg_constraintquery)POST /api/chat/completionswith JWT, nochat_id,stream: false) — both enforced and trackedTesting
Tested on an ECS Fargate deployment (CUNY AI Lab, PostgreSQL 16.3) with:
pg_constraintquery)POST /api/chat/completionswith JWT, nochat_id,stream: false) — both enforced and trackedTesting
Tested on an ECS Fargate deployment (CUNY AI Lab, PostgreSQL 16.3) with:
pg_constraintquery)POST /api/chat/completionswith JWT, nochat_id,stream: false) — both enforced and trackedTesting
Tested on an ECS Fargate deployment (CUNY AI Lab, PostgreSQL 16.3) with:
pg_constraintquery)POST /api/chat/completionswith JWT, nochat_id,stream: false) — both enforced and trackedTesting
Tested on an ECS Fargate deployment (CUNY AI Lab, PostgreSQL 16.3) with:
pg_constraintquery)POST /api/chat/completionswith JWT, nochat_id,stream: false) — both enforced and trackedTesting
Tested on an ECS Fargate deployment (CUNY AI Lab, PostgreSQL 16.3) with:
pg_constraintquery)POST /api/chat/completionswith JWT, nochat_id,stream: false) — both enforced and trackedTesting
Tested on an ECS Fargate deployment (CUNY AI Lab, PostgreSQL 16.3) with:
pg_constraintquery)POST /api/chat/completionswith JWT, nochat_id,stream: false) — both enforced and trackedTesting
Tested on an ECS Fargate deployment (CUNY AI Lab, PostgreSQL 16.3) with:
pg_constraintquery)POST /api/chat/completionswith JWT, nochat_id,stream: false) — both enforced and trackedTesting
Tested on an ECS Fargate deployment (CUNY AI Lab, PostgreSQL 16.3) with:
pg_constraintquery)POST /api/chat/completionswith JWT, nochat_id,stream: false) — both enforced and trackedBreaking Changes
delete_chat_by_id,delete_chat_by_id_and_user_id,delete_chats_by_user_id, anddelete_chats_by_user_id_and_folder_id.Additional Information
usage_ledgertable (revisionc3d4e5f6a7b8, depends onb7c8d9e0f1a2)Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.