From 76c69bb933d5709e4007ea8685bb4c8cdadc53f2 Mon Sep 17 00:00:00 2001 From: Sameer Kankute Date: Fri, 17 Apr 2026 12:49:31 +0530 Subject: [PATCH] fix(proxy): avoid duplicate reasoning capability lookup Compute supports_reasoning once per non-wildcard health-check resolution path and update the stale default-max-tokens test docstring. Made-with: Cursor --- litellm/proxy/health_check.py | 14 ++++---------- .../proxy/test_health_check_max_tokens.py | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/litellm/proxy/health_check.py b/litellm/proxy/health_check.py index fbe056d41c..e0664703d2 100644 --- a/litellm/proxy/health_check.py +++ b/litellm/proxy/health_check.py @@ -328,25 +328,19 @@ def _resolve_health_check_max_tokens(model_info: dict, litellm_params: dict) -> deployment_model = _deployment_model_string_for_health_check(litellm_params) if not is_wildcard: + try: + is_reasoning = litellm.supports_reasoning(deployment_model) + except Exception: + is_reasoning = False tokens_reasoning = model_info.get("health_check_max_tokens_reasoning", None) tokens_non_reasoning = model_info.get( "health_check_max_tokens_non_reasoning", None ) if tokens_reasoning is not None or tokens_non_reasoning is not None: - try: - is_reasoning = litellm.supports_reasoning(deployment_model) - except Exception: - is_reasoning = False if is_reasoning and tokens_reasoning is not None: return int(tokens_reasoning) if not is_reasoning and tokens_non_reasoning is not None: return int(tokens_non_reasoning) - - if not is_wildcard: - try: - is_reasoning = litellm.supports_reasoning(deployment_model) - except Exception: - is_reasoning = False if ( is_reasoning and BACKGROUND_HEALTH_CHECK_MAX_TOKENS_REASONING is not None diff --git a/tests/test_litellm/proxy/test_health_check_max_tokens.py b/tests/test_litellm/proxy/test_health_check_max_tokens.py index d5011e51fe..09211b72c3 100644 --- a/tests/test_litellm/proxy/test_health_check_max_tokens.py +++ b/tests/test_litellm/proxy/test_health_check_max_tokens.py @@ -13,7 +13,7 @@ from litellm.proxy.health_check import ( @pytest.mark.asyncio async def test_update_litellm_params_max_tokens_default(monkeypatch): """ - Test that max_tokens defaults to 1 for non-wildcard models. + Test that max_tokens defaults to 5 for non-wildcard models. """ monkeypatch.setattr(hc_module, "BACKGROUND_HEALTH_CHECK_MAX_TOKENS", None) monkeypatch.setattr(hc_module, "BACKGROUND_HEALTH_CHECK_MAX_TOKENS_REASONING", None)