diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index 369774090ef..891565c6481 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -1845,7 +1845,7 @@ def completion_cost( ) elif call_type in _SPEECH_CALL_TYPES: prompt_characters = ( - len(prompt.strip()) + len(prompt) if custom_llm_provider == LlmProviders.ELEVENLABS.value else litellm.utils.count_characters(text=prompt) ) diff --git a/tests/unit/test_cost_calculator.py b/tests/unit/test_cost_calculator.py index 418096fadaf..dfe236ae237 100644 --- a/tests/unit/test_cost_calculator.py +++ b/tests/unit/test_cost_calculator.py @@ -9134,7 +9134,7 @@ def test_azure_tts_cost_uses_test_owned_character_rate(monkeypatch: pytest.Monke assert cost == pytest.approx(0.05) -def test_elevenlabs_tts_cost_counts_the_spaces_between_words(monkeypatch: pytest.MonkeyPatch) -> None: +def test_elevenlabs_tts_cost_counts_every_whitespace_character(monkeypatch: pytest.MonkeyPatch) -> None: model: Final = "litellm-test-tts" monkeypatch.setitem( litellm.model_cost, @@ -9146,7 +9146,7 @@ def test_elevenlabs_tts_cost_counts_the_spaces_between_words(monkeypatch: pytest "mode": "audio_speech", }, ) - spoken: Final = "hello there, world" + prompt: Final = " hello there, world\n" cost: Final = response_cost_calculator( response_object=TranscriptionResponse(text=""), @@ -9154,10 +9154,10 @@ def test_elevenlabs_tts_cost_counts_the_spaces_between_words(monkeypatch: pytest custom_llm_provider="elevenlabs", call_type="aspeech", optional_params={}, - prompt=f" {spoken}\n", + prompt=prompt, ) - assert cost == pytest.approx(len(spoken) * 0.01) + assert cost == pytest.approx(len(prompt) * 0.01) def test_moderation_cost_uses_test_owned_token_rate() -> None: