From 6eeb1b1c77c334fd308be24b238261b752cd2c58 Mon Sep 17 00:00:00 2001 From: sharosoo Date: Mon, 28 Sep 2026 20:01:20 +0900 Subject: [PATCH] fix(logging): skip async pre-call dispatch when no async input callbacks are registered --- litellm/utils.py | 3 ++- tests/unit/test_utils.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/litellm/utils.py b/litellm/utils.py index 06347564324..029498024f6 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -2079,7 +2079,8 @@ def client(original_function): else kwargs ) try: - await logging_obj.async_pre_call() + if litellm._async_input_callback: + await logging_obj.async_pre_call() result = await original_function(*args, **call_kwargs) except Exception as deployment_error: _deployment_call_end_time = datetime.datetime.now() # noqa: DTZ005 # matches the naive datetimes this whole function already times start_time/end_time with diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index b0c617ddb2e..0011cd82dd0 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -5298,6 +5298,8 @@ async def test_wrapper_async_awaits_async_input_callback_before_the_provider_cal def sync_callback(kwargs: dict) -> None: events.append(("sync", kwargs["log_event_type"])) + monkeypatch.setattr("litellm.litellm_core_utils.litellm_logging.customLogger", CustomLogger()) + if registration == "manager": litellm.logging_callback_manager.add_litellm_input_callback(async_callback) else: @@ -5344,6 +5346,8 @@ async def test_wrapper_async_skips_async_input_callback_on_cache_hit( def sync_callback(kwargs: dict) -> None: events.append("sync") + monkeypatch.setattr("litellm.litellm_core_utils.litellm_logging.customLogger", CustomLogger()) + monkeypatch.setattr(litellm, "_async_input_callback", [async_callback]) monkeypatch.setattr(litellm, "input_callback", [sync_callback]) monkeypatch.setattr(litellm, "cache", Cache(type="local"))