diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 606a590c24b..8f55838f2d4 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -13561,7 +13561,7 @@ def _enrich_model_info_with_litellm_data( except Exception: litellm_model_info = {} for k, v in litellm_model_info.items(): - if k not in model_info: + if model_info.get(k) is None: model_info[k] = v model["model_info"] = model_info # don't return the api key / vertex credentials @@ -15027,7 +15027,7 @@ def _get_proxy_model_info(model: dict) -> dict: except Exception: litellm_model_info = {} for k, v in litellm_model_info.items(): - if k not in model_info: + if model_info.get(k) is None: model_info[k] = v model["model_info"] = model_info # don't return the llm credentials diff --git a/tests/test_litellm/proxy/proxy_server/test_routes_model_info.py b/tests/test_litellm/proxy/proxy_server/test_routes_model_info.py index 4c141bcf698..60dcd3b72bc 100644 --- a/tests/test_litellm/proxy/proxy_server/test_routes_model_info.py +++ b/tests/test_litellm/proxy/proxy_server/test_routes_model_info.py @@ -541,3 +541,56 @@ def test_v2_model_info_access_group_paginates_over_the_filtered_set(client, auth assert _model_names(payload) == ["openai/*"] assert payload["total_count"] == 2 assert payload["total_pages"] == 2 + + +def test_enrich_model_info_with_litellm_data_populates_none_keys(monkeypatch): + monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True") + from litellm.proxy._types import ModelInfo as ProxyModelInfo + from litellm.proxy.proxy_server import _enrich_model_info_with_litellm_data + + backend = "bedrock/eu.anthropic.claude-opus-5" + p_model_info = ProxyModelInfo(id="d1").model_dump() + model = {"model_name": "m", "litellm_params": {"model": backend}, "model_info": dict(p_model_info)} + + enriched = _enrich_model_info_with_litellm_data(model=model, llm_router=None) + mi = enriched["model_info"] + assert mi.get("input_cost_per_token") == 5.5e-06 + assert mi.get("max_tokens") == 128000 + assert mi.get("mode") == "chat" + + +def test_get_proxy_model_info_populates_none_keys(monkeypatch): + monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True") + from litellm.proxy._types import ModelInfo as ProxyModelInfo + from litellm.proxy.proxy_server import _get_proxy_model_info + + backend = "bedrock/eu.anthropic.claude-opus-5" + p_model_info = ProxyModelInfo(id="d1").model_dump() + fresh_model = {"model_name": "m", "litellm_params": {"model": backend}, "model_info": dict(p_model_info)} + + proxy_info = _get_proxy_model_info(model=fresh_model) + p_mi = proxy_info["model_info"] + assert p_mi.get("input_cost_per_token") == 5.5e-06 + assert p_mi.get("max_tokens") == 128000 + assert p_mi.get("mode") == "chat" + + +def test_enrich_model_info_with_litellm_data_preserves_custom_pricing(monkeypatch): + monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True") + from litellm.proxy._types import ModelInfo as ProxyModelInfo + from litellm.proxy.proxy_server import _enrich_model_info_with_litellm_data, _get_proxy_model_info + + backend = "bedrock/eu.anthropic.claude-opus-5" + custom_model_info = ProxyModelInfo(id="d1", input_cost_per_token=0.00099).model_dump() + model = {"model_name": "m", "litellm_params": {"model": backend}, "model_info": dict(custom_model_info)} + + enriched = _enrich_model_info_with_litellm_data(model=model, llm_router=None) + mi = enriched["model_info"] + assert mi.get("input_cost_per_token") == 0.00099 + assert mi.get("max_tokens") == 128000 + + fresh_custom_model = {"model_name": "m", "litellm_params": {"model": backend}, "model_info": dict(custom_model_info)} + proxy_info = _get_proxy_model_info(model=fresh_custom_model) + p_mi = proxy_info["model_info"] + assert p_mi.get("input_cost_per_token") == 0.00099 +