From 26a2704010d6d149a6a1c7252fd8395be68f7bb0 Mon Sep 17 00:00:00 2001 From: milan Date: Thu, 23 Jul 2026 20:11:35 +0000 Subject: [PATCH] perf(cost): short-circuit above-threshold key discovery with cheap substring pre-filter Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/litellm_core_utils/llm_cost_calc/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/litellm/litellm_core_utils/llm_cost_calc/utils.py b/litellm/litellm_core_utils/llm_cost_calc/utils.py index ebe9df3a44e..ce0c8285221 100644 --- a/litellm/litellm_core_utils/llm_cost_calc/utils.py +++ b/litellm/litellm_core_utils/llm_cost_calc/utils.py @@ -248,10 +248,11 @@ def _get_token_base_cost( threshold_keys = [ k for k in model_info - if k.startswith(_ABOVE_THRESHOLD_KEY_PREFIXES) + if "_above_" in k and k.endswith("_tokens") and "_above_1hr" not in k and not k.endswith(_SERVICE_TIER_SUFFIXES) + and k.startswith(_ABOVE_THRESHOLD_KEY_PREFIXES) ] if not threshold_keys: return (