From a70414d646439c2b4a84657d94f22f07bed3ec61 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Wed, 18 Feb 2026 15:14:02 -0800 Subject: [PATCH] fix: guard calculate_total_usage against None usage in chunks --- litellm/litellm_core_utils/streaming_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/litellm_core_utils/streaming_handler.py b/litellm/litellm_core_utils/streaming_handler.py index 14f332dfcaf..73d3e6bb629 100644 --- a/litellm/litellm_core_utils/streaming_handler.py +++ b/litellm/litellm_core_utils/streaming_handler.py @@ -2193,7 +2193,7 @@ def calculate_total_usage(chunks: List[ModelResponse]) -> Usage: prompt_tokens: int = 0 completion_tokens: int = 0 for chunk in chunks: - if "usage" in chunk: + if "usage" in chunk and chunk["usage"] is not None: if "prompt_tokens" in chunk["usage"]: prompt_tokens = chunk["usage"].get("prompt_tokens", 0) or 0 if "completion_tokens" in chunk["usage"]: