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(responses): preserve query params in compact URL construction (#22668)
SebLz2b91978b9935
diff --git a/litellm/llms/openai/responses/transformation.py b/litellm/llms/openai/responses/transformation.pyindex 2988e0970a3..28080103661 100644--- a/litellm/llms/openai/responses/transformation.py+++ b/litellm/llms/openai/responses/transformation.py@@ -528,7 +528,10 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig):OpenAI API expects the following request- POST /v1/responses/compact"""- url = f"{api_base}/compact"+ # Preserve query params (e.g., api-version) while appending /compact.+ parsed_url = httpx.URL(api_base)+ compact_path = parsed_url.path.rstrip("/") + "/compact"+ url = str(parsed_url.copy_with(path=compact_path))input = self._validate_input_param(input)data = dict(diff --git a/tests/test_litellm/llms/openai/responses/test_openai_responses_transformation.py b/tests/test_litellm/llms/openai/responses/test_openai_responses_transformation.pyindex 1a5ab808f7b..d3214a88018 100644--- a/tests/test_litellm/llms/openai/responses/test_openai_responses_transformation.py+++ b/tests/test_litellm/llms/openai/responses/test_openai_responses_transformation.py@@ -686,6 +686,48 @@ class TestTransformListInputItemsRequest:# Assertassert "include" not in params # Empty list should not be included+ def test_openai_transform_compact_response_api_request_query_params_preserved(self):+ """Test compact URL construction preserves query params and appends path."""+ # Setup+ azure_style_api_base = (+ "https://test.openai.azure.com/openai/responses?api-version=2024-05-01-preview"+ )++ # Execute+ url, data = self.openai_config.transform_compact_response_api_request(+ model="gpt-5.2-codex",+ input="hello",+ response_api_optional_request_params={},+ api_base=azure_style_api_base,+ litellm_params=self.litellm_params,+ headers=self.headers,+ )++ # Assert+ assert (+ url+ == "https://test.openai.azure.com/openai/responses/compact?api-version=2024-05-01-preview"+ )+ assert data["model"] == "gpt-5.2-codex"+ assert data["input"] == "hello"++ def test_openai_transform_compact_response_api_request_path_without_query(self):+ """Test compact URL construction for base URL without query params."""+ # Execute+ url, data = self.openai_config.transform_compact_response_api_request(+ model="gpt-4o",+ input="hello",+ response_api_optional_request_params={},+ api_base="https://api.openai.com/v1/responses",+ litellm_params=self.litellm_params,+ headers=self.headers,+ )++ # Assert+ assert url == "https://api.openai.com/v1/responses/compact"+ assert data["model"] == "gpt-4o"+ assert data["input"] == "hello"+def test_azure_transform_list_input_items_request_minimal(self):"""Test Azure implementation with minimal parameters"""# Setup@@ -1239,4 +1281,4 @@ class TestPhaseParameter:assert validated[0]["phase"] == "commentary"assert validated[1]["phase"] == "final_answer"- assert "phase" not in validated[2]\ No newline at end of file+ assert "phase" not in validated[2]