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 public model hub not showing config-defined models after save
yuneng-jiangb7c43d948e02
diff --git a/litellm/proxy/management_endpoints/model_management_endpoints.py b/litellm/proxy/management_endpoints/model_management_endpoints.pyindex 248b34c3dfc..cd7e3d15402 100644--- a/litellm/proxy/management_endpoints/model_management_endpoints.py+++ b/litellm/proxy/management_endpoints/model_management_endpoints.py@@ -1186,9 +1186,8 @@ async def update_public_model_groups(},)- litellm.public_model_groups = request.model_groups-- # Load existing config+ # Load existing config first (this may overwrite in-memory litellm settings+ # from DB values via _update_config_from_db), so set the in-memory value AFTERconfig = await proxy_config.get_config()# Update config with new settings@@ -1200,6 +1199,10 @@ async def update_public_model_groups(# Save the updated configawait proxy_config.save_config(new_config=config)+ # Set in-memory value AFTER get_config() and save_config() to avoid+ # get_config() overwriting with stale DB value+ litellm.public_model_groups = request.model_groups+verbose_proxy_logger.debug(f"Updated public model groups to: {request.model_groups} by user: {user_api_key_dict.user_id}")diff --git a/tests/test_litellm/proxy/management_endpoints/test_model_management_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_model_management_endpoints.pyindex e70bc57e59b..d669c878d04 100644--- a/tests/test_litellm/proxy/management_endpoints/test_model_management_endpoints.py+++ b/tests/test_litellm/proxy/management_endpoints/test_model_management_endpoints.py@@ -453,6 +453,64 @@ class TestClearCache:)+class TestUpdatePublicModelGroups:+ """Test that update_public_model_groups correctly sets litellm.public_model_groups+ even when get_config() overwrites it with stale DB values."""++ @pytest.mark.asyncio+ async def test_public_model_groups_set_after_get_config(self):+ """+ Regression test: get_config() internally calls _update_config_from_db which+ sets litellm.public_model_groups to the old DB value. The endpoint must set+ the in-memory value AFTER get_config() so the new value is not overwritten.+ """+ import litellm+ from litellm.proxy.management_endpoints.model_management_endpoints import (+ update_public_model_groups,+ UpdatePublicModelGroupsRequest,+ )++ old_db_models = ["db-model-1", "db-model-2"]+ new_models = ["db-model-1", "db-model-2", "config-model-1", "config-model-2"]++ # Simulate get_config() overwriting litellm.public_model_groups with old DB value+ async def mock_get_config(*args, **kwargs):+ # This simulates _update_config_from_db calling setattr(litellm, "public_model_groups", old_value)+ litellm.public_model_groups = old_db_models+ return {"litellm_settings": {"public_model_groups": old_db_models}}++ mock_proxy_config = MagicMock()+ mock_proxy_config.get_config = mock_get_config+ mock_proxy_config.save_config = AsyncMock()++ admin_user = UserAPIKeyAuth(+ user_id="admin", user_role=LitellmUserRoles.PROXY_ADMIN+ )++ request = UpdatePublicModelGroupsRequest(model_groups=new_models)++ original_value = getattr(litellm, "public_model_groups", None)+ try:+ with patch(+ "litellm.proxy.proxy_server.proxy_config",+ mock_proxy_config,+ ), patch(+ "litellm.proxy.proxy_server.store_model_in_db",+ True,+ ):+ result = await update_public_model_groups(+ request=request,+ user_api_key_dict=admin_user,+ )++ # After the endpoint completes, the in-memory value must reflect+ # the NEW models, not the stale DB value+ assert litellm.public_model_groups == new_models+ assert result["public_model_groups"] == new_models+ finally:+ litellm.public_model_groups = original_value++class TestTeamModelUpdate:"""Test team model update handles team_id consistently with model creation"""