diff --git a/litellm/router.py b/litellm/router.py index a2aec6847a3..aa36ddf7eef 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -2574,6 +2574,16 @@ class Router: llm_provider="", ) + ## CHECK MAPPED FINISH REASON ERROR ## + if isinstance(response, ModelResponse): + if self._should_raise_mapped_finish_reason_error(model=model, response=response, kwargs=kwargs): + raise self._finish_reason_failure_error( + model=model, reason=self._get_mapped_finish_reason(response) + ) + self._account_mapped_finish_reason_failure( + model=model, deployment=deployment, response=response, kwargs=kwargs + ) + if ( isinstance(response, CustomStreamWrapper) and response.completion_stream is None @@ -3698,6 +3708,16 @@ class Router: llm_provider="", ) + ## CHECK MAPPED FINISH REASON ERROR ## + if isinstance(response, ModelResponse): + if self._should_raise_mapped_finish_reason_error(model=model, response=response, kwargs=kwargs): + raise self._finish_reason_failure_error( + model=model, reason=self._get_mapped_finish_reason(response) + ) + self._account_mapped_finish_reason_failure( + model=model, deployment=deployment, response=response, kwargs=kwargs + ) + if ( isinstance(response, CustomStreamWrapper) and response.completion_stream is None