fix(auth): resolve zero-cost model aliases

Alias pricing resolves through its target model group, but explicit-cost validation searched under the alias name and enforced budgets on free models.\n\nFixes #35369
This commit is contained in:
Rithvik Mysore Suresh 2026-07-31 10:25:23 -04:00
parent 3c2264cfac
commit 136e09534a
2 changed files with 22 additions and 1 deletions

View file

@ -263,8 +263,9 @@ def _is_cost_explicitly_configured(model: str, llm_router: "Router") -> bool:
fields. _get_model_info_helper() then defaults missing costs to 0.
This function detects that scenario by checking the raw model_cost entry.
"""
resolved_model = llm_router._get_model_from_alias(model) or model
for deployment in llm_router.model_list:
if deployment.get("model_name") != model:
if deployment.get("model_name") != resolved_model:
continue
model_id = deployment.get("model_info", {}).get("id")
if model_id is None:

View file

@ -108,6 +108,26 @@ class TestIsModelCostZero:
)
assert result is True
@pytest.mark.parametrize(
"alias_target",
[
"on-prem-model",
{"model": "on-prem-model", "hidden": False},
],
)
def test_zero_cost_model_group_alias(
self, mock_router_with_zero_cost_model, alias_target
):
mock_router_with_zero_cost_model.model_group_alias = {
"free-alias": alias_target
}
result = _is_model_cost_zero(
model="free-alias", llm_router=mock_router_with_zero_cost_model
)
assert result is True
def test_paid_model_in_router(self, mock_router_with_zero_cost_model):
"""Test that a paid model is correctly identified as non-zero cost."""
with patch("litellm.get_model_info") as mock_get_model_info: