Debian Codegraph @

src/anthropic/lib/vertex/_auth.py

raw
1 from __future__ import annotations
2
3 from typing import TYPE_CHECKING
4
5 from .._extras._google_auth import refresh_credentials as refresh_auth, load_default_credentials
6
7 if TYPE_CHECKING:
8 from google.auth.credentials import Credentials # type: ignore[import-untyped]
9
10 # Note: these functions are blocking as they make HTTP requests, the async
11 # client runs these functions in a separate thread to ensure they do not
12 # cause synchronous blocking issues.
13
14 __all__ = ["load_auth", "refresh_auth"]
15
16
17 def load_auth(*, project_id: str | None) -> tuple[Credentials, str]:
18 credentials, loaded_project_id = load_default_credentials(extra="vertex")
19
20 if not project_id:
21 project_id = loaded_project_id
22
23 if not project_id:
24 raise ValueError("Could not resolve project_id")
25
26 return credentials, project_id