Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix: suppress misleading register_model unresolved-cost warnings for entries without custom pricing (#38542)

devin-ai-integration[bot]f864908cd70a
diff --git a/litellm/main.py b/litellm/main.py
index 8ee102f5d07..583c5b3f92a 100644
--- a/litellm/main.py
+++ b/litellm/main.py
@@ -1219,6 +1219,7 @@ def _register_custom_pricing_for_request(
shared_key: CustomPricingLiteLLMParams.strip_custom_pricing_fields(entry),
},
persist_across_reloads=False,
+ warning_display_name=shared_key,
)
diff --git a/litellm/router.py b/litellm/router.py
index 94a6498d490..021dafa9791 100644
--- a/litellm/router.py
+++ b/litellm/router.py
@@ -9216,7 +9216,11 @@ class Router:
}
if model_id is not None:
- litellm.register_model(model_cost={model_id: model_info}, persist_across_reloads=False)
+ litellm.register_model(
+ model_cost={model_id: model_info},
+ persist_across_reloads=False,
+ warning_display_name=model,
+ )
## OLD MODEL REGISTRATION ## Kept to prevent breaking changes
backend_keys: Final = Router._backend_cost_map_keys(model=model, custom_llm_provider=custom_llm_provider)
diff --git a/litellm/utils.py b/litellm/utils.py
index a26b2c5b440..b164a9c4671 100644
--- a/litellm/utils.py
+++ b/litellm/utils.py
@@ -2948,7 +2948,12 @@ def reapply_runtime_model_cost_registrations() -> None:
register_model(model_cost=dict(_runtime_registered_model_cost)) # mutable-ok: snapshot, replay rewrites it
-def register_model(model_cost: str | dict, *, persist_across_reloads: bool = True):
+def register_model(
+ model_cost: str | dict,
+ *,
+ persist_across_reloads: bool = True,
+ warning_display_name: str | None = None,
+):
"""
Register new / Override existing models (and their pricing) to specific providers.
Provide EITHER a model cost dictionary or a url to a hosted json blob
@@ -2968,6 +2973,10 @@ def register_model(model_cost: str | dict, *, persist_across_reloads: bool = Tru
registering a model is declaring durable intent. Pass False for a
registration that only describes one request, so it is dropped rather than
re-asserted over every future catalog.
+
+ ``warning_display_name`` names the model in the missing-cache-pricing
+ warning instead of the registered key, for callers that register under an
+ opaque key (e.g. the router's hashed deployment ids).
"""
loaded_model_cost = {}
@@ -3014,10 +3023,15 @@ def register_model(model_cost: str | dict, *, persist_across_reloads: bool = Tru
elif (
value.get("cache_creation_input_token_cost") is None
and value.get("cache_read_input_token_cost") is None
+ and value.get("tiered_pricing") is None
+ and (
+ value.get("input_cost_per_token") is not None
+ or value.get("output_cost_per_token") is not None
+ )
):
verbose_logger.warning(
- "register_model: model=%s not in built-in cost map and no prefix/region variant matched; cache cost fields will default to 0. To track cache cost, add cache_creation_input_token_cost and cache_read_input_token_cost to model_info",
- key,
+ "register_model: model=%s has custom pricing but not in built-in cost map and no prefix/region variant matched; cache_creation_input_token_cost and cache_read_input_token_cost will default to 0 for this model (input/output cost tracking is unaffected). To track cache cost, add them to model_info",
+ warning_display_name or key,
)
# ``get_model_info`` returns ``litellm_provider: None`` when the
# provider is unknown (e.g. custom deployments registered via
diff --git a/tests/test_litellm/test_register_model_custom_pricing.py b/tests/test_litellm/test_register_model_custom_pricing.py
index e3f6a1a0f40..39f498b4e58 100644
--- a/tests/test_litellm/test_register_model_custom_pricing.py
+++ b/tests/test_litellm/test_register_model_custom_pricing.py
@@ -435,6 +435,151 @@ def test_register_model_warns_when_no_builtin_match_for_cache_pricing(caplog):
litellm.model_cost.pop(registered_key, None)
+def test_register_model_no_warning_without_custom_pricing(caplog):
+ """LIT-6318: an entry with no custom pricing (e.g. router deployment
+ metadata) never drives cost calculation, so registering it under an
+ unmatched key must not emit the missing-cache-pricing warning.
+ """
+ import logging
+
+ from litellm._logging import verbose_logger
+
+ registered_key = "azure/lit6318-deployment-without-pricing"
+ litellm.model_cost.pop(registered_key, None)
+
+ try:
+ with caplog.at_level(logging.WARNING, logger=verbose_logger.name):
+ litellm.register_model(
+ {
+ registered_key: {
+ "litellm_provider": "azure",
+ "base_model": "azure/text-embedding-3-large",
+ }
+ }
+ )
+
+ assert not any("register_model" in record.message for record in caplog.records), (
+ "entry without custom pricing must register silently"
+ )
+ finally:
+ litellm.model_cost.pop(registered_key, None)
+
+
+def test_register_model_no_warning_for_tiered_pricing_without_cache_costs(caplog):
+ """LIT-6318: tiered pricing bills cache reads at the tier's input rate when
+ cache costs are omitted, so a tiered entry must not trigger the
+ cache-defaults-to-0 warning.
+ """
+ import logging
+
+ from litellm._logging import verbose_logger
+
+ registered_key = "bedrock/lit6318-tiered-priced-model"
+ litellm.model_cost.pop(registered_key, None)
+
+ try:
+ with caplog.at_level(logging.WARNING, logger=verbose_logger.name):
+ litellm.register_model(
+ {
+ registered_key: {
+ "litellm_provider": "bedrock",
+ "tiered_pricing": [
+ {
+ "range": [0, 200000],
+ "input_cost_per_token": 1e-06,
+ "output_cost_per_token": 5e-06,
+ }
+ ],
+ }
+ }
+ )
+
+ assert not any("register_model" in record.message for record in caplog.records), (
+ "tiered pricing entry must register silently"
+ )
+ finally:
+ litellm.model_cost.pop(registered_key, None)
+
+
+def test_router_deployment_without_custom_pricing_registers_silently(caplog):
+ """LIT-6318: the router registers every deployment under its hashed id and
+ its backend key. Deployments without custom pricing are costed at request
+ time from the underlying model name, so startup must not warn about them.
+ """
+ import logging
+
+ from litellm import Router
+ from litellm._logging import verbose_logger
+
+ deployment_model = "azure/lit6318-my-deployment-name"
+ deployment_id = "lit6318-no-pricing-deployment"
+ snapshot = _snapshot_model_cost_entries([deployment_model, deployment_id])
+
+ try:
+ with caplog.at_level(logging.WARNING, logger=verbose_logger.name):
+ Router(
+ model_list=[
+ {
+ "model_name": "indexing",
+ "litellm_params": {
+ "model": deployment_model,
+ "api_base": "https://example.openai.azure.com",
+ "api_key": "fake-key",
+ },
+ "model_info": {
+ "id": deployment_id,
+ "base_model": "azure/text-embedding-3-large",
+ },
+ }
+ ]
+ )
+
+ register_warnings = [record.message for record in caplog.records if "register_model" in record.message]
+ assert not register_warnings, register_warnings
+ finally:
+ _restore_model_cost_entries(snapshot)
+
+
+def test_router_custom_priced_deployment_warning_names_model_not_hash(caplog):
+ """LIT-6318: when a custom-priced deployment genuinely lacks cache pricing
+ and no built-in entry matches, the warning must name the deployment's
+ model rather than its opaque hashed id.
+ """
+ import logging
+
+ from litellm import Router
+ from litellm._logging import verbose_logger
+
+ deployment_model = "bedrock/lit6318-totally-made-up-model"
+ deployment_id = "lit6318-custom-priced-deployment-hash"
+ snapshot = _snapshot_model_cost_entries([deployment_model, deployment_id])
+
+ try:
+ with caplog.at_level(logging.WARNING, logger=verbose_logger.name):
+ Router(
+ model_list=[
+ {
+ "model_name": "made-up",
+ "litellm_params": {
+ "model": deployment_model,
+ "aws_region_name": "us-east-1",
+ "input_cost_per_token": 1e-06,
+ "output_cost_per_token": 5e-06,
+ },
+ "model_info": {"id": deployment_id},
+ }
+ ]
+ )
+
+ register_warnings = [record.message for record in caplog.records if "register_model" in record.message]
+ assert register_warnings, "expected a warning for missing cache pricing"
+ for message in register_warnings:
+ assert deployment_id not in message, message
+ assert deployment_model in message, message
+ finally:
+ _restore_model_cost_entries(snapshot)
+
+
def test_register_model_router_add_deployment_custom_pricing_applies():
"""End-to-end regression for https://github.com/BerriAI/litellm/issues/28336.