From dfd16b0b50e117106d808080f59143556daf9c2f Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Mon, 5 Oct 2026 16:37:38 -0700 Subject: [PATCH] fix(chatgpt): leave an empty string input for the backend to reject OpenAI's Responses API answers 400 for input "", so wrapping it into a one-message list would turn that error into a billed completion on the Codex backend. Only a non-empty string becomes the user message. --- litellm/llms/chatgpt/responses/transformation.py | 2 +- .../test_chatgpt_responses_transformation.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/litellm/llms/chatgpt/responses/transformation.py b/litellm/llms/chatgpt/responses/transformation.py index 8c0261cd1f9..db5e43f65bc 100644 --- a/litellm/llms/chatgpt/responses/transformation.py +++ b/litellm/llms/chatgpt/responses/transformation.py @@ -82,7 +82,7 @@ class ChatGPTResponsesAPIConfig(OpenAIResponsesAPIConfig): litellm_params, headers, ) - if isinstance(input, str): + if isinstance(input, str) and input != "": request["input"] = [{"role": "user", "content": [{"type": "input_text", "text": input}]}] base_instructions: Final = get_chatgpt_default_instructions() existing_instructions: Final = request.get("instructions") diff --git a/tests/unit/llms/chatgpt/responses/test_chatgpt_responses_transformation.py b/tests/unit/llms/chatgpt/responses/test_chatgpt_responses_transformation.py index f7a8033e2dd..f505ceb8da4 100644 --- a/tests/unit/llms/chatgpt/responses/test_chatgpt_responses_transformation.py +++ b/tests/unit/llms/chatgpt/responses/test_chatgpt_responses_transformation.py @@ -226,6 +226,18 @@ class TestChatGPTResponsesAPITransformation: assert request["input"] == list_input + def test_chatgpt_leaves_empty_string_input_for_the_backend_to_reject(self) -> None: + config: Final = ChatGPTResponsesAPIConfig() + request: Final = config.transform_responses_api_request( + model="chatgpt/gpt-6.1-sol", + input="", + response_api_optional_request_params={}, + litellm_params=GenericLiteLLMParams(), + headers={}, + ) + + assert request["input"] == "" + @pytest.mark.parametrize( "model_name", [