Skip to content

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]

_route_user_config_request fix

Ishaan Jaffera09d3e9162eb
diff --git a/litellm/proxy/route_llm_request.py b/litellm/proxy/route_llm_request.py
index 8884c9595e0..ba3d19ef458 100644
--- a/litellm/proxy/route_llm_request.py
+++ b/litellm/proxy/route_llm_request.py
@@ -12,6 +12,21 @@ else:
LitellmRouter = Any
+def _route_user_config_request(data: dict, route_type: str):
+ """Route a request using the user-provided router config."""
+ router_config = data.pop("user_config")
+
+ # Filter router_config to only include valid Router.__init__ arguments
+ # This prevents TypeError when invalid parameters are stored in the database
+ valid_args = litellm.Router.get_valid_args()
+ filtered_config = {k: v for k, v in router_config.items() if k in valid_args}
+
+ user_router = litellm.Router(**filtered_config)
+ ret_val = getattr(user_router, f"{route_type}")(**data)
+ user_router.discard()
+ return ret_val
+
+
def _is_a2a_agent_model(model_name: Any) -> bool:
"""Check if the model name is for an A2A agent (a2a/ prefix)."""
return isinstance(model_name, str) and model_name.startswith("a2a/")
@@ -211,17 +226,7 @@ async def route_request(
return llm_router.abatch_completion(models=models, **data)
elif "user_config" in data:
- router_config = data.pop("user_config")
-
- # Filter router_config to only include valid Router.__init__ arguments
- # This prevents TypeError when invalid parameters are stored in the database
- valid_args = litellm.Router.get_valid_args()
- filtered_config = {k: v for k, v in router_config.items() if k in valid_args}
-
- user_router = litellm.Router(**filtered_config)
- ret_val = getattr(user_router, f"{route_type}")(**data)
- user_router.discard()
- return ret_val
+ return _route_user_config_request(data, route_type)
elif "router_settings_override" in data:
# Apply per-request router settings overrides from key/team config