From c316e86585360a4f259e9af7f75c16da693f44cd 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 5baa28e7f76..610869374e0 100644 --- a/litellm/litellm_core_utils/streaming_handler.py +++ b/litellm/litellm_core_utils/streaming_handler.py @@ -2163,7 +2163,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"]: