mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-15 09:12:18 +00:00
test(cost-calc): cover region_name with a custom-priced router model id
_select_model_name_for_cost_calc must price a custom-priced router
deployment on the id its price was registered under, even when the
response carries a region_name. c11a1f0bc1 ("scope region_name to
response-derived model names") makes that hold via the explicit_pricing
gate, but nothing pins the custom_pricing + router_model_id + region
combination: test_custom_pricing_cost_calc_uses_router_model_id_from_
litellm_metadata exercises that path with completion_response=None, so
no region is ever in play.
The response here echoes a model and carries a region, so
priced_from_response is True and explicit_pricing alone suppresses the
region -- the guard this test exists to hold.
Test-only; no production change.
This commit is contained in:
parent
c79c73f859
commit
337f09cb1c
1 changed files with 41 additions and 0 deletions
|
|
@ -4327,6 +4327,47 @@ def test_select_model_name_keeps_base_model_free_of_region(_local_model_cost_map
|
|||
assert selected == "bedrock/moonshotai.kimi-k2.5"
|
||||
|
||||
|
||||
def test_select_model_name_keeps_custom_priced_router_id_free_of_region(_local_model_cost_map):
|
||||
"""A custom-priced router deployment prices on the id its custom price was registered under, so a
|
||||
region carried on the response must not widen the key to a regional one that was never registered."""
|
||||
|
||||
from litellm.cost_calculator import _select_model_name_for_cost_calc
|
||||
|
||||
custom_model_id = "claude-sonnet-4-custom-region-test"
|
||||
litellm.register_model(
|
||||
model_cost={
|
||||
custom_model_id: {
|
||||
"input_cost_per_token": 0.0003,
|
||||
"output_cost_per_token": 0.0015,
|
||||
"max_tokens": 8192,
|
||||
"litellm_provider": "anthropic",
|
||||
}
|
||||
}
|
||||
)
|
||||
response = litellm.ModelResponse(
|
||||
id="x",
|
||||
choices=[
|
||||
{
|
||||
"index": 0,
|
||||
"message": {"role": "assistant", "content": "hi"},
|
||||
"finish_reason": "stop",
|
||||
}
|
||||
],
|
||||
model="claude-sonnet-4-20250514",
|
||||
)
|
||||
response._hidden_params = {"region_name": "us-east-1"}
|
||||
|
||||
selected = _select_model_name_for_cost_calc(
|
||||
model="anthropic/claude-sonnet-4-20250514",
|
||||
completion_response=response,
|
||||
custom_pricing=True,
|
||||
custom_llm_provider="anthropic",
|
||||
router_model_id=custom_model_id,
|
||||
)
|
||||
|
||||
assert selected == f"anthropic/{custom_model_id}"
|
||||
|
||||
|
||||
def test_completion_cost_nonzero_for_slash_alias_model_name(_local_model_cost_map):
|
||||
"""End-to-end cost through a "/"-containing alias must price above zero (#38069)."""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue