Skip to content

Commit a00b67a

Browse files
sasha-gitgcopybara-github
authored andcommitted
fix: Do not use ADC if passing a base_url, no project, no location
PiperOrigin-RevId: 832020600
1 parent 9a9fa3c commit a00b67a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

google/genai/_api_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,15 +628,15 @@ def __init__(
628628
)
629629
self.api_key = None
630630

631-
if not self.location and not self.api_key:
632-
self.location = 'global'
633-
634631
self.custom_base_url = (
635632
validated_http_options.base_url
636633
if validated_http_options.base_url
637634
else None
638635
)
639636

637+
if not self.location and not self.api_key and not self.custom_base_url:
638+
self.location = 'global'
639+
640640
# Skip fetching project from ADC if base url is provided in http options.
641641
if (
642642
not self.project

google/genai/tests/client/test_client_initialization.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ def mock_auth_default(scopes=None):
372372
monkeypatch.setattr(google.auth, "default", mock_auth_default)
373373
# Including a base_url override skips the check for having proj/location or
374374
# api_key set.
375-
Client(vertexai=True, http_options={"base_url": "https://override.com/"})
375+
client = Client(vertexai=True, http_options={"base_url": "https://override.com/"})
376+
assert client.models._api_client.location is None
376377

377378

378379
def test_invalid_mldev_constructor_empty(monkeypatch):

0 commit comments

Comments
 (0)