File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments