| from fastapi import Depends, HTTPException, status | |
| from fastapi.security import APIKeyHeader | |
| API_KEY = "your_api_key_here" # Replace with a secure key or load from env | |
| api_key_header = APIKeyHeader(name="X-API-Key") | |
| def get_api_key(api_key: str = Depends(api_key_header)): | |
| if api_key != API_KEY: | |
| raise HTTPException( | |
| status_code=status.HTTP_401_UNAUTHORIZED, | |
| detail="Invalid or missing API Key", | |
| ) | |
| return api_key | |