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(router.py): use more descriptive error message (#12629)
Krish Dholakia3ad4d9fc3e7e
diff --git a/litellm/litellm_core_utils/token_counter.py b/litellm/litellm_core_utils/token_counter.pyindex 737784bed8e..1eb4fc9016a 100644--- a/litellm/litellm_core_utils/token_counter.py+++ b/litellm/litellm_core_utils/token_counter.py@@ -98,7 +98,7 @@ def get_modified_max_tokens(return user_max_tokensexcept Exception as e:- verbose_logger.error(+ verbose_logger.debug("litellm.litellm_core_utils.token_counter.py::get_modified_max_tokens() - Error while checking max token limit: {}\nmodel={}, base_model={}".format(str(e), model, base_model)diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.pyindex fc2920ae093..8c6ba7172f0 100644--- a/litellm/proxy/_types.py+++ b/litellm/proxy/_types.py@@ -499,6 +499,7 @@ class LiteLLMRoutes(enum.Enum):self_managed_routes = ["/team/member_add","/team/member_delete",+ "/team/member_update","/team/permissions_list","/team/permissions_update","/team/daily/activity",@@ -562,14 +563,16 @@ class LiteLLMPromptInjectionParams(LiteLLMPydanticObjectBase):)return values+######### Request Class Definition ######class ProxyChatCompletionRequest(ChatCompletionRequest):# Optional LiteLLM params- guardrails: Optional[List[str]]- caching: Optional[bool]- num_retries: Optional[int]- context_window_fallback_dict: Optional[Dict[str, str]]- fallbacks: Optional[List[str]]+ guardrails: Optional[List[str]]+ caching: Optional[bool]+ num_retries: Optional[int]+ context_window_fallback_dict: Optional[Dict[str, str]]+ fallbacks: Optional[List[str]]+class ModelInfoDelete(LiteLLMPydanticObjectBase):id: str@@ -828,7 +831,7 @@ class NewMCPServerRequest(LiteLLMPydanticObjectBase):command: Optional[str] = Noneargs: List[str] = Field(default_factory=list)env: Dict[str, str] = Field(default_factory=dict)-+@model_validator(mode="before")@classmethoddef validate_transport_fields(cls, values):@@ -845,7 +848,6 @@ class NewMCPServerRequest(LiteLLMPydanticObjectBase):return values-class UpdateMCPServerRequest(LiteLLMPydanticObjectBase):server_id: stralias: Optional[str] = None@@ -860,7 +862,7 @@ class UpdateMCPServerRequest(LiteLLMPydanticObjectBase):command: Optional[str] = Noneargs: List[str] = Field(default_factory=list)env: Dict[str, str] = Field(default_factory=dict)-+@model_validator(mode="before")@classmethoddef validate_transport_fields(cls, values):@@ -877,7 +879,6 @@ class UpdateMCPServerRequest(LiteLLMPydanticObjectBase):return values-class LiteLLM_MCPServerTable(LiteLLMPydanticObjectBase):"""Represents a LiteLLM_MCPServerTable record"""@@ -1736,11 +1737,15 @@ class UserAPIKeyAuth(@classmethoddef check_api_key(cls, values):if values.get("api_key") is not None:- values.update({"token": cls._safe_hash_litellm_api_key(values.get("api_key"))})+ values.update(+ {"token": cls._safe_hash_litellm_api_key(values.get("api_key"))}+ )if isinstance(values.get("api_key"), str):- values.update({"api_key": cls._safe_hash_litellm_api_key(values.get("api_key"))})+ values.update(+ {"api_key": cls._safe_hash_litellm_api_key(values.get("api_key"))}+ )return values-+@classmethoddef _safe_hash_litellm_api_key(cls, api_key: str) -> str:"""@@ -1752,6 +1757,7 @@ class UserAPIKeyAuth(if api_key.startswith("sk-"):return hash_token(api_key)from litellm.proxy.auth.handle_jwt import JWTHandler+if JWTHandler.is_jwt(token=api_key):return f"hashed-jwt-{hash_token(token=api_key)}"return api_keydiff --git a/litellm/router.py b/litellm/router.pyindex 879a3a5c89b..4eddbf6da1f 100644--- a/litellm/router.py+++ b/litellm/router.py@@ -6235,10 +6235,17 @@ class Router:)if len(healthy_deployments) == 0:- raise litellm.BadRequestError(- message="You passed in model={}. There is no 'model_name' with this string ".format(+ if self.get_model_list(model_name=model) is None:+ message = f"You passed in model={model}. There is no 'model_name' with this string".format(model- ),+ )+ else:+ message = f"You passed in model={model}. There are no healthy deployments for this model".format(+ model+ )++ raise litellm.BadRequestError(+ message=message,model=model,llm_provider="",)diff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.pyindex fa80f284937..0ec39e32b97 100644--- a/tests/test_litellm/test_utils.py+++ b/tests/test_litellm/test_utils.py@@ -2144,6 +2144,29 @@ def test_bedrock_application_inference_profile():assert result is True+def test_image_response_utils():+ """Test that the image response utils are correct."""+ from litellm.utils import ImageResponse++ result = {+ "created": None,+ "data": [+ {+ "b64_json": "/9j/.../2Q==",+ "revised_prompt": None,+ "url": None,+ "timings": {"inference": 0.9612685777246952},+ "index": 0,+ }+ ],+ "id": "91559891cxxx-PDX",+ "model": "black-forest-labs/FLUX.1-schnell-Free",+ "object": "list",+ "hidden_params": {"additional_headers": {}},+ }+ image_response = ImageResponse(**result)++if __name__ == "__main__":# Allow running this test file directly for debuggingpytest.main([__file__, "-v"])