test(cost_calculator): use synthetic model_cost entry for bare base_model test

Replace the assertion that pinned the built-in cost map's contents
(hosted_vllm/gpt-3.5-turbo absent) with a synthetic registered entry, so the
test fails only on behavior changes, not on future cost-map updates.
This commit is contained in:
pratik 2026-09-18 17:01:49 +05:30
parent 1e181767ce
commit e3a09a1706

View file

@ -3563,7 +3563,8 @@ def test_completion_cost_base_model_cross_provider_prefix(_local_model_cost_map)
def test_completion_cost_base_model_bare_name_kept_when_prefix_unregistered(_local_model_cost_map):
"""A bare base_model whose deployment-prefixed form is not a registered cost key is priced
from the base model's own registered key instead of being prefixed into an unresolvable
name and recording $0 spend (#41780)."""
name and recording $0 spend (#41780). Uses a synthetic cost-map entry so the assertion
depends only on registered pricing, not on the built-in map's contents."""
response = litellm.ModelResponse(
id="x",
@ -3572,14 +3573,22 @@ def test_completion_cost_base_model_bare_name_kept_when_prefix_unregistered(_loc
usage={"prompt_tokens": 1000, "completion_tokens": 100, "total_tokens": 1100},
)
response._hidden_params = {"custom_llm_provider": "hosted_vllm"}
assert "hosted_vllm/gpt-3.5-turbo" not in litellm.model_cost
entry = litellm.model_cost["gpt-3.5-turbo"]
litellm.register_model(
model_cost={
"openrouter/synthetic-base-model": {
"input_cost_per_token": 2e-6,
"output_cost_per_token": 4e-6,
"litellm_provider": "openrouter",
}
}
)
entry = litellm.model_cost["openrouter/synthetic-base-model"]
cost = litellm.completion_cost(
completion_response=response,
model="custom-model",
custom_llm_provider="hosted_vllm",
base_model="gpt-3.5-turbo",
base_model="openrouter/synthetic-base-model",
)
assert cost == pytest.approx(1000 * entry["input_cost_per_token"] + 100 * entry["output_cost_per_token"])