diff --git a/app/core/config.py b/app/core/config.py index 6bd3384..4df2b13 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -6,7 +6,7 @@ load_dotenv() class Settings: PROJECT_NAME: str = "Storyline AI Gateway" API_KEY: str = os.getenv("API_KEY", "storyline-secret-key-123") - RATE_LIMIT: str = "20/minute" + RATE_LIMIT: str = "10/minute" GOOGLE_API_KEY: str = os.getenv("GOOGLE_API_KEY") OPENAI_API_KEY: str = os.getenv("OPENAI_API_KEY") DATABASE_URL: str = os.getenv("DATABASE_URL") diff --git a/app/main.py b/app/main.py index 34e8729..895de96 100644 --- a/app/main.py +++ b/app/main.py @@ -42,7 +42,18 @@ def create_application() -> FastAPI: # Set up Rate Limiter application.state.limiter = limiter - application.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler) + + @application.exception_handler(RateLimitExceeded) + async def custom_rate_limit_exceeded_handler(request, exc): + from fastapi.responses import JSONResponse + return JSONResponse( + status_code=429, + content={ + "error": "Too Many Requests", + "message": "Chill out! You've reached the rate limit. Please wait a moment before trying again.", + "limit": str(exc.detail) + } + ) # Include routes application.include_router(api_router, prefix="/api/v1")