From 84c507bc145a71b377a41807bc888183e91a0609 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Tue, 14 Apr 2026 19:03:56 -0700 Subject: [PATCH] fix(mypy): use explicit None check for cache rate values to satisfy type checker --- litellm/cost_calculator.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index bd5fe65ff2d..fbabad27d50 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -1611,10 +1611,12 @@ def completion_cost( # noqa: PLR0915 if (_cr or _cc) and model: try: _mi = litellm.get_model_info(model=model, custom_llm_provider=custom_llm_provider) - if _cr and _mi.get("cache_read_input_token_cost"): - _cache_read_cost = float(_cr) * float(_mi["cache_read_input_token_cost"]) - if _cc and _mi.get("cache_creation_input_token_cost"): - _cache_creation_cost = float(_cc) * float(_mi["cache_creation_input_token_cost"]) + _cr_rate = _mi.get("cache_read_input_token_cost") + if _cr and _cr_rate is not None: + _cache_read_cost = float(_cr) * float(_cr_rate) + _cc_rate = _mi.get("cache_creation_input_token_cost") + if _cc and _cc_rate is not None: + _cache_creation_cost = float(_cc) * float(_cc_rate) except Exception: pass _store_cost_breakdown_in_logging_obj(