From ff3b5135cb83cf87bf06bf0b10ef74d20b310421 Mon Sep 17 00:00:00 2001 From: Yuneng Jiang Date: Wed, 8 Apr 2026 10:23:04 -0700 Subject: [PATCH] Use dict spread instead of in-place mutation in _normalize_usage_cache_tokens Avoids mutating the caller's response_obj["usage"] dict as a side effect. --- litellm/litellm_core_utils/litellm_logging.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index 01275922c07..8acb321796e 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -4920,13 +4920,13 @@ class StandardLoggingPayloadSetup: cached = getattr(prompt_details, "cached_tokens", None) creation = getattr(prompt_details, "cache_creation_tokens", None) + extra: dict = {} if cached and not usage_dict.get("cache_read_input_tokens"): - usage_dict["cache_read_input_tokens"] = cached - + extra["cache_read_input_tokens"] = cached if creation and not usage_dict.get("cache_creation_input_tokens"): - usage_dict["cache_creation_input_tokens"] = creation + extra["cache_creation_input_tokens"] = creation - return usage_dict + return {**usage_dict, **extra} if extra else usage_dict @staticmethod def get_model_cost_information(