def load_auth()

in src/anthropic/lib/vertex/_auth.py [0:0]


def load_auth(*, project_id: str | None) -> tuple[Credentials, str]:
    try:
        from google.auth.transport.requests import Request  # type: ignore[import-untyped]
    except ModuleNotFoundError as err:
        raise RuntimeError(f'Could not import google.auth, you need to install the SDK with `pip install anthropic[vertex]`') from err

    credentials, loaded_project_id = google_auth.default(
        scopes=["https://www.googleapis.com/auth/cloud-platform"],
    )
    credentials = cast(Any, credentials)
    credentials.refresh(Request())

    if not project_id:
        project_id = loaded_project_id

    if not project_id:
        raise ValueError("Could not resolve project_id")

    if not isinstance(project_id, str):
        raise TypeError(f"Expected project_id to be a str but got {type(project_id)}")

    return credentials, project_id