From 19c9bb5c17b6a5ae94589a3dae50a2d1998a7ebf Mon Sep 17 00:00:00 2001 From: Alexsander Hamir Date: Wed, 14 Jan 2026 11:46:04 -0800 Subject: [PATCH] fix: restore defensive behavior for unknown usage types - Restore original defensive behavior: return Usage(0,0,0) for unknown types instead of raising ValueError - Keep explicit ResponseAPIUsage handling to fix the bug where it was incorrectly returning 0 tokens - Maintain backward compatibility by preserving original error handling approach --- litellm/litellm_core_utils/litellm_logging.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index bf47619d5ae..3a099aeca73 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -4525,8 +4525,13 @@ class StandardLoggingPayloadSetup: ) elif isinstance(usage, dict): return Usage(**usage) - - raise ValueError(f"usage is required, got={usage} of type {type(usage)}") + else: + # Unknown type - return 0 tokens (defensive behavior) + return Usage( + prompt_tokens=0, + completion_tokens=0, + total_tokens=0, + ) @staticmethod def get_model_cost_information(