litellm/tests/unit/test_elevenlabs_tts_pricing.py
devin-ai-integration[bot] f3d53a9b50
fix(cost-map): rolling registry audit, add elevenlabs api rates, together minimax-m3.1-flash, mistral voxtral 3 and azure_ai phi-4 dates (#47623)
* fix(cost-map): add mistral voxtral 3 transcription and tts rows

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(cost-map): add azure_ai phi-4 family retirement dates

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(cost-map): add elevenlabs v4 and flash/turbo tts rows at API rates and together minimax-m3.1-flash

Co-authored-by: Shebin Sabu <85486313+shebin09@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* chore(cost-map): credit elevenlabs api pricing from #47917

Co-authored-by: Shebin Sabu <85486313+shebin09@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Shebin Sabu <85486313+shebin09@users.noreply.github.com>
2026-10-23 14:57:35 -07:00

49 lines
1.8 KiB
Python

"""ElevenLabs text-to-speech prices match the published API rates.
https://elevenlabs.io/pricing/api lists "v3" and "v2 Multilingual" at $0.08 and
"Flash / Turbo" at $0.04, each "Price per 1K characters", and says API usage is
billed in US dollars, not credits. The map had v3 and Multilingual v2 at a
Scale-plan credit estimate ($0.18 per 1K characters) and no Flash rows.
"""
import json
from pathlib import Path
import pytest
import litellm
REPO_ROOT = Path(__file__).parents[2]
PRICES = {
"elevenlabs/eleven_v3": 8e-05,
"elevenlabs/eleven_multilingual_v2": 8e-05,
"elevenlabs/eleven_flash_v2_5": 4e-05,
"elevenlabs/eleven_flash_v2": 4e-05,
}
@pytest.fixture(autouse=True)
def local_model_cost_map(monkeypatch):
"""Never depend on the published cost map having these rows yet."""
monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True")
monkeypatch.setattr(litellm, "model_cost", litellm.get_model_cost_map(url=""))
litellm.get_model_info.cache_clear()
yield
litellm.get_model_info.cache_clear()
@pytest.mark.parametrize("model, per_character", PRICES.items())
def test_metadata_and_backup(model, per_character):
main = json.loads((REPO_ROOT / "model_prices_and_context_window.json").read_text())
backup = json.loads((REPO_ROOT / "litellm/model_prices_and_context_window_backup.json").read_text())
assert main[model] == backup[model]
info = litellm.get_model_info(model)
assert info["litellm_provider"] == "elevenlabs"
assert info["mode"] == "audio_speech"
assert info["input_cost_per_character"] == per_character
@pytest.mark.parametrize("model, per_character", PRICES.items())
def test_speech_cost_is_charged_per_character(model, per_character):
cost = litellm.completion_cost(model=model, call_type="speech", prompt="x" * 1000)
assert cost == pytest.approx(per_character * 1000)