From dc2d465c7e0aebedd1ad668a935388cc7b55af00 Mon Sep 17 00:00:00 2001 From: Sameer Kankute Date: Wed, 4 Mar 2026 11:48:42 +0530 Subject: [PATCH] Add support for wildcards models for files api --- litellm/router.py | 11 ++++++ tests/local_testing/test_router_utils.py | 47 ++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/litellm/router.py b/litellm/router.py index 8eb2c41751..25268f7fab 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -7100,6 +7100,17 @@ class Router: model_group_name=model_id ) + # If still not found, check for wildcard pattern matches + if deployment is None: + potential_wildcard_models = self.pattern_router.route(model_id) or [] + if potential_wildcard_models: + # Use the first matching wildcard deployment + deployment_dict = potential_wildcard_models[0] + if isinstance(deployment_dict, dict): + deployment = Deployment(**deployment_dict) + elif isinstance(deployment_dict, Deployment): + deployment = deployment_dict + if deployment is None: return None diff --git a/tests/local_testing/test_router_utils.py b/tests/local_testing/test_router_utils.py index 7ade077709..9d51685751 100644 --- a/tests/local_testing/test_router_utils.py +++ b/tests/local_testing/test_router_utils.py @@ -502,6 +502,53 @@ def test_router_get_deployment_credentials_with_provider(): assert credentials3 is None +def test_router_get_deployment_credentials_with_provider_wildcard(): + """ + Test that get_deployment_credentials_with_provider handles wildcard patterns. + + When a model like openai/gpt-4o is requested and the config has openai/*, + the method should resolve the wildcard pattern and return credentials. + """ + router = Router( + model_list=[ + { + "model_name": "openai/*", + "litellm_params": { + "model": "openai/*", + "api_key": "sk-wildcard-123", + "api_base": "https://api.openai.com/v1", + }, + "model_info": {"id": "openai-wildcard-deployment"}, + }, + { + "model_name": "anthropic/*", + "litellm_params": { + "model": "anthropic/*", + "api_key": "sk-ant-wildcard-456", + }, + "model_info": {"id": "anthropic-wildcard-deployment"}, + }, + ] + ) + + # Test wildcard pattern matching for OpenAI + credentials = router.get_deployment_credentials_with_provider(model_id="openai/gpt-4o") + assert credentials is not None + assert credentials["api_key"] == "sk-wildcard-123" + assert credentials["custom_llm_provider"] == "openai" + assert credentials["api_base"] == "https://api.openai.com/v1" + + # Test wildcard pattern matching for Anthropic + credentials2 = router.get_deployment_credentials_with_provider(model_id="anthropic/claude-3-opus") + assert credentials2 is not None + assert credentials2["api_key"] == "sk-ant-wildcard-456" + assert credentials2["custom_llm_provider"] == "anthropic" + + # Test with non-matching model + credentials3 = router.get_deployment_credentials_with_provider(model_id="vertex_ai/gemini-pro") + assert credentials3 is None + + def test_router_get_deployment_model_info(): router = Router( model_list=[