Cap max_tokens and n to prevent local API DoS#3637
Open
arditbe wants to merge 2 commits intonomic-ai:mainfrom
Open
Cap max_tokens and n to prevent local API DoS#3637arditbe wants to merge 2 commits intonomic-ai:mainfrom
arditbe wants to merge 2 commits intonomic-ai:mainfrom
Conversation
This PR adds server-side upper bounds for max_tokens and n in BaseCompletionRequest::parseImpl. Requests exceeding limits now return 400 via InvalidRequestError, preventing memory/CPU exhaustion on /v1/completions and /v1/chat/completions. Fixes nomic-ai#3635. Signed-off-by: ardit <88629825+arditbe@users.noreply.github.com>
Signed-off-by: ardit <88629825+arditbe@users.noreply.github.com>
Author
|
Hi! This PR adds server-side caps for max_tokens and n in BaseCompletionRequest to prevent local API DoS on /v1/completions and /v1/chat/completions. Fixes #3635. Happy to adjust limits or add tests if you prefer. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
My Changes
Added server-side upper bounds for
max_tokensandninBaseCompletionRequest::parseImpl.Requests exceeding these limits now return 400 via
InvalidRequestError, preventing memory and CPU exhaustion in/v1/completionsand/v1/chat/completions.Issue ticket number and link
Fixes #3635
Checklist before requesting a review
Demo
N/A (validation change)
Steps to Reproduce
max_tokensorn.Notes
Limits used:
max_tokens <= 4096,n <= 8. Happy to adjust per maintainer preference.