From cd2672a448834a652198783907fcee2df5adac14 Mon Sep 17 00:00:00 2001 From: its-amann Date: Fri, 12 Jun 2026 17:34:25 +0530 Subject: [PATCH] Clarify tiered pricing helper comment --- litellm/litellm_core_utils/llm_cost_calc/utils.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/litellm/litellm_core_utils/llm_cost_calc/utils.py b/litellm/litellm_core_utils/llm_cost_calc/utils.py index 16b4d494dd9..018486cba41 100644 --- a/litellm/litellm_core_utils/llm_cost_calc/utils.py +++ b/litellm/litellm_core_utils/llm_cost_calc/utils.py @@ -612,10 +612,9 @@ def _apply_off_peak_to_base_costs( def _get_effective_prompt_tokens_for_tiered_pricing(usage: Usage) -> float: """Return the total effective input tokens for tier-threshold comparisons. - Some providers (Anthropic direct, Bedrock) roll cache_creation and cache_read - tokens into prompt_tokens before constructing the Usage object, while others - (Vertex AI) keep them separate. When prompt_tokens_details is present we can - derive the true total from its per-category fields and avoid double-counting. + Some providers report cache tokens inside prompt_tokens, while others keep + them separate. When prompt_tokens_details is present, prefer the category + fields so the threshold check can avoid double-counting cache tokens. """ if usage.prompt_tokens_details is not None: details = usage.prompt_tokens_details @@ -635,7 +634,7 @@ def _get_effective_prompt_tokens_for_tiered_pricing(usage: Usage) -> float: text_tokens = float(raw_text_tokens or 0) return text_tokens + cached_tokens + cache_creation - # No prompt_tokens_details — add explicit cache fields only if they are + # No prompt_tokens_details. Add explicit cache fields only if they are # not already rolled into prompt_tokens (determined by their presence). prompt_tokens = float(getattr(usage, "prompt_tokens", 0) or 0) cache_read_tokens = float(getattr(usage, "cache_read_input_tokens", 0) or 0)