Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test(e2e): enforce the cross-region invariant on the Bedrock allowlist

Yuneng Jiang7c2234be3a91
diff --git a/tests/code_coverage_tests/test_provider_cache.py b/tests/code_coverage_tests/test_provider_cache.py
index ac1ccd5692b..c24ba8d6221 100644
--- a/tests/code_coverage_tests/test_provider_cache.py
+++ b/tests/code_coverage_tests/test_provider_cache.py
@@ -33,7 +33,13 @@ from provider_cache import (
successful_response,
)
from provider_cache_redis import PUBLISH, RedisCommands, RedisResponseStore, configured_cache, redis_store
-from provider_cache_routing import LIVE_PROVIDER_REQUIRED, route_cache_model
+from provider_cache_routing import (
+ BEDROCK_CROSS_REGION_PREFIX,
+ BEDROCK_EDGE_MODELS,
+ LIVE_PROVIDER_REQUIRED,
+ bedrock_region,
+ route_cache_model,
+)
from fixture_mode import SESSION_TEST_KEY
from provider_edge import EDGE_MOUNTS, configured_cache_backend, resolve_mount, start_provider_edge
from provider_edge_bedrock import bedrock_signer
@@ -856,6 +862,31 @@ def test_bedrock_deployments_the_edge_must_not_touch_keep_their_direct_route(par
assert routed is params
[email protected]("declared,expected", [
+ (None, "us-east-1"),
+ ("us-west-2", "us-west-2"),
+ ("eu-west-1", "eu-west-1"),
+ ("os.environ/AWS_REGION", "us-east-1"),
+ ("os.environ/ANY_OTHER_NAME", "us-east-1"),
+])
+def test_a_region_only_the_proxy_can_resolve_falls_back_to_the_default_mount(
+ declared: str | None, expected: str,
+) -> None:
+ """A declared literal region is the one the deployment meant. A region the
+ proxy resolves from its own environment is one the run pod cannot see, and
+ the default mount answers it."""
+ assert bedrock_region(declared) == expected
+
+
+def test_every_model_on_the_edge_allowlist_is_a_cross_region_profile() -> None:
+ """Answering an env-referenced region with the default mount is only correct
+ for a profile that fans out across the US regions and is reachable from any
+ of them. A single-region model on this list would be sent to a region it may
+ not exist in, so the list is where that is caught."""
+ assert BEDROCK_EDGE_MODELS
+ assert all(model.startswith(BEDROCK_CROSS_REGION_PREFIX) for model in BEDROCK_EDGE_MODELS)
+
+
@pytest.mark.parametrize("mode", ["batch", "realtime", "image_generation"])
def test_a_bedrock_deployment_with_a_mode_keeps_its_direct_route(mode: ModelMode) -> None:
params: Final = LiteLLMParamsBody(model="bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0")
diff --git a/tests/e2e/provider_cache_routing.py b/tests/e2e/provider_cache_routing.py
index 97e05344423..f9775a2b152 100644
--- a/tests/e2e/provider_cache_routing.py
+++ b/tests/e2e/provider_cache_routing.py
@@ -21,22 +21,18 @@ BEDROCK_EDGE_MODELS: Final = frozenset(
ENV_REFERENCE_PREFIX: Final = "os.environ/"
-def bedrock_region(declared: str | None, model: str) -> str | None:
- """The region whose edge mount a deployment belongs to, or None when the
- harness cannot know it.
+def bedrock_region(declared: str | None) -> str:
+ """The region whose edge mount a deployment belongs to.
- Most Bedrock deployments declare `os.environ/AWS_REGION`, which the proxy
- resolves from its own environment. The run pod does not share that
- environment, so the harness genuinely does not know the region. A `us.`
- inference profile fans out across the US regions and is reachable from any
- of them, so the default entry point is correct for those whatever the proxy
- resolved; anything else keeps its direct path rather than being sent to a
- region the model may not exist in."""
- if declared is None:
+ Most Bedrock deployments declare `os.environ/AWS_REGION`, which only the
+ proxy can resolve from its own environment; the run pod does not share it.
+ Answering those with the default mount is correct because every model on the
+ edge allowlist is a `us.` inference profile, which fans out across the US
+ regions and is reachable from any of them. That invariant is enforced on the
+ allowlist itself rather than re-checked per call."""
+ if declared is None or declared.startswith(ENV_REFERENCE_PREFIX):
return DEFAULT_BEDROCK_REGION
- if not declared.startswith(ENV_REFERENCE_PREFIX):
- return declared
- return DEFAULT_BEDROCK_REGION if model.startswith(BEDROCK_CROSS_REGION_PREFIX) else None
+ return declared
def bedrock_mount(params: LiteLLMParamsBody) -> str | None:
@@ -51,8 +47,7 @@ def bedrock_mount(params: LiteLLMParamsBody) -> str | None:
model: Final = route.partition("/")[2] or route
if model not in BEDROCK_EDGE_MODELS:
return None
- region: Final = bedrock_region(params.aws_region_name, model)
- return None if region is None else f"bedrock/{region}"
+ return f"bedrock/{bedrock_region(params.aws_region_name)}"
def route_bedrock(