Update app/dependencies.py
Browse files- app/dependencies.py +13 -3
app/dependencies.py
CHANGED
@@ -1,7 +1,17 @@
|
|
1 |
-
|
2 |
|
3 |
-
|
|
|
4 |
|
5 |
def require_api_key(x_api_key: str = Header(...)):
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
raise HTTPException(status_code=403, detail="Invalid API Key")
|
|
|
|
1 |
+
# app/dependencies.py
|
2 |
|
3 |
+
import os
|
4 |
+
from fastapi import Header, HTTPException, Depends
|
5 |
|
6 |
def require_api_key(x_api_key: str = Header(...)):
|
7 |
+
"""
|
8 |
+
Simple header-based API key check.
|
9 |
+
The key is read from the environment variable API_KEY, which you set in
|
10 |
+
Settings → Secrets on your Hugging Face Space.
|
11 |
+
"""
|
12 |
+
expected_key = os.getenv("API_KEY")
|
13 |
+
if not expected_key:
|
14 |
+
raise HTTPException(status_code=500, detail="API_KEY not configured")
|
15 |
+
if x_api_key != expected_key:
|
16 |
raise HTTPException(status_code=403, detail="Invalid API Key")
|
17 |
+
return True
|