diff --git a/litellm/proxy/response_api_endpoints/endpoints.py b/litellm/proxy/response_api_endpoints/endpoints.py index 36908f1949b..5907ffc64eb 100644 --- a/litellm/proxy/response_api_endpoints/endpoints.py +++ b/litellm/proxy/response_api_endpoints/endpoints.py @@ -245,12 +245,6 @@ async def responses_api( data = await _read_request_body(request=request) - if "input" not in data: - raise HTTPException( - status_code=400, - detail={"error": "input parameter is required"}, - ) - # Check if polling via cache should be used for this request from litellm.proxy.response_polling.polling_handler import ( should_use_polling_for_request, diff --git a/litellm/proxy/route_llm_request.py b/litellm/proxy/route_llm_request.py index 20b4708c193..536c58df65a 100644 --- a/litellm/proxy/route_llm_request.py +++ b/litellm/proxy/route_llm_request.py @@ -159,6 +159,7 @@ class ProxyModelNotFoundError(HTTPException): REQUIRED_BODY_PARAMS_BY_ROUTE: Final[Mapping[str, tuple[str, ...]]] = { "acompletion": ("messages",), "aembedding": ("input",), + "aresponses": ("input",), "acreate_batch": ("input_file_id", "endpoint", "completion_window"), } diff --git a/litellm/responses/main.py b/litellm/responses/main.py index a68cd02e61b..a286e94b8cd 100644 --- a/litellm/responses/main.py +++ b/litellm/responses/main.py @@ -518,8 +518,8 @@ def _prompt_management_sees_a_provisional_message_list( @client async def aresponses( - input: str | ResponseInputParam, - model: str, + input: str | ResponseInputParam | None = None, + model: str | None = None, include: list[ResponseIncludable] | None = None, instructions: str | None = None, max_output_tokens: int | None = None, @@ -554,6 +554,13 @@ async def aresponses( """ Async: Handles responses API requests by reusing the synchronous function """ + if input is None: + raise litellm.BadRequestError( + message="input is a required parameter for the Responses API", + model=model or "", + llm_provider=custom_llm_provider or "", + response=None, + ) local_vars: Final = locals() try: loop: Final = asyncio.get_event_loop() @@ -1065,8 +1072,8 @@ def _responses_try_dispatch_emulated_file_search( @client def responses( - input: str | ResponseInputParam, - model: str, + input: str | ResponseInputParam | None = None, + model: str | None = None, include: list[ResponseIncludable] | None = None, instructions: str | None = None, max_output_tokens: int | None = None, @@ -1103,6 +1110,13 @@ def responses( Synchronous version of the Responses API. Uses the synchronous HTTP handler to make requests. """ + if input is None: + raise litellm.BadRequestError( + message="input is a required parameter for the Responses API", + model=model or "", + llm_provider=custom_llm_provider or "", + response=None, + ) local_vars: Final = locals() try: diff --git a/tests/test_litellm/proxy/response_api_endpoints/test_endpoints.py b/tests/test_litellm/proxy/response_api_endpoints/test_endpoints.py index 02068878f1b..ed21f654c7d 100644 --- a/tests/test_litellm/proxy/response_api_endpoints/test_endpoints.py +++ b/tests/test_litellm/proxy/response_api_endpoints/test_endpoints.py @@ -58,9 +58,6 @@ class TestResponsesAPIEndpoints(unittest.TestCase): @patch("litellm.proxy.proxy_server.llm_router") @patch("litellm.proxy.proxy_server.user_api_key_auth") def test_openai_v1_responses_missing_input_raises_400(self, mock_auth, mock_router): - """ - Test that /openai/v1/responses returns 400 when 'input' is missing (Issue #41159). - """ mock_auth.return_value = MagicMock( token="test_token", user_id="test_user", @@ -78,7 +75,20 @@ class TestResponsesAPIEndpoints(unittest.TestCase): ) assert response.status_code == 400 - assert "input" in response.text.lower() + data = response.json() + assert "error" in data + assert "input" in data["error"]["message"].lower() + + def test_responses_missing_input_raises_bad_request_error(self): + with pytest.raises(litellm.BadRequestError) as exc_info: + litellm.responses(model="gpt-4o") + assert "input" in str(exc_info.value).lower() + + @pytest.mark.asyncio + async def test_aresponses_missing_input_raises_bad_request_error(self): + with pytest.raises(litellm.BadRequestError) as exc_info: + await litellm.aresponses(model="gpt-4o") + assert "input" in str(exc_info.value).lower() @pytest.mark.asyncio @patch("litellm.proxy.proxy_server.llm_router")