This commit is contained in:
SrivalliKoppanapudi 2026-09-20 03:36:46 -04:00 • committed by GitHub
commit d813bf8ce9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 207 additions and 13 deletions

View file

@ -331,6 +331,15 @@ class BaseResponsesAPIConfig(ABC):
########## END COMPACT RESPONSE API TRANSFORMATION ######
#########################################################
@staticmethod
def normalize_responses_input(input: str | ResponseInputParam) -> ResponseInputParam:
if isinstance(input, str):
return cast(
"ResponseInputParam",
[{"role": "user", "content": input}], # mutable-ok: outbound Responses input item
) # cast-ok: OpenAI string shorthand is one user item
return input
@staticmethod
def strip_custom_tool_call_namespace_from_responses_input(
input: str | ResponseInputParam,

View file

@ -2688,9 +2688,10 @@ class BaseLLMHTTPHandler:
litellm_params=dict(litellm_params),
)
canonical_input: Final = BaseResponsesAPIConfig.normalize_responses_input(input)
data = responses_api_provider_config.transform_responses_api_request(
model=model,
input=input,
input=canonical_input,
response_api_optional_request_params=response_api_optional_request_params,
litellm_params=litellm_params,
headers=headers,
@ -2876,9 +2877,10 @@ class BaseLLMHTTPHandler:
litellm_params=dict(litellm_params),
)
canonical_input: Final = BaseResponsesAPIConfig.normalize_responses_input(input)
data = responses_api_provider_config.transform_responses_api_request(
model=model,
input=input,
input=canonical_input,
response_api_optional_request_params=response_api_optional_request_params,
litellm_params=litellm_params,
headers=headers,

View file

@ -1204,8 +1204,9 @@ def test_basic_computer_use_preview_tool_call():
assert request_body["truncation"] == "auto"
# Validate the input format
assert isinstance(request_body["input"], str)
assert request_body["input"] == "Check the latest OpenAI news on bing.com."
assert request_body["input"] == [
{"role": "user", "content": "Check the latest OpenAI news on bing.com."}
]
def test_mcp_tools_with_responses_api():
@ -1500,7 +1501,9 @@ async def test_aresponses_service_tier_and_safety_identifier():
request_body["safety_identifier"] == "123"
), "safety_identifier should be '123' in request body"
assert request_body["model"] == "gpt-5.5"
assert request_body["input"] == "Test with service tier and safety identifier"
assert request_body["input"] == [
{"role": "user", "content": "Test with service tier and safety identifier"}
]
# Validate the response
print("Response:", json.dumps(response, indent=4, default=str))
@ -1596,7 +1599,9 @@ async def test_openai_gpt5_reasoning_effort_parameter():
request_body["reasoning"]["effort"] == "minimal"
), "reasoning_effort should be 'minimal' in request body"
assert request_body["model"] == "gpt-5-mini"
assert request_body["input"] == "What is the capital of France?"
assert request_body["input"] == [
{"role": "user", "content": "What is the capital of France?"}
]
# Validate the response
print("Response:", json.dumps(response, indent=4, default=str))
@ -1774,7 +1779,7 @@ async def test_aresponses_extra_body_params_passed(extra_body_mock_response_data
assert "experimental_feature" in request_body
assert request_body["experimental_feature"] is True
assert request_body["model"] == "gpt-5.5"
assert request_body["input"] == "Test input"
assert request_body["input"] == [{"role": "user", "content": "Test input"}]
def test_responses_extra_body_params_passed_sync(extra_body_mock_response_data):

View file

@ -1,6 +1,11 @@
{
"model": "gpt-5-mini",
"input": "List files in /mnt/data and run python --version.",
"input": [
{
"role": "user",
"content": "List files in /mnt/data and run python --version."
}
],
"tools": [
{
"type": "shell",

View file

@ -1,6 +1,11 @@
{
"model": "gpt-4o",
"input": "List files in /mnt/data and run python --version.",
"input": [
{
"role": "user",
"content": "List files in /mnt/data and run python --version."
}
],
"context_management": [
{
"type": "compaction",

View file

@ -227,7 +227,7 @@ def _assert_native_responses_request(route, expected_url, expected_model):
assert f"{request.url.scheme}://{request.url.host}{request.url.path}" == expected_url
assert request.headers["api-key"] == "fake-key"
assert body["model"] == expected_model
assert body["input"] == "What is the weather in SF?"
assert body["input"] == [{"role": "user", "content": "What is the weather in SF?"}]
assert "messages" not in body
assert body["reasoning"] == {"effort": "high"}
assert body["tools"] == [WEATHER_TOOL]

View file

@ -11,6 +11,7 @@ import httpx
import pytest
import litellm
from litellm.llms.base_llm.responses.transformation import BaseResponsesAPIConfig
from litellm.llms.chatgpt.responses.transformation import ChatGPTResponsesAPIConfig
from litellm.llms.openai.common_utils import OpenAIError
from litellm.main import responses_api_bridge_check
@ -114,6 +115,22 @@ class TestChatGPTResponsesAPITransformation:
assert headers["accept"] == "text/event-stream"
assert headers["session_id"] == "session-123"
def test_chatgpt_string_input_is_list_after_central_normalize(self):
config = ChatGPTResponsesAPIConfig()
request = config.transform_responses_api_request(
model="chatgpt/gpt-5.3-codex",
input=BaseResponsesAPIConfig.normalize_responses_input(
"Reply with exactly ROUTE_OK."
),
response_api_optional_request_params={},
litellm_params=GenericLiteLLMParams(),
headers={},
)
assert request["input"] == [
{"role": "user", "content": "Reply with exactly ROUTE_OK."}
]
@pytest.mark.parametrize(
"model_name",
[

View file

@ -259,6 +259,147 @@ def test_prepare_fake_stream_request():
assert result_data["messages"] == [{"role": "user", "content": "Hello"}]
def test_response_api_handler_passes_string_input_to_transform_as_user_list():
handler = BaseLLMHTTPHandler()
config = Mock()
config.validate_environment.return_value = {}
config.get_complete_url.return_value = "https://chatgpt.example.com/responses"
config.sign_request.return_value = ({}, None)
config.transform_response_api_response.return_value = ResponsesAPIResponse(
id="resp_1",
created_at=0,
output=[],
status="completed",
model="gpt-5.3-codex",
)
def transform_responses_api_request(**kwargs):
return {
"model": kwargs["model"],
"input": kwargs["input"],
}
config.transform_responses_api_request.side_effect = transform_responses_api_request
client = HTTPHandler(client=httpx.Client())
client.post = Mock(
return_value=httpx.Response(
200,
request=httpx.Request("POST", "https://chatgpt.example.com/responses"),
)
)
handler.response_api_handler(
model="gpt-5.3-codex",
input="Reply with exactly ROUTE_OK.",
responses_api_provider_config=config,
response_api_optional_request_params={},
custom_llm_provider="chatgpt",
litellm_params=GenericLiteLLMParams(),
logging_obj=Mock(),
client=client,
)
assert config.transform_responses_api_request.call_args.kwargs["input"] == [
{"role": "user", "content": "Reply with exactly ROUTE_OK."}
]
assert client.post.call_args.kwargs["json"]["input"] == [
{"role": "user", "content": "Reply with exactly ROUTE_OK."}
]
@pytest.mark.asyncio
async def test_async_response_api_handler_passes_string_input_to_transform_as_user_list():
handler = BaseLLMHTTPHandler()
config = Mock()
config.validate_environment.return_value = {}
config.get_complete_url.return_value = "https://chatgpt.example.com/responses"
config.sign_request.return_value = ({}, None)
config.should_fake_stream.return_value = False
config.transform_response_api_response.return_value = ResponsesAPIResponse(
id="resp_1",
created_at=0,
output=[],
status="completed",
model="gpt-5.3-codex",
)
def transform_responses_api_request(**kwargs):
return {
"model": kwargs["model"],
"input": kwargs["input"],
}
config.transform_responses_api_request.side_effect = transform_responses_api_request
client = AsyncHTTPHandler()
client.post = AsyncMock(
return_value=httpx.Response(
200,
request=httpx.Request("POST", "https://chatgpt.example.com/responses"),
)
)
logging_obj = Mock()
logging_obj.dynamic_success_callbacks = []
await handler.async_response_api_handler(
model="gpt-5.3-codex",
input="Reply with exactly ROUTE_OK.",
responses_api_provider_config=config,
response_api_optional_request_params={},
custom_llm_provider="chatgpt",
litellm_params=GenericLiteLLMParams(),
logging_obj=logging_obj,
client=client,
)
assert config.transform_responses_api_request.call_args.kwargs["input"] == [
{"role": "user", "content": "Reply with exactly ROUTE_OK."}
]
assert client.post.call_args.kwargs["json"]["input"] == [
{"role": "user", "content": "Reply with exactly ROUTE_OK."}
]
def test_response_api_handler_leaves_list_input_untouched():
handler = BaseLLMHTTPHandler()
config = Mock()
config.validate_environment.return_value = {}
config.get_complete_url.return_value = "https://chatgpt.example.com/responses"
config.sign_request.return_value = ({}, None)
config.transform_response_api_response.return_value = ResponsesAPIResponse(
id="resp_1",
created_at=0,
output=[],
status="completed",
model="gpt-5.3-codex",
)
list_input = [{"role": "user", "content": "Reply with exactly ROUTE_OK."}]
def transform_responses_api_request(**kwargs):
return {"model": kwargs["model"], "input": kwargs["input"]}
config.transform_responses_api_request.side_effect = transform_responses_api_request
client = HTTPHandler(client=httpx.Client())
client.post = Mock(
return_value=httpx.Response(
200,
request=httpx.Request("POST", "https://chatgpt.example.com/responses"),
)
)
handler.response_api_handler(
model="gpt-5.3-codex",
input=list_input,
responses_api_provider_config=config,
response_api_optional_request_params={},
custom_llm_provider="chatgpt",
litellm_params=GenericLiteLLMParams(),
logging_obj=Mock(),
client=client,
)
assert config.transform_responses_api_request.call_args.kwargs["input"] is list_input
def test_response_api_handler_streams_when_provider_transform_adds_stream():
handler = BaseLLMHTTPHandler()
config = Mock()

View file

@ -321,7 +321,7 @@ def test_responses_call_keeps_a_developer_item_with_non_text_parts_in_place_as_a
)
def test_responses_call_forwards_string_input_and_instructions_unchanged() -> None:
def test_responses_call_normalizes_string_input_and_forwards_instructions() -> None:
client: Final = _mock_http_client(_fireworks_response("accounts/fireworks/models/kimi-k3"))
with patch(HTTPX_CLIENT_FACTORY, return_value=client):
litellm.responses(
@ -332,7 +332,7 @@ def test_responses_call_forwards_string_input_and_instructions_unchanged() -> No
)
_, _, body = _sent_request(client)
assert body["instructions"] == "Answer with exactly one word."
assert body["input"] == "What is the capital of France?"
assert body["input"] == [{"role": "user", "content": "What is the capital of France?"}]
def test_transform_request_forwards_non_string_instructions_and_input_untouched() -> None:

View file

@ -885,6 +885,15 @@ class TestOpenAIResponsesAPIConfig:
assert result.output_index == 0
assert result.content_index == 0
def test_normalize_responses_input_wraps_string_as_user_item(self):
assert BaseResponsesAPIConfig.normalize_responses_input("Reply with exactly ROUTE_OK.") == [
{"role": "user", "content": "Reply with exactly ROUTE_OK."}
]
def test_normalize_responses_input_leaves_list_untouched(self):
items = [{"role": "user", "content": "Reply with exactly ROUTE_OK."}]
assert BaseResponsesAPIConfig.normalize_responses_input(items) is items
def test_base_strip_custom_tool_call_namespace_all_providers(self):
"""Base helper strips ``namespace`` from custom_tool_call for every provider path."""
inp = [

View file

@ -219,6 +219,7 @@ async def test_aresponses_drops_stream_options():
post_kwargs = mock_post.call_args.kwargs
request_body = post_kwargs["json"] if "json" in post_kwargs else json.loads(post_kwargs["data"])
assert "stream_options" not in request_body
assert request_body["input"] == [{"role": "user", "content": "hi"}]
@pytest.mark.asyncio

View file

@ -141,7 +141,7 @@ async def test_opt_in_forwards_responses_natively():
assert chat_route.call_count == 0
request = responses_route.calls.last.request
assert request.headers["authorization"] == "Bearer sk-backend"
assert json.loads(request.content)["input"] == "hi"
assert json.loads(request.content)["input"] == [{"role": "user", "content": "hi"}]
assert isinstance(result, ResponsesAPIResponse)
assert result.output[0].content[0].text == "native"