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
Add support for wildcards models for files api
Sameer Kankutedc2d465c7e0a
diff --git a/litellm/router.py b/litellm/router.pyindex 8eb2c417511..25268f7faba 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 Nonediff --git a/tests/local_testing/test_router_utils.py b/tests/local_testing/test_router_utils.pyindex 7ade0777093..9d51685751a 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=[