Update main.py
Browse files
main.py
CHANGED
@@ -38,11 +38,11 @@ rate_limit_store = defaultdict(lambda: {"count": 0, "timestamp": time.time()})
|
|
38 |
async def get_api_key(authorization: str = Header(...)) -> str:
|
39 |
if not authorization.startswith('Bearer '):
|
40 |
logger.warning("Invalid authorization header format.")
|
41 |
-
raise HTTPException(status_code=401, detail='Invalid authorization header format')
|
42 |
api_key = authorization[7:]
|
43 |
if api_key not in API_KEYS:
|
44 |
logger.warning(f"Invalid API key attempted: {api_key}")
|
45 |
-
raise HTTPException(status_code=401, detail='Invalid API key')
|
46 |
return api_key
|
47 |
|
48 |
async def rate_limiter(api_key: str = Depends(get_api_key)):
|
@@ -53,7 +53,7 @@ async def rate_limiter(api_key: str = Depends(get_api_key)):
|
|
53 |
else:
|
54 |
if rate_limit_store[api_key]["count"] >= RATE_LIMIT:
|
55 |
logger.warning(f"Rate limit exceeded for API key: {api_key}")
|
56 |
-
raise HTTPException(status_code=429, detail='Rate limit exceeded')
|
57 |
rate_limit_store[api_key]["count"] += 1
|
58 |
|
59 |
# Custom exception for model not working
|
|
|
38 |
async def get_api_key(authorization: str = Header(...)) -> str:
|
39 |
if not authorization.startswith('Bearer '):
|
40 |
logger.warning("Invalid authorization header format.")
|
41 |
+
raise HTTPException(status_code=401, detail='Invalid authorization header format | NiansuhAI')
|
42 |
api_key = authorization[7:]
|
43 |
if api_key not in API_KEYS:
|
44 |
logger.warning(f"Invalid API key attempted: {api_key}")
|
45 |
+
raise HTTPException(status_code=401, detail='Invalid API key | NiansuhAI')
|
46 |
return api_key
|
47 |
|
48 |
async def rate_limiter(api_key: str = Depends(get_api_key)):
|
|
|
53 |
else:
|
54 |
if rate_limit_store[api_key]["count"] >= RATE_LIMIT:
|
55 |
logger.warning(f"Rate limit exceeded for API key: {api_key}")
|
56 |
+
raise HTTPException(status_code=429, detail='Rate limit exceeded | NiansuhAI')
|
57 |
rate_limit_store[api_key]["count"] += 1
|
58 |
|
59 |
# Custom exception for model not working
|