Spaces:
Sleeping
Sleeping
| from fastapi.security.api_key import APIKeyHeader | |
| from fastapi import Security, HTTPException | |
| import os | |
| # from dotenv import load_dotenv | |
| api_key_header = APIKeyHeader(name="x-api-key", auto_error=False) | |
| async def api_key_auth(api_key: str = Security(api_key_header)): | |
| # for local | |
| # load_dotenv() | |
| API_Keys = [os.environ.get('API_KEY')] | |
| if api_key not in API_Keys: | |
| raise HTTPException(status_code=401, detail="Missing or invalid API key") |