From d10ec508078a610433b9f48c5ed194ca6375b6b2 Mon Sep 17 00:00:00 2001 From: factnn <166481866+factnn@users.noreply.github.com> Date: Thu, 18 Jun 2026 18:48:58 +0800 Subject: [PATCH] test: verify overhead computed for routes without pre-existing value GH#30566 --- .../test_response_metadata.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test_litellm/litellm_core_utils/llm_response_utils/test_response_metadata.py b/tests/test_litellm/litellm_core_utils/llm_response_utils/test_response_metadata.py index 203c6d3da0d..d481743d29a 100644 --- a/tests/test_litellm/litellm_core_utils/llm_response_utils/test_response_metadata.py +++ b/tests/test_litellm/litellm_core_utils/llm_response_utils/test_response_metadata.py @@ -8,6 +8,8 @@ through _hidden_params to the x-litellm-callback-duration-ms response header. import datetime from unittest.mock import MagicMock +import pytest + import litellm.litellm_core_utils.llm_response_utils.response_metadata as response_metadata_mod import litellm.proxy.common_request_processing as common_request_processing_mod from litellm.litellm_core_utils.litellm_logging import Logging @@ -91,6 +93,32 @@ class TestCallbackDurationMs: # overhead should also be set assert hidden.get("litellm_overhead_time_ms") is not None + def test_overhead_computed_for_routes_without_pre_existing_value(self): + """GH#30566: overhead is set even when _hidden_params + does not already contain litellm_overhead_time_ms. + This simulates non-chat-completions routes that skip + the SDK-level update_response_metadata call.""" + result = ModelResponse() + logging_obj = self._make_logging_obj(llm_api_duration_ms=900.0) + logging_obj._response_cost_calculator = MagicMock(return_value=0.001) + logging_obj.litellm_call_id = "test-gh30566" + + start = datetime.datetime(2025, 1, 1, 0, 0, 0) + end = datetime.datetime(2025, 1, 1, 0, 0, 1) + + update_response_metadata( + result=result, + logging_obj=logging_obj, + model="gpt-4", + kwargs={}, + start_time=start, + end_time=end, + ) + + hidden = result._hidden_params + assert hidden.get("litellm_overhead_time_ms") == pytest.approx(100.0, rel=0.01) + assert hidden.get("_response_ms") == pytest.approx(1000.0, rel=0.01) + class TestCallbackDurationInCustomHeaders: """Test that callback_duration_ms flows into get_custom_headers."""