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]

fix test proxy exception mapping

Ishaan Jaffc50a60004f94
diff --git a/litellm/proxy/route_llm_request.py b/litellm/proxy/route_llm_request.py
index 27555598c3a..90fd09a4ace 100644
--- a/litellm/proxy/route_llm_request.py
+++ b/litellm/proxy/route_llm_request.py
@@ -25,6 +25,17 @@ else:
LitellmRouter = Any
+ROUTE_ENDPOINT_MAPPING = {
+ "acompletion": "/chat/completions",
+ "atext_completion": "/completions",
+ "aembedding": "/embeddings",
+ "aimage_generation": "/image/generations",
+ "aspeech": "/audio/speech",
+ "atranscription": "/audio/transcriptions",
+ "amoderation": "/moderations",
+}
+
+
async def route_request(
data: dict,
llm_router: Optional[LitellmRouter],
@@ -94,10 +105,12 @@ async def route_request(
elif user_model is not None:
return getattr(litellm, f"{route_type}")(**data)
+ # if no route found then it's a bad request
+ route_name = ROUTE_ENDPOINT_MAPPING.get(route_type, route_type)
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail={
- "error": f"{route_type}: Invalid model name passed in model="
+ "error": f"{route_name}: Invalid model name passed in model="
+ data.get("model", "")
},
)
diff --git a/litellm/tests/test_proxy_exception_mapping.py b/litellm/tests/test_proxy_exception_mapping.py
index a774d1b0ef0..89b4cd926e0 100644
--- a/litellm/tests/test_proxy_exception_mapping.py
+++ b/litellm/tests/test_proxy_exception_mapping.py
@@ -229,8 +229,9 @@ def test_chat_completion_exception_any_model(client):
)
assert isinstance(openai_exception, openai.BadRequestError)
_error_message = openai_exception.message
- assert "chat_completion: Invalid model name passed in model=Lite-GPT-12" in str(
- _error_message
+ assert (
+ "/chat/completions: Invalid model name passed in model=Lite-GPT-12"
+ in str(_error_message)
)
except Exception as e:
@@ -259,7 +260,7 @@ def test_embedding_exception_any_model(client):
print("Exception raised=", openai_exception)
assert isinstance(openai_exception, openai.BadRequestError)
_error_message = openai_exception.message
- assert "embeddings: Invalid model name passed in model=Lite-GPT-12" in str(
+ assert "/embeddings: Invalid model name passed in model=Lite-GPT-12" in str(
_error_message
)