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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(azure): build responses input_items url with path before query string (#32270)
Mateo Wange2df153bfbfe
diff --git a/litellm/llms/azure/responses/transformation.py b/litellm/llms/azure/responses/transformation.pyindex fef9b7d0154..d0b0dbb070d 100644--- a/litellm/llms/azure/responses/transformation.py+++ b/litellm/llms/azure/responses/transformation.py@@ -205,7 +205,7 @@ class AzureOpenAIResponsesAPIConfig(OpenAIResponsesAPIConfig):################################################################### DELETE RESPONSE API TRANSFORMATION #######################################################################- def _construct_url_for_response_id_in_path(self, api_base: str, response_id: str) -> str:+ def _construct_url_for_response_id_in_path(self, api_base: str, response_id: str, path_suffix: str = "") -> str:"""Constructs a URL for the API request with the response_id in the path."""@@ -218,14 +218,14 @@ class AzureOpenAIResponsesAPIConfig(OpenAIResponsesAPIConfig):# Remove trailing slash if present to avoid double slashespath = parsed_url.path.rstrip("/")encoded_response_id = encode_url_path_segment(response_id, field_name="response_id")- new_path = f"{path}/{encoded_response_id}"+ new_path = f"{path}/{encoded_response_id}{path_suffix}"# Reconstruct the URL with all original components but with the modified pathconstructed_url = urlunparse((parsed_url.scheme, # http, httpsparsed_url.netloc, # domain name, port- new_path, # path with response_id added+ new_path,parsed_url.params, # parametersparsed_url.query, # query stringparsed_url.fragment, # fragment@@ -288,7 +288,9 @@ class AzureOpenAIResponsesAPIConfig(OpenAIResponsesAPIConfig):limit: int = 20,order: Literal["asc", "desc"] = "desc",) -> Tuple[str, Dict]:- url = self._construct_url_for_response_id_in_path(api_base=api_base, response_id=response_id) + "/input_items"+ url = self._construct_url_for_response_id_in_path(+ api_base=api_base, response_id=response_id, path_suffix="/input_items"+ )params: Dict[str, Any] = {}if after is not None:params["after"] = after@@ -322,27 +324,8 @@ class AzureOpenAIResponsesAPIConfig(OpenAIResponsesAPIConfig):This function handles URLs with query parameters by inserting the response_idat the correct location (before any query parameters)."""- from urllib.parse import urlparse, urlunparse-- # Parse the URL to separate its components- parsed_url = urlparse(api_base)-- # Insert the response_id and /cancel at the end of the path component- # Remove trailing slash if present to avoid double slashes- path = parsed_url.path.rstrip("/")- encoded_response_id = encode_url_path_segment(response_id, field_name="response_id")- new_path = f"{path}/{encoded_response_id}/cancel"-- # Reconstruct the URL with all original components but with the modified path- cancel_url = urlunparse(- (- parsed_url.scheme, # http, https- parsed_url.netloc, # domain name, port- new_path, # path with response_id and /cancel added- parsed_url.params, # parameters- parsed_url.query, # query string- parsed_url.fragment, # fragment- )+ cancel_url = self._construct_url_for_response_id_in_path(+ api_base=api_base, response_id=response_id, path_suffix="/cancel")data: Dict = {}diff --git a/tests/test_litellm/llms/azure/response/test_azure_transformation.py b/tests/test_litellm/llms/azure/response/test_azure_transformation.pyindex a4bd14d69ff..24ae563fb76 100644--- a/tests/test_litellm/llms/azure/response/test_azure_transformation.py+++ b/tests/test_litellm/llms/azure/response/test_azure_transformation.py@@ -337,6 +337,24 @@ class TestAzureResponsesAPIConfig:assert url == expected_urlassert data == {}+ def test_azure_list_input_items_request_url_path_before_query(self):+ from litellm.types.router import GenericLiteLLMParams++ api_base = "https://test.openai.azure.com/openai/responses?api-version=2025-03-01-preview"++ url, params = self.config.transform_list_input_items_request(+ response_id="resp_test123",+ api_base=api_base,+ litellm_params=GenericLiteLLMParams(api_version="2025-03-01-preview"),+ headers={},+ )++ assert (+ url+ == "https://test.openai.azure.com/openai/responses/resp_test123/input_items?api-version=2025-03-01-preview"+ )+ assert params == {"limit": 20, "order": "desc"}+def test_azure_cancel_response_api_response(self):"""Test Azure cancel response API response transformation"""from unittest.mock import Mock