Implementing rate limiting with dynamic quotas based on user subscription level in FastAPI with Redis
I'm building an API that needs to handle different rate limits based on user subscription levels (free, premium, enterprise). I'm using FastAPI with Redis for rate limiting, but struggling with implementing dynamic quotas. Current implementation: from fastapi import FastAPI, Depends, HTTPException import redis from typing import Optional app = FastAPI() redis_client = redis.Redis(host='localhost', port=6379, db=0) async def get_rate_limit(user_id: str) -> int: # Currently hardcoded, need dynamic solution return 100 # requests per hour @app.get("/api/data") async def get_data(user_id: str = Dep
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.