Skip to content

Commit f4530b0

Browse files
yinghsienwucopybara-github
authored andcommitted
feat: Support global endpoint natively in Vertex
PiperOrigin-RevId: 720746911
1 parent ed7f356 commit f4530b0

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

google/genai/_api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def __init__(
255255
'Project and location or API key must be set when using the Vertex '
256256
'AI API.'
257257
)
258-
if self.api_key:
258+
if self.api_key or self.location == 'global':
259259
self._http_options['base_url'] = (
260260
f'https://aiplatform.googleapis.com/'
261261
)

google/genai/tests/client/test_client_initialization.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,3 +593,21 @@ def test_vertexai_apikey_combo3(monkeypatch):
593593
assert client.models._api_client.location == location
594594
assert "aiplatform" in client._api_client._http_options["base_url"]
595595
assert isinstance(client.models._api_client, api_client.ApiClient)
596+
597+
598+
def test_vertexai_global_endpoint(monkeypatch):
599+
# Vertex AI uses global endpoint when location is global.
600+
project_id = "fake_project_id"
601+
location = "global"
602+
monkeypatch.setenv("GOOGLE_CLOUD_PROJECT", project_id)
603+
monkeypatch.setenv("GOOGLE_CLOUD_LOCATION", location)
604+
605+
client = Client(vertexai=True, location=location)
606+
607+
assert client.models._api_client.vertexai
608+
assert client.models._api_client.project == project_id
609+
assert client.models._api_client.location == location
610+
assert client.models._api_client._http_options["base_url"] == (
611+
"https://aiplatform.googleapis.com/"
612+
)
613+
assert isinstance(client.models._api_client, api_client.ApiClient)

0 commit comments

Comments
 (0)