@@ -516,6 +516,43 @@ def test_vertexai_no_default_location_when_location_explicitly_set(monkeypatch):
516516 assert client .models ._api_client .project == project_id
517517
518518
519+ def test_vertexai_location_us_routing (monkeypatch ):
520+ # Verify that location='us' correctly routes to the us.rep endpoint
521+ project_id = "fake_project_id"
522+ location = "us"
523+
524+ with monkeypatch .context () as m :
525+ m .delenv ("GOOGLE_CLOUD_LOCATION" , raising = False )
526+ client = Client (vertexai = True , project = project_id , location = location )
527+ assert client .models ._api_client .location == location
528+ assert client .models ._api_client .project == project_id
529+ assert (
530+ client .models ._api_client .get_read_only_http_options ()["base_url" ]
531+ == "https://aiplatform.us.rep.googleapis.com/"
532+ )
533+
534+
535+ def test_vertexai_location_us_routing_base_url_override (monkeypatch ):
536+ # Verify that base_url override takes precedence over location='us' routing
537+ project_id = "fake_project_id"
538+ location = "us"
539+
540+ with monkeypatch .context () as m :
541+ m .delenv ("GOOGLE_CLOUD_LOCATION" , raising = False )
542+ client = Client (
543+ vertexai = True ,
544+ project = project_id ,
545+ location = location ,
546+ http_options = {"base_url" : "https://my-custom-url.com/" },
547+ )
548+ assert client .models ._api_client .location == location
549+ assert client .models ._api_client .project == project_id
550+ assert (
551+ client .models ._api_client .get_read_only_http_options ()["base_url" ]
552+ == "https://my-custom-url.com/"
553+ )
554+
555+
519556def test_vertexai_no_default_location_when_env_location_set (monkeypatch ):
520557 # Verify that location is NOT defaulted to global when set via environment
521558 project_id = "fake_project_id"
0 commit comments