File size: 693 Bytes
44459bb 01fba1c 44459bb 01fba1c 44459bb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
"""Headers for HTTP requests."""
from folding_studio.config import FOLDING_API_KEY
from folding_studio.utils.gcp import get_id_token
def get_auth_headers(api_key: str | None = None) -> dict[str, str]:
"""
Create authentication headers based on available credentials.
API key is the default authentication.
If none is provided, we fallback to JWT from Google Cloud.
Returns:
dict: Authentication headers for API requests.
"""
if api_key is not None:
return {"X-API-Key": api_key}
if FOLDING_API_KEY:
return {"X-API-Key": FOLDING_API_KEY}
identity_token = get_id_token()
return {"Authorization": f"Bearer {identity_token}"}
|