From 6830b63269df5cf4bdd4d0c53707f7097571b1d8 Mon Sep 17 00:00:00 2001 From: Sameer Kankute Date: Sat, 21 Mar 2026 20:44:52 +0530 Subject: [PATCH] =?UTF-8?q?Revert=20"fix(whisper):=20correct=20output=5Fco?= =?UTF-8?q?st=5Fper=5Fsecond=20pricing=20and=20cost=20calcula=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 00dd9844158c06da595a863c3c18552612068079. --- litellm/llms/openai/cost_calculation.py | 3 +- ...odel_prices_and_context_window_backup.json | 4 +- model_prices_and_context_window.json | 4 +- tests/test_litellm/test_cost_calculator.py | 52 ------------------- 4 files changed, 6 insertions(+), 57 deletions(-) diff --git a/litellm/llms/openai/cost_calculation.py b/litellm/llms/openai/cost_calculation.py index d5077e25a4..ac1e4a6b08 100644 --- a/litellm/llms/openai/cost_calculation.py +++ b/litellm/llms/openai/cost_calculation.py @@ -114,7 +114,7 @@ def cost_per_second( ) ## COST PER SECOND ## completion_cost = model_info["output_cost_per_second"] * duration - if ( + elif ( "input_cost_per_second" in model_info and model_info["input_cost_per_second"] is not None ): @@ -123,6 +123,7 @@ def cost_per_second( ) ## COST PER SECOND ## prompt_cost = model_info["input_cost_per_second"] * duration + completion_cost = 0.0 return prompt_cost, completion_cost diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index 595cdf3e13..879dd42be4 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -5725,7 +5725,7 @@ "input_cost_per_second": 0.0001, "litellm_provider": "azure", "mode": "audio_transcription", - "output_cost_per_second": 0.0 + "output_cost_per_second": 0.0001 }, "azure_ai/Cohere-embed-v3-english": { "input_cost_per_token": 1e-07, @@ -31996,7 +31996,7 @@ "input_cost_per_second": 0.0001, "litellm_provider": "openai", "mode": "audio_transcription", - "output_cost_per_second": 0.0, + "output_cost_per_second": 0.0001, "supported_endpoints": [ "/v1/audio/transcriptions" ] diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index c1ba4d88d4..bbf9f6d9dc 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -5725,7 +5725,7 @@ "input_cost_per_second": 0.0001, "litellm_provider": "azure", "mode": "audio_transcription", - "output_cost_per_second": 0.0 + "output_cost_per_second": 0.0001 }, "azure_ai/Cohere-embed-v3-english": { "input_cost_per_token": 1e-07, @@ -32000,7 +32000,7 @@ "input_cost_per_second": 0.0001, "litellm_provider": "openai", "mode": "audio_transcription", - "output_cost_per_second": 0.0, + "output_cost_per_second": 0.0001, "supported_endpoints": [ "/v1/audio/transcriptions" ] diff --git a/tests/test_litellm/test_cost_calculator.py b/tests/test_litellm/test_cost_calculator.py index 88c384bcae..8f5c3ece0c 100644 --- a/tests/test_litellm/test_cost_calculator.py +++ b/tests/test_litellm/test_cost_calculator.py @@ -1,6 +1,5 @@ import os import sys -from unittest.mock import patch import pytest @@ -17,7 +16,6 @@ from litellm.cost_calculator import ( handle_realtime_stream_cost_calculation, response_cost_calculator, ) -from litellm.llms.openai.cost_calculation import cost_per_second from litellm.types.llms.openai import OpenAIRealtimeStreamList from litellm.types.utils import ModelResponse, PromptTokensDetailsWrapper, Usage from litellm.utils import TranscriptionResponse @@ -1972,53 +1970,3 @@ def test_additional_costs_only_for_azure_ai(): completion_tokens=50, ) assert result is None, "Vertex AI should have no additional costs" - - -class TestCostPerSecondArithmetic: - """Unit tests for the cost_per_second arithmetic itself. - - The tests in TestCostCalculatorReadsDurationFromHiddenParams mock - openai_cost_per_second entirely — they verify that the right duration - is forwarded, but never that the math inside cost_per_second is correct. - These tests cover the arithmetic directly. - """ - - def test_input_cost_per_second_only(self): - """input_cost_per_second * duration = prompt_cost; completion_cost = 0.""" - with patch("litellm.llms.openai.cost_calculation.get_model_info") as mock_info: - mock_info.return_value = { - "input_cost_per_second": 0.0001, - "output_cost_per_second": 0.0, - } - prompt_cost, completion_cost_val = cost_per_second( - model="whisper-1", custom_llm_provider="openai", duration=60.0 - ) - assert prompt_cost == pytest.approx(0.006) - assert completion_cost_val == 0.0 - - def test_both_input_and_output_cost_per_second(self): - """When both fields are set, they are applied independently.""" - with patch("litellm.llms.openai.cost_calculation.get_model_info") as mock_info: - mock_info.return_value = { - "input_cost_per_second": 0.002, - "output_cost_per_second": 0.003, - } - prompt_cost, completion_cost_val = cost_per_second( - model="some-model", custom_llm_provider="openai", duration=10.0 - ) - assert prompt_cost == pytest.approx(0.02) - assert completion_cost_val == pytest.approx(0.03) - - def test_zero_duration_returns_zero_cost(self): - """A zero-duration transcription must cost nothing regardless of the rate.""" - with patch("litellm.llms.openai.cost_calculation.get_model_info") as mock_info: - mock_info.return_value = { - "input_cost_per_second": 0.0001, - "output_cost_per_second": 0.0, - } - prompt_cost, completion_cost_val = cost_per_second( - model="whisper-1", custom_llm_provider="openai", duration=0.0 - ) - assert prompt_cost == 0.0 - assert completion_cost_val == 0.0 -