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
test(test_router.py): add test to ensure error is correctly re-raised
Krrish Dholakia5a2c9d512117
diff --git a/litellm/main.py b/litellm/main.pyindex 001cbe24f56..649fc12a5cc 100644--- a/litellm/main.py+++ b/litellm/main.py@@ -503,7 +503,6 @@ def mock_completion():raise litellm.RateLimitError(message="this is a mock rate limit error",- status_code=getattr(mock_response, "status_code", 429), # type: ignorellm_provider=getattr(mock_response, "llm_provider", custom_llm_provider or "openai"), # type: ignoremodel=model,)diff --git a/litellm/tests/test_router.py b/litellm/tests/test_router.pyindex 0eb014f8506..3c374df87db 100644--- a/litellm/tests/test_router.py+++ b/litellm/tests/test_router.py@@ -2110,18 +2110,18 @@ def test_router_context_window_pre_call_check(model, base_model, llm_provider):def test_router_cooldown_api_connection_error():- # try:- # _ = litellm.completion(- # model="vertex_ai/gemini-1.5-pro",- # messages=[{"role": "admin", "content": "Fail on this!"}],- # )- # except litellm.APIConnectionError as e:- # assert (- # Router()._is_cooldown_required(- # exception_status=e.code, exception_str=str(e)- # )- # is False- # )+ try:+ _ = litellm.completion(+ model="vertex_ai/gemini-1.5-pro",+ messages=[{"role": "admin", "content": "Fail on this!"}],+ )+ except litellm.APIConnectionError as e:+ assert (+ Router()._is_cooldown_required(+ exception_status=e.code, exception_str=str(e)+ )+ is False+ )router = Router(model_list=[@@ -2155,3 +2155,32 @@ def test_router_cooldown_api_connection_error():)except litellm.APIConnectionError:pass+++def test_router_correctly_reraise_error():+ """+ User feedback: There is a problem with my messages array, but the error exception thrown is a Rate Limit error.+ ```+ Rate Limit: Error code: 429 - {'error': {'message': 'No deployments available for selected model, Try again in 60 seconds. Passed model=gemini-1.5-flash..+ ```+ What they want? Propagation of the real error.+ """+ router = Router(+ model_list=[+ {+ "model_name": "gemini-1.5-pro",+ "litellm_params": {+ "model": "vertex_ai/gemini-1.5-pro",+ "mock_response": "litellm.RateLimitError",+ },+ }+ ]+ )++ try:+ router.completion(+ model="gemini-1.5-pro",+ messages=[{"role": "admin", "content": "Fail on this!"}],+ )+ except litellm.RateLimitError:+ pass