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
test: cover _finalize_adaptive_router_if_configured
Krrish Dholakiaf0efc5f67085
diff --git a/tests/test_litellm/router_strategy/adaptive_router/test_router_dispatch.py b/tests/test_litellm/router_strategy/adaptive_router/test_router_dispatch.pyindex 7a67dac1a81..73cb66616ef 100644--- a/tests/test_litellm/router_strategy/adaptive_router/test_router_dispatch.py+++ b/tests/test_litellm/router_strategy/adaptive_router/test_router_dispatch.py@@ -378,3 +378,56 @@ def test_init_adaptive_router_rejects_duplicate_model_name():r.init_adaptive_router_deployment(deployment=deployment)with pytest.raises(ValueError, match="already exists"):r.init_adaptive_router_deployment(deployment=deployment)+++def test_finalize_adaptive_router_if_configured_initializes_and_is_idempotent():+ """`_finalize_adaptive_router_if_configured` walks the model_list, builds an+ AdaptiveRouter for each adaptive deployment, and is a safe no-op on+ re-entry (models already in self.adaptive_routers are skipped)."""+ r = Router(+ model_list=[+ {+ "model_name": "fast",+ "litellm_params": {"model": "openai/gpt-4o-mini"},+ "model_info": {"input_cost_per_token": 0.00000015},+ },+ {+ "model_name": "smart",+ "litellm_params": {"model": "openai/gpt-4o"},+ "model_info": {"input_cost_per_token": 0.0000025},+ },+ {+ "model_name": "my-router",+ "litellm_params": {+ "model": "auto_router/adaptive_router",+ "adaptive_router_config": {+ "available_models": ["fast", "smart"],+ },+ },+ },+ ]+ )++ # Router __init__ already called _finalize_adaptive_router_if_configured.+ assert "my-router" in r.adaptive_routers+ original = r.adaptive_routers["my-router"]++ # Calling again must be idempotent: the existing AdaptiveRouter instance+ # is preserved, not rebuilt.+ r._finalize_adaptive_router_if_configured()+ assert r.adaptive_routers["my-router"] is original+++def test_finalize_adaptive_router_if_configured_noop_when_none_configured():+ """With no adaptive deployments in model_list, the finalizer leaves+ `adaptive_routers` empty."""+ r = Router(+ model_list=[+ {+ "model_name": "fast",+ "litellm_params": {"model": "openai/gpt-4o-mini"},+ }+ ]+ )+ r._finalize_adaptive_router_if_configured()+ assert r.adaptive_routers == {}