chengzhang1006's picture
add more informations (#15)
01fba1c verified
raw
history blame contribute delete
693 Bytes
"""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}"}