Custom credentials for Vertex AI authentication.
When provided, forces Vertex AI backend (regardless of API key presence in
google_api_key/api_key).
Accepts a google.auth.credentials.Credentials
object.
If omitted and no API key is found, the SDK uses Application Default Credentials (ADC).
from google.oauth2 import service_account
credentials = service_account.Credentials.from_service_account_file(
"path/to/service-account.json",
scopes=["https://www.googleapis.com/auth/cloud-platform"],
)
llm = ChatGoogleGenerativeAI(
model="gemini-2.5-flash",
credentials=credentials,
project="my-project-id",
)