Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions google/genai/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import google.auth
import google.auth.credentials
from google.auth.credentials import Credentials
from google.auth.exceptions import DefaultCredentialsError
from google.auth.transport.requests import Request
import httpx
from pydantic import BaseModel
Expand Down Expand Up @@ -183,9 +184,15 @@ def _join_url_path(base_url: str, path: str) -> str:

def _load_auth(*, project: Union[str, None]) -> Tuple[Credentials, str]:
"""Loads google auth credentials and project id."""
credentials, loaded_project_id = google.auth.default( # type: ignore[no-untyped-call]
scopes=['https://www.googleapis.com/auth/cloud-platform'],
)
try:
credentials, loaded_project_id = google.auth.default( # type: ignore[no-untyped-call]
scopes=['https://www.googleapis.com/auth/cloud-platform'],
)
except DefaultCredentialsError:
time.sleep(0.5)
credentials, loaded_project_id = google.auth.default( # type: ignore[no-untyped-call]
scopes=['https://www.googleapis.com/auth/cloud-platform'],
)

if not project:
project = loaded_project_id
Expand Down