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(exceptions.py): use correct status code for content policy exceptions
Krrish Dholakia66dbd938e8ee
diff --git a/litellm/exceptions.py b/litellm/exceptions.pyindex d2337b7f494..f55c0914db9 100644--- a/litellm/exceptions.py+++ b/litellm/exceptions.py@@ -122,7 +122,7 @@ class BadRequestError(openai.BadRequestError): # type: ignoreself.model = modelself.llm_provider = llm_providerself.litellm_debug_info = litellm_debug_info- response = response or httpx.Response(+ response = httpx.Response(status_code=self.status_code,request=httpx.Request(method="GET", url="https://litellm.ai"@@ -287,16 +287,13 @@ class RateLimitError(openai.RateLimitError): # type: ignoreself.litellm_debug_info = litellm_debug_infoself.max_retries = max_retriesself.num_retries = num_retries- if response is None:- self.response = httpx.Response(- status_code=429,- request=httpx.Request(- method="POST",- url=" https://cloud.google.com/vertex-ai/",- ),- )- else:- self.response = response+ self.response = httpx.Response(+ status_code=429,+ request=httpx.Request(+ method="POST",+ url=" https://cloud.google.com/vertex-ai/",+ ),+ )super().__init__(self.message, response=self.response, body=None) # Call the base class constructor with the parameters it needs@@ -334,7 +331,7 @@ class ContextWindowExceededError(BadRequestError): # type: ignoreself.llm_provider = llm_providerself.litellm_debug_info = litellm_debug_inforequest = httpx.Request(method="POST", url="https://api.openai.com/v1")- self.response = response or httpx.Response(status_code=400, request=request)+ self.response = httpx.Response(status_code=400, request=request)super().__init__(message=self.message,model=self.model, # type: ignore@@ -377,7 +374,7 @@ class RejectedRequestError(BadRequestError): # type: ignoreself.litellm_debug_info = litellm_debug_infoself.request_data = request_datarequest = httpx.Request(method="POST", url="https://api.openai.com/v1")- response = httpx.Response(status_code=500, request=request)+ response = httpx.Response(status_code=400, request=request)super().__init__(message=self.message,model=self.model, # type: ignore@@ -419,7 +416,7 @@ class ContentPolicyViolationError(BadRequestError): # type: ignoreself.llm_provider = llm_providerself.litellm_debug_info = litellm_debug_inforequest = httpx.Request(method="POST", url="https://api.openai.com/v1")- self.response = response or httpx.Response(status_code=500, request=request)+ self.response = httpx.Response(status_code=400, request=request)super().__init__(message=self.message,model=self.model, # type: ignore@@ -463,16 +460,13 @@ class ServiceUnavailableError(openai.APIStatusError): # type: ignoreself.litellm_debug_info = litellm_debug_infoself.max_retries = max_retriesself.num_retries = num_retries- if response is None:- self.response = httpx.Response(- status_code=self.status_code,- request=httpx.Request(- method="POST",- url=" https://cloud.google.com/vertex-ai/",- ),- )- else:- self.response = response+ self.response = httpx.Response(+ status_code=self.status_code,+ request=httpx.Request(+ method="POST",+ url=" https://cloud.google.com/vertex-ai/",+ ),+ )super().__init__(self.message, response=self.response, body=None) # Call the base class constructor with the parameters it needs@@ -512,16 +506,13 @@ class InternalServerError(openai.InternalServerError): # type: ignoreself.litellm_debug_info = litellm_debug_infoself.max_retries = max_retriesself.num_retries = num_retries- if response is None:- self.response = httpx.Response(- status_code=self.status_code,- request=httpx.Request(- method="POST",- url=" https://cloud.google.com/vertex-ai/",- ),- )- else:- self.response = response+ self.response = httpx.Response(+ status_code=self.status_code,+ request=httpx.Request(+ method="POST",+ url=" https://cloud.google.com/vertex-ai/",+ ),+ )super().__init__(self.message, response=self.response, body=None) # Call the base class constructor with the parameters it needsdiff --git a/litellm/main.py b/litellm/main.pyindex 4a0d1251e8c..fc65ae73cc9 100644--- a/litellm/main.py+++ b/litellm/main.py@@ -500,6 +500,16 @@ def mock_completion(llm_provider=getattr(mock_response, "llm_provider", custom_llm_provider or "openai"), # type: ignoremodel=model,)+ elif isinstance(mock_response, str) and mock_response.startswith(+ "Exception: content_filter_policy"+ ):+ raise litellm.MockException(+ status_code=400,+ message=mock_response,+ llm_provider="azure",+ model=model, # type: ignore+ request=httpx.Request(method="POST", url="https://api.openai.com/v1/"),+ )time_delay = kwargs.get("mock_delay", None)if time_delay is not None:time.sleep(time_delay)diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yamlindex d13fb3f37af..c31c9873a92 100644--- a/litellm/proxy/_new_secret_config.yaml+++ b/litellm/proxy/_new_secret_config.yaml@@ -3,7 +3,7 @@ model_list:litellm_params:model: "*"-litellm_settings:- cache: true- cache_params:- type: redis\ No newline at end of file+# litellm_settings:+# cache: true+# cache_params:+# type: redis\ No newline at end of file