mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-11 08:38:24 +00:00
Merge f0811a0165 into fbd126e518
This commit is contained in:
commit
a93d4c9bdd
3 changed files with 40 additions and 3 deletions
|
|
@ -920,7 +920,7 @@ def _declares_rates(model_info: ModelInfo | None) -> bool:
|
|||
return model_info is not None and cost_map_key_prices_anything(model_info["key"])
|
||||
|
||||
|
||||
def _base_model_pricing_provider(base_model: str, custom_llm_provider: str | None) -> str | None:
|
||||
def base_model_pricing_provider(base_model: str, custom_llm_provider: str | None) -> str | None:
|
||||
"""The provider to price an explicit base_model under, when the deployment's own provider has
|
||||
no rates for it (e.g. chatgpt/ subscription rows) but the base model's own row does"""
|
||||
if custom_llm_provider is None or _declares_rates(_cost_map_model_info(base_model, custom_llm_provider)):
|
||||
|
|
@ -1702,7 +1702,7 @@ def completion_cost(
|
|||
_configured_search_cost_per_query(litellm_logging_obj) if custom_pricing else None
|
||||
)
|
||||
base_model_provider: Final = (
|
||||
_base_model_pricing_provider(
|
||||
base_model_pricing_provider(
|
||||
base_model,
|
||||
_get_provider_for_cost_calc(
|
||||
model=model,
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ from litellm.constants import (
|
|||
from litellm.cost_calculator import (
|
||||
RealtimeAPITokenUsageProcessor,
|
||||
ResponsesWebSocketTokenUsageProcessor,
|
||||
base_model_pricing_provider,
|
||||
get_usage_object,
|
||||
pricing_entry_for_cost_calc,
|
||||
select_model_name_for_cost_calc,
|
||||
|
|
@ -6895,10 +6896,20 @@ class StandardLoggingPayloadSetup:
|
|||
if model_cost_name is None:
|
||||
model_cost_information = StandardLoggingModelInformation(model_map_key="", model_map_value=None)
|
||||
else:
|
||||
# When base_model points at a priced row under a different provider than the deployment's own
|
||||
# transport (e.g. a chatgpt/ subscription deployment priced via an openai/ base_model), completion_cost
|
||||
# already resolves the correct provider for billing. Without the same correction here, get_model_info
|
||||
# rejects the match on provider mismatch and this diagnostic field stays None even though spend is
|
||||
# computed correctly.
|
||||
pricing_provider: Final = (
|
||||
base_model_pricing_provider(base_model, custom_llm_provider)
|
||||
if base_model is not None and custom_pricing is not True
|
||||
else None
|
||||
)
|
||||
try:
|
||||
_model_cost_information: Final = litellm.get_model_info(
|
||||
model=pricing_model_name or model_cost_name,
|
||||
custom_llm_provider=custom_llm_provider,
|
||||
custom_llm_provider=pricing_provider or custom_llm_provider,
|
||||
api_base=api_base,
|
||||
)
|
||||
model_cost_information = StandardLoggingModelInformation(
|
||||
|
|
|
|||
|
|
@ -12506,6 +12506,32 @@ def test_get_model_cost_information_keeps_a_priced_response_model_that_echoes_wi
|
|||
assert result["model_map_value"]["input_cost_per_token"] == served_row["input_cost_per_token"]
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown")
|
||||
def test_get_model_cost_information_base_model_cross_provider():
|
||||
"""Regression test for #47908: a deployment whose transport provider differs from the priced
|
||||
base_model's own registered provider must still populate model_map_value, not just completion_cost's
|
||||
return value, since the two used to disagree (spend computed correctly, this field stayed None)."""
|
||||
litellm.register_model(
|
||||
model_cost={
|
||||
"custom-provider/base-model-cross-provider-test": {
|
||||
"input_cost_per_token": 1.5e-07,
|
||||
"output_cost_per_token": 5e-07,
|
||||
"litellm_provider": "custom-provider",
|
||||
"mode": "chat",
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
result = StandardLoggingPayloadSetup.get_model_cost_information(
|
||||
base_model="custom-provider/base-model-cross-provider-test",
|
||||
custom_pricing=False,
|
||||
custom_llm_provider="openai",
|
||||
init_response_obj={},
|
||||
)
|
||||
assert result["model_map_value"] is not None
|
||||
assert result["model_map_value"]["input_cost_per_token"] == 1.5e-07
|
||||
assert result["model_map_value"]["litellm_provider"] == "custom-provider"
|
||||
|
||||
@pytest.mark.usefixtures("_vcr_outcome_gate", "drain_logging_worker", "isolate_litellm_state", "setup_and_teardown")
|
||||
def test_standard_logging_payload_uses_deployment_when_no_base_model():
|
||||
"""metadata["deployment"] is used for cost-map lookup when base_model is not set."""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue