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