feat: add rate limiting, CORS, queue loop in lifespan

This commit is contained in:
2026-05-25 18:51:58 +02:00
parent 1feb012682
commit 1b1a0eb6ff
4 changed files with 69 additions and 7 deletions
+5 -3
View File
@@ -1,7 +1,8 @@
from fastapi import APIRouter, Depends, Query
from fastapi import APIRouter, Depends, Query, Request as FastAPIRequest
from starlette.responses import JSONResponse
from src.backend.api.dependencies import verify_api_key
from src.backend.api.dependencies import verify_api_key, limiter
from src.backend.config import settings
from src.backend.db.database import (
get_db,
create_request,
@@ -27,7 +28,8 @@ async def _get_db():
@router.post("", summary="Create request")
async def create(body: RequestCreate, db=Depends(_get_db)):
@limiter.limit(lambda: f"{settings.rate_limit_per_minute}/minute;{settings.rate_limit_per_hour}/hour")
async def create(request: FastAPIRequest, body: RequestCreate, db=Depends(_get_db)):
req = await create_request(
db,
prompt=body.prompt,