From 1eb49115cf29e11db74df063b8429c967815b889 Mon Sep 17 00:00:00 2001 From: Filippo Mattia Menghi Date: Wed, 10 Jun 2026 10:58:58 +0200 Subject: [PATCH] fix(cost): read litellm.model_cost once in _model_has_known_pricing The cost-map reload path can swap the litellm.model_cost dict between loop iterations; binding it to a local first makes both key lookups observe the same snapshot --- litellm/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/litellm/main.py b/litellm/main.py index 39c6f3b4c24..42e22dadd7f 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -1097,8 +1097,9 @@ def _model_has_known_pricing(model: str, custom_llm_provider: str) -> bool: pricing dimensions checked here); registration is only needed so unknown models can be priced at all. """ + model_cost_map = litellm.model_cost for key in (model, f"{custom_llm_provider}/{model}"): - entry = litellm.model_cost.get(key) + entry = model_cost_map.get(key) if entry is not None and ( entry.get("input_cost_per_token") is not None or entry.get("input_cost_per_second") is not None