diff --git a/litellm/llms/chatgpt/responses/transformation.py b/litellm/llms/chatgpt/responses/transformation.py index 3c59ca16581..af1f7a70a48 100644 --- a/litellm/llms/chatgpt/responses/transformation.py +++ b/litellm/llms/chatgpt/responses/transformation.py @@ -73,6 +73,7 @@ class ChatGPTResponsesAPIConfig(OpenAIResponsesAPIConfig): litellm_params, headers, ) + request["input"] = self._normalize_chatgpt_input(request.get("input")) base_instructions = get_chatgpt_default_instructions() existing_instructions = request.get("instructions") if existing_instructions: @@ -105,6 +106,18 @@ class ChatGPTResponsesAPIConfig(OpenAIResponsesAPIConfig): return {k: v for k, v in request.items() if k in allowed_keys} + @staticmethod + def _normalize_chatgpt_input(input_value: Any) -> Any: + if isinstance(input_value, str): + return [ + { + "role": "user", + "content": [{"type": "input_text", "text": input_value}], + } + ] + + return input_value + def transform_response_api_response( self, model: str, diff --git a/tests/test_litellm/llms/chatgpt/responses/test_chatgpt_responses_transformation.py b/tests/test_litellm/llms/chatgpt/responses/test_chatgpt_responses_transformation.py index c0a0927b7d1..d9353c16bae 100644 --- a/tests/test_litellm/llms/chatgpt/responses/test_chatgpt_responses_transformation.py +++ b/tests/test_litellm/llms/chatgpt/responses/test_chatgpt_responses_transformation.py @@ -107,6 +107,24 @@ class TestChatGPTResponsesAPITransformation: "You are Codex, based on GPT-5." ) + def test_chatgpt_normalizes_string_input_for_responses_api(self): + config = ChatGPTResponsesAPIConfig() + + request = config.transform_responses_api_request( + model="chatgpt/gpt-5.4", + input="hi", + response_api_optional_request_params={}, + litellm_params=GenericLiteLLMParams(), + headers={}, + ) + + assert request["input"] == [ + { + "role": "user", + "content": [{"type": "input_text", "text": "hi"}], + } + ] + @pytest.mark.parametrize( "model_name", [