From 05cdcf13881d7a4ccad159762bb9fe6f90e8a71a Mon Sep 17 00:00:00 2001 From: Mike Hummel Date: Wed, 2 Sep 2026 16:42:26 +0200 Subject: [PATCH] fix(streaming): do not adopt a provider-reported cost when coercing usage --- litellm/litellm_core_utils/streaming_handler.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/litellm/litellm_core_utils/streaming_handler.py b/litellm/litellm_core_utils/streaming_handler.py index e8299d0e3a5..846b8ddce57 100644 --- a/litellm/litellm_core_utils/streaming_handler.py +++ b/litellm/litellm_core_utils/streaming_handler.py @@ -1670,7 +1670,16 @@ class CustomStreamWrapper: if not isinstance(usage_from_chunk, Usage) and hasattr( usage_from_chunk, "model_dump" ): - usage_from_chunk = Usage(**usage_from_chunk.model_dump()) + usage_fields = usage_from_chunk.model_dump() + # Do NOT adopt a provider-reported cost. `cost` IS a declared + # field on litellm Usage and cost tracking bills it as the + # response cost, but providers report it in their own unit -- + # one gateway sends an integer that is neither dollars nor + # cents, and adopting it recorded 555533 for a request that + # costs 0.008. Only the token fields are coerced here. + usage_fields.pop("cost", None) + usage_fields.pop("cost_details", None) + usage_from_chunk = Usage(**usage_fields) model_response.usage = usage_from_chunk ## RETURN ARG