Skip to content

Commit 9858051

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: Add "eu" as a supported service location for Vertex AI platform.
PiperOrigin-RevId: 896680569
1 parent 6ca8209 commit 9858051

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

google/genai/_api_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191
INITIAL_RETRY_DELAY = 1 # second
9292
DELAY_MULTIPLIER = 2
9393

94+
_MULTI_REGIONAL_LOCATIONS = {'us', 'eu'}
95+
9496

9597
class EphemeralTokenAPIKeyError(ValueError):
9698
"""Error raised when the API key is invalid."""
@@ -702,7 +704,10 @@ def __init__(
702704
self.api_key or self.location == 'global'
703705
) and not self.custom_base_url:
704706
self._http_options.base_url = f'https://aiplatform.googleapis.com/'
705-
elif self.location == 'us' and not self.custom_base_url:
707+
elif (
708+
self.location in _MULTI_REGIONAL_LOCATIONS
709+
and not self.custom_base_url
710+
):
706711
self._http_options.base_url = (
707712
f'https://aiplatform.{self.location}.rep.googleapis.com/'
708713
)

google/genai/tests/client/test_client_initialization.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,22 @@ def test_vertexai_location_us_routing(monkeypatch):
532532
)
533533

534534

535+
def test_vertexai_location_eu_routing(monkeypatch):
536+
# Verify that location='eu' correctly routes to the eu.rep endpoint
537+
project_id = "fake_project_id"
538+
location = "eu"
539+
540+
with monkeypatch.context() as m:
541+
m.delenv("GOOGLE_CLOUD_LOCATION", raising=False)
542+
client = Client(vertexai=True, project=project_id, location=location)
543+
assert client.models._api_client.location == location
544+
assert client.models._api_client.project == project_id
545+
assert (
546+
client.models._api_client.get_read_only_http_options()["base_url"]
547+
== "https://aiplatform.eu.rep.googleapis.com/"
548+
)
549+
550+
535551
def test_vertexai_location_us_routing_base_url_override(monkeypatch):
536552
# Verify that base_url override takes precedence over location='us' routing
537553
project_id = "fake_project_id"

0 commit comments

Comments
 (0)