diff --git a/litellm/exceptions.py b/litellm/exceptions.py index b8e933bf046..ec572d3283c 100644 --- a/litellm/exceptions.py +++ b/litellm/exceptions.py @@ -637,7 +637,7 @@ class RejectedRequestError(BadRequestError): def __init__( self, message, - model, + model: str, llm_provider, request_data: dict, litellm_debug_info: str | None = None, diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index bd96548a078..f61bb317963 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -12824,7 +12824,7 @@ async def chat_completion( request_data=_data, ) _chat_response = litellm.ModelResponse() - _chat_response.model = _data.get("model") or e.model or "" + _chat_response.model = e.model _chat_response.choices[0].message.content = e.message if data.get("stream", None) is not None and data["stream"] is True: @@ -13010,7 +13010,7 @@ async def completion( else: _response = litellm.TextCompletionResponse() _response.choices[0].text = e.message - _response.model = _data.get("model") or e.model or "" + _response.model = e.model return _response except Exception as e: await proxy_logging_obj.post_call_failure_hook( diff --git a/tests/unit/proxy/test_rejected_request_response_model.py b/tests/unit/proxy/test_rejected_request_response_model.py index 398fef243d7..467a8dae8dc 100644 --- a/tests/unit/proxy/test_rejected_request_response_model.py +++ b/tests/unit/proxy/test_rejected_request_response_model.py @@ -17,10 +17,10 @@ from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.proxy_server import chat_completion, completion -async def _run_rejected_request(route, body, exception_model="my-model"): +async def _run_rejected_request(route, body): exception = RejectedRequestError( message="cached answer", - model=exception_model, + model=body["model"], llm_provider="", request_data=dict(body), ) @@ -64,18 +64,3 @@ async def test_rejected_text_completion_response_has_model(): # finish_reason is still None here, so this is not validated against # openai.types.Completion the way the chat response is. assert response.model == "my-model" - - -@pytest.mark.asyncio -@pytest.mark.parametrize( - "route, body", - [ - (chat_completion, {"model": "my-model", "messages": [{"role": "user", "content": "hi"}]}), - (completion, {"model": "my-model", "prompt": "hi"}), - ], -) -async def test_rejected_response_falls_back_to_request_model(route, body): - # RejectedRequestError is public, so a custom hook can raise it without a model. - response = await _run_rejected_request(route, body, exception_model=None) - - assert response.model == "my-model"