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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(cost-map): keep register_model url fetch to a single attempt
kerry536a85b42967
diff --git a/litellm/utils.py b/litellm/utils.pyindex 36b48d3b8d8..8df28870544 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -3079,7 +3079,7 @@ def register_model(# Convert stringified numbers to appropriate numeric typesloaded_model_cost = model_costelif isinstance(model_cost, str):- loaded_model_cost = litellm.get_model_cost_map(url=model_cost)+ loaded_model_cost = litellm.get_model_cost_map(url=model_cost, max_attempts=1)if persist_across_reloads:_registrations: Final[Mapping[str, Mapping[str, object]]] = loaded_model_costdiff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.pyindex fee5e3a2e4c..e90372141bd 100644--- a/tests/test_litellm/test_utils.py+++ b/tests/test_litellm/test_utils.py@@ -2,10 +2,12 @@ import asyncioimport jsonimport loggingimport os+import threadingfrom datetime import datetime, timedelta, timezonefrom typing import Finalfrom unittest.mock import AsyncMock, MagicMock, patch+import httpximport pytestimport respxfrom jsonschema import validate@@ -2382,6 +2384,27 @@ def test_register_model_with_scientific_notation():_invalidate_model_cost_lowercase_map()+def test_register_model_url_fetch_uses_single_attempt(monkeypatch):+ monkeypatch.setattr(litellm, "model_cost", dict(litellm.model_cost))+ before = dict(litellm.model_cost)+ threads_before = {thread.name for thread in threading.enumerate()}+ route = respx.get("https://example.invalid/custom_pricing.json").mock(+ return_value=httpx.Response(503)+ )++ litellm.register_model(model_cost="https://example.invalid/custom_pricing.json")++ threads_after = {thread.name for thread in threading.enumerate()}+ assert route.call_count == 1+ assert not (threads_after - threads_before) & {"litellm-model-cost-map-retry"}+ assert not any(+ thread.name == "litellm-model-cost-map-retry" and thread.is_alive()+ for thread in threading.enumerate()+ )+ assert litellm.model_cost.keys() >= before.keys()++def test_register_model_openrouter_without_slash():"""Test that register_model handles openrouter models without '/' in the name.