From f0d41e4d1696951dfb18e2fa48e7d67be00faf76 Mon Sep 17 00:00:00 2001 From: Shivam Rawat Date: Sat, 4 Jul 2026 12:22:53 -0700 Subject: [PATCH] fix: attribute realtime transcription cost in cost breakdown Pass transcription_cost through additional_costs so cost_breakdown's input_cost + output_cost + additional_costs sums to total_cost instead of silently folding it into total_cost only. Co-authored-by: Cursor --- litellm/cost_calculator.py | 1 + tests/test_litellm/test_cost_calculator.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index 243060ee46e..2cb94e02d9c 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -2356,6 +2356,7 @@ def handle_realtime_stream_cost_calculation( completion_tokens_cost_usd_dollar=output_cost_per_token, cost_for_built_in_tools_cost_usd_dollar=0.0, total_cost_usd_dollar=total_cost, + additional_costs={"transcription_cost": transcription_cost} if transcription_cost > 0 else None, ) return total_cost diff --git a/tests/test_litellm/test_cost_calculator.py b/tests/test_litellm/test_cost_calculator.py index 41feec83a1c..0198a396b9b 100644 --- a/tests/test_litellm/test_cost_calculator.py +++ b/tests/test_litellm/test_cost_calculator.py @@ -695,6 +695,18 @@ def test_realtime_transcription_duration_cost(monkeypatch): assert logging_obj.cost_breakdown is not None assert abs(logging_obj.cost_breakdown["total_cost"] - cost) < 1e-9 + # The transcription cost must be attributed in the breakdown, not just folded + # into total_cost, or input_cost + output_cost + additional_costs won't sum to total_cost. + additional_costs = logging_obj.cost_breakdown.get("additional_costs") + assert additional_costs is not None + assert abs(additional_costs["transcription_cost"] - expected) < 1e-9 + attributed_total = ( + logging_obj.cost_breakdown["input_cost"] + + logging_obj.cost_breakdown["output_cost"] + + additional_costs["transcription_cost"] + ) + assert abs(attributed_total - logging_obj.cost_breakdown["total_cost"]) < 1e-9 + def test_realtime_transcription_duration_cost_resolves_model_from_litellm_name( monkeypatch,