Skip to content

Commit 1a3e69b

Browse files
sararobcopybara-github
authored andcommitted
fix: Support multi-regional locations in vertexai.Client
PiperOrigin-RevId: 912661628
1 parent 1f9c8e0 commit 1a3e69b

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

tests/unit/vertexai/genai/test_genai_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ def test_genai_client(self):
5252
assert test_client._api_client.project == _TEST_PROJECT
5353
assert test_client._api_client.location == _TEST_LOCATION
5454

55+
@pytest.mark.parametrize("location", ["us", "eu"])
56+
@pytest.mark.usefixtures("google_auth_mock")
57+
def test_genai_client_mrep(self, location):
58+
test_client = vertexai.Client(project=_TEST_PROJECT, location=location)
59+
expected_url = f"https://aiplatform.{location}.rep.googleapis.com/"
60+
assert test_client._api_client._http_options.base_url == expected_url
61+
5562
@pytest.mark.asyncio
5663
@pytest.mark.usefixtures("google_auth_mock")
5764
async def test_async_client(self):

vertexai/_genai/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ def __init__(
219219
if http_options.headers is None:
220220
http_options.headers = {}
221221

222+
# Set the base URL for MREP locations.
223+
if location in ["us", "eu"] and not http_options.base_url:
224+
http_options.base_url = (
225+
f"https://aiplatform.{location}.rep.googleapis.com/"
226+
)
227+
222228
tracking_label = f"{_GENAI_MODULES_TELEMETRY_HEADER}/{aip_version.__version__}"
223229

224230
if "user-agent" in http_options.headers:

0 commit comments

Comments
 (0)