The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix: attribute realtime transcription cost in cost breakdown
Shivam Rawatf0d41e4d1696
diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.pyindex 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_costdiff --git a/tests/test_litellm/test_cost_calculator.py b/tests/test_litellm/test_cost_calculator.pyindex 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 Noneassert 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,