From b4ee6ef4f30ae53230a21651055c024c4fd322f3 Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Sun, 25 Oct 2026 02:20:53 +0000 Subject: [PATCH] fix(cost): stamp the billed cost over a reported usage.cost on streams The final streamed usage.cost a client sees is what the proxy billed, so an operator priced deployment shows its own rates instead of the upstream's number. Types region_name on cost_per_token. --- litellm/cost_calculator.py | 4 ++-- litellm/litellm_core_utils/streaming_chunk_builder_utils.py | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index 6ec8d00e37f..cacf130aeab 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -427,7 +427,7 @@ def cost_per_token( completion_tokens: int = 0, response_time_ms: float | None = 0.0, custom_llm_provider: str | None = None, - region_name=None, + region_name: str | None = None, ### CHARACTER PRICING ### prompt_characters: int | None = None, completion_characters: int | None = None, @@ -508,7 +508,7 @@ def _cost_per_token_from_rates( completion_tokens: int = 0, response_time_ms: float | None = 0.0, custom_llm_provider: str | None = None, - region_name=None, + region_name: str | None = None, ### CHARACTER PRICING ### prompt_characters: int | None = None, completion_characters: int | None = None, diff --git a/litellm/litellm_core_utils/streaming_chunk_builder_utils.py b/litellm/litellm_core_utils/streaming_chunk_builder_utils.py index 4cdb9004619..3a5a2cbe914 100644 --- a/litellm/litellm_core_utils/streaming_chunk_builder_utils.py +++ b/litellm/litellm_core_utils/streaming_chunk_builder_utils.py @@ -1413,8 +1413,6 @@ def _set_stream_builder_response_cost( def _stamp_streaming_usage_cost(usage: Usage, response: ModelResponse, logging_obj: Optional["Logging"]) -> None: if logging_obj is None: return - if isinstance(getattr(usage, "cost", None), (int, float)): - return computed_cost: Final = logging_obj.response_cost_calculator(result=response) if not isinstance(computed_cost, (int, float)) or computed_cost <= 0: return