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]

fix(azure_ai): keep a deployment named like the first native path segment in the relayed URL

mateo-berri8627576c9c37
diff --git a/litellm/llms/azure_ai/passthrough/transformation.py b/litellm/llms/azure_ai/passthrough/transformation.py
index ed630bc6f2b..f2be1d95593 100644
--- a/litellm/llms/azure_ai/passthrough/transformation.py
+++ b/litellm/llms/azure_ai/passthrough/transformation.py
@@ -62,6 +62,10 @@ def foundry_root(api_base: str) -> str:
return str(url.copy_with(path="/" + "/".join(root_segments), query=None)).rstrip("/")
+def is_repeated_native_prefix(native_segments: tuple[str, ...], overlap: int) -> bool:
+ return overlap == len(native_segments) or native_segments[0] == "openai"
+
+
def without_repeated_native_prefix(root: str, native_endpoint: str) -> str:
url: Final = httpx.URL(root)
root_segments: Final = tuple(segment for segment in url.path.split("/") if segment)
@@ -71,6 +75,7 @@ def without_repeated_native_prefix(root: str, native_endpoint: str) -> str:
length
for length in range(min(len(root_segments), len(native_segments)), 0, -1)
if tuple(segment.casefold() for segment in root_segments[-length:]) == native_segments[:length]
+ and is_repeated_native_prefix(native_segments, length)
),
0,
)
diff --git a/tests/test_litellm/llms/azure_ai/passthrough/test_azure_ai_passthrough_transformation.py b/tests/test_litellm/llms/azure_ai/passthrough/test_azure_ai_passthrough_transformation.py
index 1b9036c50c5..c8007acf70f 100644
--- a/tests/test_litellm/llms/azure_ai/passthrough/test_azure_ai_passthrough_transformation.py
+++ b/tests/test_litellm/llms/azure_ai/passthrough/test_azure_ai_passthrough_transformation.py
@@ -153,6 +153,20 @@ def test_deployment_root_api_base_is_not_repeated_when_the_relay_carries_the_dep
assert base == "https://my-resource.openai.azure.com"
+def test_deployment_named_like_the_first_native_segment_keeps_its_deployment_root():
+ url, base = AzureAIPassthroughConfig().get_complete_url(
+ api_base="https://my-resource.openai.azure.com/openai/deployments/chat",
+ api_key="key",
+ model="chat",
+ endpoint="aoai-chat/chat/completions",
+ request_query_params={"api-version": "2024-10-21"},
+ litellm_params={"litellm_metadata": {"model_group": "aoai-chat"}},
+ )
+
+ assert str(url) == "https://my-resource.openai.azure.com/openai/deployments/chat/chat/completions?api-version=2024-10-21"
+ assert base == "https://my-resource.openai.azure.com/openai/deployments/chat"
+
+
def test_parse_relay_under_a_models_api_base_targets_the_foundry_root():
url, _ = AzureAIPassthroughConfig().get_complete_url(
api_base=f"{FOUNDRY_BASE}/models",