feat(api): add per-user rate limiter on scan endpoints#83
Merged
Conversation
|
@Tirthpanchori is attempting to deploy a commit to the karan3431's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
🎉 Thank you for your Pull Request! We're thrilled to have your contribution to FreshScan AI. Before we review, please make sure you have:
A maintainer will review your code as soon as possible! |
Owner
|
backend test is failing fix that. |
fe08ec5 to
cf6a848
Compare
Contributor
Author
Fixed - added slowapi to requirements-base.txt and requirements-ci.txt so it's available in the CI environment. Latest commit 7a41d6e should resolve the ModuleNotFoundError. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Author
Happy to contribute! Looking forward to more. |
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.
Description
Implements per-user rate limiting on the FreshScan AI backend to prevent abuse of the Hugging Face Space inference endpoint and Supabase resources.
What this PR does:
slowapi==0.1.9middleware for request rate limitingbackend/rate_limiter.pywith aget_user_idkey function that keys limits by authenticated Supabase user ID, falling back to client IP for unauthenticated requests/api/v1/scanand/api/v1/scan-auto(the heavy ML inference endpoints)429 Too Many Requestsresponses withretry_afterfield/api/v1/healthendpoint for lightweight status checksbackend/tests/test_rate_limiter.pycovering 429 behavior and response shapeCloses #4
Checklist
npm run lintpasses with no errorsnpm run buildcompiles without TypeScript errorspython -m pytestpasses (including new tests I added).envfiles, API keys, secrets, model weights, or__pycache__in this diffmain, not merged