File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -599,7 +599,7 @@ def __init__(
599599 # Handle when to use Vertex AI in express mode (api key).
600600 # Explicit initializer arguments are already validated above.
601601 if self .vertexai :
602- if credentials :
602+ if credentials and env_api_key :
603603 # Explicit credentials take precedence over implicit api_key.
604604 logger .info (
605605 'The user provided Google Cloud credentials will take precedence'
Original file line number Diff line number Diff line change @@ -417,6 +417,25 @@ def test_invalid_vertexai_constructor3(monkeypatch):
417417 Client (vertexai = True , project = project_id )
418418
419419
420+ def test_vertexai_explicit_credentials (monkeypatch ):
421+ creds = credentials .AnonymousCredentials ()
422+ monkeypatch .setenv ("GOOGLE_CLOUD_PROJECT" , "fake_project_id" )
423+ monkeypatch .setenv ("GOOGLE_CLOUD_LOCATION" , "fake-location" )
424+ monkeypatch .setenv ("GOOGLE_API_KEY" , "env_api_key" )
425+
426+ client = Client (
427+ vertexai = True ,
428+ credentials = creds
429+ )
430+
431+ assert client .models ._api_client .vertexai
432+ assert client .models ._api_client .project
433+ assert client .models ._api_client .location
434+ assert not client .models ._api_client .api_key
435+ assert client .models ._api_client ._credentials is creds
436+ assert isinstance (client .models ._api_client , api_client .BaseApiClient )
437+
438+
420439def test_vertexai_explicit_arg_precedence1 (monkeypatch ):
421440 project_id = "constructor_project_id"
422441 location = "constructor-location"
You can’t perform that action at this time.
0 commit comments