Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

fix(providers/vertex): Vertex route multi-region locations (#3802)

slxng1758a9c1ac536879
diff --git a/headroom/providers/vertex/runtime.py b/headroom/providers/vertex/runtime.py
index 4cf6194de..8a62de7f0 100644
--- a/headroom/providers/vertex/runtime.py
+++ b/headroom/providers/vertex/runtime.py
@@ -18,6 +18,10 @@ _VERTEX_GLOBAL_API_URL = "https://aiplatform.googleapis.com"
# port, path, or URL-fragment delimiter into the interpolated hostname.
_VERTEX_REGION_RE = re.compile(r"^[a-z0-9]+(?:-[a-z0-9]+)*$")
+# The only documented Vertex multi-region ids; an explicit allowlist since a
+# future bare-word location need not be one.
+_VERTEX_MULTI_REGION_LOCATIONS = frozenset({"us", "eu"})
+
VERTEX_GOOGLE_PUBLISHER = "google"
VERTEX_ANTHROPIC_PUBLISHER = "anthropic"
VERTEX_GOOGLE_PROVIDER_NAME = "vertex:google"
@@ -82,4 +86,6 @@ def vertex_target_for_location(configured_target: str, location: str) -> str:
return configured_target
if not location or location == "global" or not _VERTEX_REGION_RE.match(location):
return _VERTEX_GLOBAL_API_URL
+ if location in _VERTEX_MULTI_REGION_LOCATIONS:
+ return f"https://aiplatform.{location}.rep.googleapis.com"
return f"https://{location}-aiplatform.googleapis.com"
diff --git a/tests/test_provider_vertex_runtime.py b/tests/test_provider_vertex_runtime.py
index 8c3584054..165e918c8 100644
--- a/tests/test_provider_vertex_runtime.py
+++ b/tests/test_provider_vertex_runtime.py
@@ -71,6 +71,24 @@ def test_vertex_target_for_location_derives_regional_hosts_from_default_target()
)
+def test_vertex_target_for_location_uses_rep_hostname_for_multi_region() -> None:
+ assert vertex_target_for_location(DEFAULT_VERTEX_API_URL, "us") == (
+ "https://aiplatform.us.rep.googleapis.com"
+ )
+ assert vertex_target_for_location(DEFAULT_VERTEX_API_URL, "eu") == (
+ "https://aiplatform.eu.rep.googleapis.com"
+ )
+
+
+def test_vertex_target_for_location_falls_back_for_unsupported_bare_word_locations() -> None:
+ assert vertex_target_for_location(DEFAULT_VERTEX_API_URL, "asia") == (
+ "https://asia-aiplatform.googleapis.com"
+ )
+ assert vertex_target_for_location(DEFAULT_VERTEX_API_URL, "foo") == (
+ "https://foo-aiplatform.googleapis.com"
+ )
+
+
def test_vertex_target_for_location_honors_explicit_gateway() -> None:
assert vertex_target_for_location("https://vertex-gateway.internal", "europe-west1") == (
"https://vertex-gateway.internal"