-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
feat(rate_limit): support per-tag rpm limiting on a single key #31502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yassin-berriai
merged 3 commits into
litellm_internal_staging
from
litellm_lit-3147-per-tag-rate-limit
Jul 8, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
8e2ed6c
feat(rate_limit): support per-tag rpm limiting on a single key
yassin-berriai 5743971
Merge remote-tracking branch 'origin/litellm_internal_staging' into l…
yassin-berriai 730c674
Merge remote-tracking branch 'origin/litellm_internal_staging' into l…
yassin-berriai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Medium: Caller-controlled tags bypass tag limits
The tag descriptor is only added for tags supplied in the request body. A client using a key with
tag_rpm_limit={"cell-1": 2}can omitmetadata.tagsor send an unconfigured tag and avoid the per-tag counter entirely, falling back to the broader key limit. If tag limits are intended as an enforcement boundary, derive the tag from trusted key/team configuration or fail closed when a key has tag limits but the request has no authorized matching tag.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per-tag limits are designed as opt-in sub-limits layered under the key-level rpm/tpm ceiling, not as a standalone enforcement boundary. A tag with no configured limit, or a request that carries no tag at all, is still governed by the key-level
rpm_limit/tpm_limit, which stays the hard ceiling for the key. Dropping or changing the tag cannot lift a caller above the key's overall budget; it only forfeits the finer per-tag bucket and falls back to the broader key limit. That fallback is the behavior the feature is built around (the proof-of-fix shows an untagged request returning 200 under the key limit), and a fail-closed-on-missing-tag rule would reject legitimate untagged traffic the key is entitled to sendIf a deployment wants tags to act as a hard boundary, it sets a key-level
rpm_limit/tpm_limitas the ceiling and the per-tag limits subdivide it. I added a regression test,test_per_tag_untagged_request_governed_by_key_limit_v3, that pins this: an untagged or unconfigured-tag request is bounded by the key-level limit and is never rejected by a tag counter, so a future fail-closed change fails the test instead of silently breaking the documented behaviorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed by design, and unchanged now that this PR is narrowed to per-tag RPM only. Per-tag limits are opt-in sub-limits beneath the key-level
rpm_limitceiling, not a standalone enforcement boundary. Omitting or changing a tag only forfeits the finer per-tag bucket and falls back to the key-level limit, which stays the hard ceiling and cannot be exceeded; it cannot lift a caller above the key overall budget. Failing closed on a missing tag would reject legitimate untagged traffic the key is entitled to send (the live proof shows an untagged request returning 200 under the key limit).test_per_tag_untagged_request_governed_by_key_limit_v3pins this so a future fail-closed change fails the test instead of silently changing the documented behavior