fix(responses): preserve query params in compact URL construction (#22668)

Co-authored-by: LIESLEN <sebastien.lentz@arcelormittal.com>
This commit is contained in:
SebLz 2026-03-04 20:33:13 +01:00 • committed by GitHub
parent 750fc4a980
commit 2b91978b99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 47 additions and 2 deletions

View file

@ -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(

View file

@ -686,6 +686,48 @@ class TestTransformListInputItemsRequest:
# Assert
assert "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]
assert "phase" not in validated[2]