litellm/tests/unit/rust_bridge/host/test_model_cost.py
Kerry Lu 8abcd13a9d
fix(cost): keep a deployment's per-second video price over the catalog row's flat price (#51688)
* fix(cost): keep a deployment's per-second video price over the catalog row's flat price

* fix(cost): drop the superseded flat video price from the registration kept for reloads

* test(cost): derive the per-second rate from the catalog row so the regression holds at any vendor price

* fix(cost): keep the flat video price when only a resolution tier is priced per second

* test(integration): assert the body sent to fal in the per-second price test

---------

Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Nate Armstrong <narmstrong@berri.ai>
2026-11-15 12:04:41 -08:00

39 lines
1.6 KiB
Python

from typing import Final
import pytest
import litellm
from litellm.litellm_core_utils.model_cost_table import AliasedCostEntry
from litellm.rust_bridge.host.model_cost import kept, merged, resolve
pytestmark = pytest.mark.usefixtures("local_model_cost_map")
def test_resolve_lands_on_the_row_a_lookup_in_the_published_table_resolves() -> None:
landing: Final = resolve(litellm.model_cost, "openai/gpt-4o", {"input_cost_per_token": 1.0}, None)
assert landing is not None
assert (landing.key, landing.matched_builtin) == ("gpt-4o", True)
def test_merged_keeps_the_alias_names_and_adds_only_the_fields_a_registration_set() -> None:
current: Final = AliasedCostEntry({"mode": "chat", "x": 1}, ("owner", "alias"), frozenset({"mode"}))
row: Final = merged(current, {"x": 2}, {"litellm_provider": "openai", "output_cost_per_token": None})
assert row == {"mode": "chat", "x": 2, "litellm_provider": "openai"}
assert (row.names, row.registered_fields) == (("owner", "alias"), frozenset({"mode", "litellm_provider"}))
def test_kept_registration_drops_the_flat_video_price_a_later_per_second_price_replaced() -> None:
replayed: Final = kept({"mode": "video_generation", "output_cost_per_video": 0.37}, {"output_cost_per_second": 0.1})
assert replayed == {"mode": "video_generation", "output_cost_per_second": 0.1}
def test_kept_registration_keeps_a_flat_video_price_registered_beside_a_per_second_price() -> None:
replayed: Final = kept(
{"output_cost_per_video": 0.37}, {"output_cost_per_video": 0.4, "output_cost_per_second": 0.1}
)
assert replayed == {"output_cost_per_video": 0.4, "output_cost_per_second": 0.1}