diff --git a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py index 885512a2289..e32b7ac1cb6 100644 --- a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py +++ b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py @@ -779,7 +779,7 @@ def _build_passthrough_failure_request_payload( if logging_obj is not None: request_payload["litellm_logging_obj"] = logging_obj logging_litellm_params: Final = logging_obj.model_call_details.get("litellm_params") - existing_litellm_params: Final[dict] = request_payload.get("litellm_params") or {} + existing_litellm_params: Final[Mapping[str, object]] = request_payload.get("litellm_params") or {} api_base: Final = logging_litellm_params.get("api_base") if isinstance(logging_litellm_params, dict) else None if isinstance(api_base, str) and api_base and "api_base" not in existing_litellm_params: request_payload["litellm_params"] = {**existing_litellm_params, "api_base": api_base} @@ -1746,18 +1746,12 @@ async def pass_through_request( # Monitoring: Trigger post_call_failure_hook # for pass through endpoint failure ######################################################### - request_payload: Final[dict] = _parsed_body or {} - # add user_api_key_dict, litellm_call_id, passthrough_logging_payloa for logging - if kwargs: - for key, value in kwargs.items(): - request_payload[key] = value - if logging_obj is not None: - request_payload["litellm_logging_obj"] = logging_obj - - if "model" not in request_payload and _parsed_body and isinstance(_parsed_body, dict): - request_payload["model"] = _parsed_body.get("model", "") - if "custom_llm_provider" not in request_payload and custom_llm_provider: - request_payload["custom_llm_provider"] = custom_llm_provider + request_payload: Final = _build_passthrough_failure_request_payload( + parsed_body=_parsed_body, + kwargs=kwargs, + logging_obj=logging_obj, + custom_llm_provider=custom_llm_provider, + ) _carry_guardrail_logging_info(request_payload, post_call_guardrail_data) diff --git a/tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py b/tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py index 7ca14445f36..fe460cee305 100644 --- a/tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py +++ b/tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py @@ -399,12 +399,13 @@ async def test_pass_through_request_failure_handler(): ) as mock_processing: # Setup mock for post_call_failure_hook and pre_call_hook mock_proxy_logging.post_call_failure_hook = AsyncMock() - mock_proxy_logging.pre_call_hook = AsyncMock() + mock_proxy_logging.pre_call_hook = AsyncMock(return_value={}) # Setup mock for httpx client mock_client = MagicMock() mock_client.client = MagicMock() - mock_client.client.request = AsyncMock(side_effect=httpx.HTTPError("Request failed")) + mock_client.client.build_request = MagicMock(return_value=MagicMock()) + mock_client.client.send = AsyncMock(side_effect=httpx.ConnectError("boom")) mock_get_client.return_value = mock_client # Mock headers for custom headers @@ -437,7 +438,12 @@ async def test_pass_through_request_failure_handler(): # Verify the arguments to post_call_failure_hook call_args = mock_proxy_logging.post_call_failure_hook.call_args[1] assert call_args["user_api_key_dict"] == mock_user_api_key_dict - assert isinstance(call_args["original_exception"], TypeError) # Now expecting TypeError + assert isinstance(call_args["original_exception"], httpx.ConnectError) + request_data = call_args["request_data"] + logging_obj = request_data["litellm_logging_obj"] + api_base = request_data["litellm_params"]["api_base"] + assert api_base == logging_obj.model_call_details["litellm_params"]["api_base"] + assert api_base.startswith("http://test.com") assert "traceback_str" in call_args