mgbam commited on
Commit
9520ed7
·
verified ·
1 Parent(s): 666d79b

Update app/dependencies.py

Browse files
Files changed (1) hide show
  1. app/dependencies.py +13 -3
app/dependencies.py CHANGED
@@ -1,7 +1,17 @@
1
- from fastapi import Header, HTTPException
2
 
3
- API_KEY = "your-admin-key" # OR read from env/secrets
 
4
 
5
  def require_api_key(x_api_key: str = Header(...)):
6
- if x_api_key != API_KEY:
 
 
 
 
 
 
 
 
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