mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-17 09:34:48 +00:00
fix(responses): return 400 with standard OpenAI error when input is missing in Responses API
This commit is contained in:
parent
e2aff27221
commit
275dbfaf51
4 changed files with 33 additions and 14 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue