From ab3f12410e4a2b57d6e193432d1bb0c184b9ee45 Mon Sep 17 00:00:00 2001 From: soroush5 Date: Thu, 3 Sep 2026 23:24:25 +0330 Subject: [PATCH] fix(cost): avoid parameter reassignment in token coercion --- litellm/cost_calculator.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index 0be166310e0..64fc255d6d3 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -378,17 +378,17 @@ def cost_per_token( if model is None: raise Exception("Invalid arg. Model cannot be none.") - prompt_tokens = _coerce_token_count(prompt_tokens) - completion_tokens = _coerce_token_count(completion_tokens) + coerced_prompt_tokens = _coerce_token_count(prompt_tokens) + coerced_completion_tokens = _coerce_token_count(completion_tokens) ## RECONSTRUCT USAGE BLOCK ## if usage_object is not None: usage_block = usage_object else: usage_block = Usage( - prompt_tokens=prompt_tokens, - completion_tokens=completion_tokens, - total_tokens=prompt_tokens + completion_tokens, + prompt_tokens=coerced_prompt_tokens, + completion_tokens=coerced_completion_tokens, + total_tokens=coerced_prompt_tokens + coerced_completion_tokens, cache_creation_input_tokens=cache_creation_input_tokens, cache_read_input_tokens=cache_read_input_tokens, )