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
update tests
Tim Elfrinkc9daf3bc8ed0
diff --git a/litellm/litellm_core_utils/exception_mapping_utils.py b/litellm/litellm_core_utils/exception_mapping_utils.pyindex 6fc4accc8c0..dabe4d1d277 100644--- a/litellm/litellm_core_utils/exception_mapping_utils.py+++ b/litellm/litellm_core_utils/exception_mapping_utils.py@@ -763,7 +763,7 @@ def exception_type( # type: ignore # noqa: PLR0915error_str += "XXXXXXX" + '"'raise AuthenticationError(- message=f"{custom_llm_provider}Exception: Authentication Error - {error_str}",+ message=f"{custom_llm_provider.capitalize()}Exception: Authentication Error - {error_str}",llm_provider=custom_llm_provider,model=model,response=getattr(original_exception, "response", None),@@ -772,14 +772,14 @@ def exception_type( # type: ignore # noqa: PLR0915elif "model's maximum context limit" in error_str:exception_mapping_worked = Trueraise ContextWindowExceededError(- message=f"{custom_llm_provider}Exception: Context Window Error - {error_str}",+ message=f"{custom_llm_provider.capitalize()}Exception: Context Window Error - {error_str}",model=model,llm_provider=custom_llm_provider,)elif "token_quota_reached" in error_str:exception_mapping_worked = Trueraise RateLimitError(- message=f"{custom_llm_provider}Exception: Rate Limit Errror - {error_str}",+ message=f"{custom_llm_provider.capitalize()}Exception: Rate Limit Errror - {error_str}",llm_provider=custom_llm_provider,model=model,response=getattr(original_exception, "response", None),@@ -790,14 +790,14 @@ def exception_type( # type: ignore # noqa: PLR0915):exception_mapping_worked = Trueraise litellm.InternalServerError(- message=f"{custom_llm_provider}Exception - {original_exception.message}",+ message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",llm_provider=custom_llm_provider,model=model,)elif "model_no_support_for_function" in error_str:exception_mapping_worked = Trueraise BadRequestError(- message=f"{custom_llm_provider}Exception - Use 'watsonx_text' route instead. IBM WatsonX does not support `/text/chat` endpoint. - {error_str}",+ message=f"{custom_llm_provider.capitalize()}Exception - Use 'watsonx_text' route instead. IBM WatsonX does not support `/text/chat` endpoint. - {error_str}",llm_provider=custom_llm_provider,model=model,)@@ -805,7 +805,7 @@ def exception_type( # type: ignore # noqa: PLR0915if original_exception.status_code == 500:exception_mapping_worked = Trueraise litellm.InternalServerError(- message=f"{custom_llm_provider}Exception - {original_exception.message}",+ message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",llm_provider=custom_llm_provider,model=model,)@@ -815,28 +815,28 @@ def exception_type( # type: ignore # noqa: PLR0915):exception_mapping_worked = Trueraise AuthenticationError(- message=f"{custom_llm_provider}Exception - {original_exception.message}",+ message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",llm_provider=custom_llm_provider,model=model,)elif original_exception.status_code == 400:exception_mapping_worked = Trueraise BadRequestError(- message=f"{custom_llm_provider}Exception - {original_exception.message}",+ message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",llm_provider=custom_llm_provider,model=model,)elif original_exception.status_code == 404:exception_mapping_worked = Trueraise NotFoundError(- message=f"{custom_llm_provider}Exception - {original_exception.message}",+ message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",llm_provider=custom_llm_provider,model=model,)elif original_exception.status_code == 408:exception_mapping_worked = Trueraise Timeout(- message=f"{custom_llm_provider}Exception - {original_exception.message}",+ message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",model=model,llm_provider=custom_llm_provider,litellm_debug_info=extra_information,@@ -847,7 +847,7 @@ def exception_type( # type: ignore # noqa: PLR0915):exception_mapping_worked = Trueraise BadRequestError(- message=f"{custom_llm_provider}Exception - {original_exception.message}",+ message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",model=model,llm_provider=custom_llm_provider,litellm_debug_info=extra_information,@@ -855,7 +855,7 @@ def exception_type( # type: ignore # noqa: PLR0915elif original_exception.status_code == 429:exception_mapping_worked = Trueraise RateLimitError(- message=f"{custom_llm_provider}Exception - {original_exception.message}",+ message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",model=model,llm_provider=custom_llm_provider,litellm_debug_info=extra_information,@@ -863,7 +863,7 @@ def exception_type( # type: ignore # noqa: PLR0915elif original_exception.status_code == 503:exception_mapping_worked = Trueraise ServiceUnavailableError(- message=f"{custom_llm_provider}Exception - {original_exception.message}",+ message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",model=model,llm_provider=custom_llm_provider,litellm_debug_info=extra_information,@@ -871,7 +871,7 @@ def exception_type( # type: ignore # noqa: PLR0915elif original_exception.status_code == 504: # gateway timeout errorexception_mapping_worked = Trueraise Timeout(- message=f"{custom_llm_provider}Exception - {original_exception.message}",+ message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",model=model,llm_provider=custom_llm_provider,litellm_debug_info=extra_information,@@ -1171,6 +1171,7 @@ def exception_type( # type: ignore # noqa: PLR0915elif (custom_llm_provider == LlmProviders.VERTEX_AIor custom_llm_provider == LlmProviders.VERTEX_AI_BETA+ or custom_llm_provider == LlmProviders.GEMINI):if ("Vertex AI API has not been used in project" in error_str@@ -1178,9 +1179,9 @@ def exception_type( # type: ignore # noqa: PLR0915):exception_mapping_worked = Trueraise BadRequestError(- message=f"litellm.BadRequestError: VertexAIException - {error_str}",+ message=f"litellm.BadRequestError: {custom_llm_provider}Exception - {error_str}",model=model,- llm_provider="vertex_ai",+ llm_provider=custom_llm_provider,response=httpx.Response(status_code=400,request=httpx.Request(@@ -1193,7 +1194,7 @@ def exception_type( # type: ignore # noqa: PLR0915if "400 Request payload size exceeds" in error_str:exception_mapping_worked = Trueraise ContextWindowExceededError(- message=f"VertexException - {error_str}",+ message=f"{custom_llm_provider.capitalize()}Exception - {error_str}",model=model,llm_provider=custom_llm_provider,)@@ -1203,9 +1204,9 @@ def exception_type( # type: ignore # noqa: PLR0915):exception_mapping_worked = Trueraise litellm.InternalServerError(- message=f"litellm.InternalServerError: VertexAIException - {error_str}",+ message=f"litellm.InternalServerError: {custom_llm_provider}Exception - {error_str}",model=model,- llm_provider="vertex_ai",+ llm_provider=custom_llm_provider,response=httpx.Response(status_code=500,content=str(original_exception),@@ -1216,7 +1217,7 @@ def exception_type( # type: ignore # noqa: PLR0915elif "API key not valid." in error_str:exception_mapping_worked = Trueraise AuthenticationError(- message=f"{custom_llm_provider}Exception - {error_str}",+ message=f"{custom_llm_provider.capitalize()}Exception - {error_str}",model=model,llm_provider=custom_llm_provider,litellm_debug_info=extra_information,@@ -1224,9 +1225,9 @@ def exception_type( # type: ignore # noqa: PLR0915elif "403" in error_str:exception_mapping_worked = Trueraise BadRequestError(- message=f"VertexAIException BadRequestError - {error_str}",+ message=f"{custom_llm_provider.capitalize()}Exception BadRequestError - {error_str}",model=model,- llm_provider="vertex_ai",+ llm_provider=custom_llm_provider,response=httpx.Response(status_code=403,request=httpx.Request(@@ -1243,9 +1244,9 @@ def exception_type( # type: ignore # noqa: PLR0915):exception_mapping_worked = Trueraise ContentPolicyViolationError(- message=f"VertexAIException ContentPolicyViolationError - {error_str}",+ message=f"{custom_llm_provider.capitalize()}Exception ContentPolicyViolationError - {error_str}",model=model,- llm_provider="vertex_ai",+ llm_provider=custom_llm_provider,litellm_debug_info=extra_information,response=httpx.Response(status_code=400,@@ -1264,9 +1265,9 @@ def exception_type( # type: ignore # noqa: PLR0915):exception_mapping_worked = Trueraise RateLimitError(- message=f"litellm.RateLimitError: VertexAIException - {error_str}",+ message=f"litellm.RateLimitError: {custom_llm_provider}Exception - {error_str}",model=model,- llm_provider="vertex_ai",+ llm_provider=custom_llm_provider,litellm_debug_info=extra_information,response=httpx.Response(status_code=429,@@ -1282,18 +1283,18 @@ def exception_type( # type: ignore # noqa: PLR0915):exception_mapping_worked = Trueraise litellm.InternalServerError(- message=f"litellm.InternalServerError: VertexAIException - {error_str}",+ message=f"litellm.InternalServerError: {custom_llm_provider}Exception - {error_str}",model=model,- llm_provider="vertex_ai",+ llm_provider=custom_llm_provider,litellm_debug_info=extra_information,)if hasattr(original_exception, "status_code"):if original_exception.status_code == 400:exception_mapping_worked = Trueraise BadRequestError(- message=f"VertexAIException BadRequestError - {error_str}",+ message=f"{custom_llm_provider.capitalize()}Exception BadRequestError - {error_str}",model=model,- llm_provider="vertex_ai",+ llm_provider=custom_llm_provider,litellm_debug_info=extra_information,response=httpx.Response(status_code=400,@@ -1306,21 +1307,21 @@ def exception_type( # type: ignore # noqa: PLR0915if original_exception.status_code == 401:exception_mapping_worked = Trueraise AuthenticationError(- message=f"VertexAIException - {original_exception.message}",+ message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",llm_provider=custom_llm_provider,model=model,)if original_exception.status_code == 404:exception_mapping_worked = Trueraise NotFoundError(- message=f"VertexAIException - {original_exception.message}",+ message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",llm_provider=custom_llm_provider,model=model,)if original_exception.status_code == 408:exception_mapping_worked = Trueraise Timeout(- message=f"VertexAIException - {original_exception.message}",+ message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",llm_provider=custom_llm_provider,model=model,)@@ -1328,9 +1329,9 @@ def exception_type( # type: ignore # noqa: PLR0915if original_exception.status_code == 429:exception_mapping_worked = Trueraise RateLimitError(- message=f"litellm.RateLimitError: VertexAIException - {error_str}",+ message=f"litellm.RateLimitError: {custom_llm_provider}Exception - {error_str}",model=model,- llm_provider="vertex_ai",+ llm_provider=custom_llm_provider,litellm_debug_info=extra_information,response=httpx.Response(status_code=429,@@ -1343,9 +1344,9 @@ def exception_type( # type: ignore # noqa: PLR0915if original_exception.status_code == 500:exception_mapping_worked = Trueraise litellm.InternalServerError(- message=f"VertexAIException InternalServerError - {error_str}",+ message=f"{custom_llm_provider.capitalize()}Exception InternalServerError - {error_str}",model=model,- llm_provider="vertex_ai",+ llm_provider=custom_llm_provider,litellm_debug_info=extra_information,response=httpx.Response(status_code=500,@@ -1356,124 +1357,10 @@ def exception_type( # type: ignore # noqa: PLR0915if original_exception.status_code == 503:exception_mapping_worked = Trueraise ServiceUnavailableError(- message=f"VertexAIException - {original_exception.message}",+ message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",llm_provider=custom_llm_provider,model=model,)- elif custom_llm_provider == "palm" or custom_llm_provider == LlmProviders.GEMINI:- if "503 Getting metadata" in error_str:- # auth errors look like this- # 503 Getting metadata from plugin failed with error: Reauthentication is needed. Please run `gcloud auth application-default login` to reauthenticate.- exception_mapping_worked = True- raise BadRequestError(- message="GeminiException - Invalid api key",- model=model,- llm_provider="palm",- response=getattr(original_exception, "response", None),- )- if (- "504 Deadline expired before operation could complete." in error_str- or "504 Deadline Exceeded" in error_str- ):- exception_mapping_worked = True- raise Timeout(- message=f"GeminiException - {original_exception.message}",- model=model,- llm_provider="palm",- exception_status_code=original_exception.status_code,- )- if "400 Request payload size exceeds" in error_str:- exception_mapping_worked = True- raise ContextWindowExceededError(- message=f"GeminiException - {error_str}",- model=model,- llm_provider="palm",- response=getattr(original_exception, "response", None),- )- if (- "500 An internal error has occurred." in error_str- or "list index out of range" in error_str- ):- exception_mapping_worked = True- raise APIError(- status_code=getattr(original_exception, "status_code", 500),- message=f"GeminiException - {original_exception.message}",- llm_provider="palm",- model=model,- request=httpx.Response(- status_code=429,- request=httpx.Request(- method="POST",- url=" https://cloud.google.com/vertex-ai/",- ),- ),- )- if hasattr(original_exception, "status_code"):- if original_exception.status_code == 400:- exception_mapping_worked = True- raise BadRequestError(- message=f"GeminiException - {error_str}",- model=model,- llm_provider="palm",- response=getattr(original_exception, "response", None),- )- if original_exception.status_code == 401:- exception_mapping_worked = True- raise AuthenticationError(- message=f"GeminiException - {error_str}",- llm_provider=custom_llm_provider,- model=model,- response=getattr(original_exception, "response", None),- )- if original_exception.status_code == 403:- exception_mapping_worked = True- raise PermissionDeniedError(- message=f"GeminiException - {error_str}",- llm_provider=custom_llm_provider,- model=model,- response=getattr(original_exception, "response", None),- )- if original_exception.status_code == 404:- exception_mapping_worked = True- raise NotFoundError(- message=f"GeminiException - {error_str}",- llm_provider=custom_llm_provider,- model=model,- response=getattr(original_exception, "response", None),- )- if original_exception.status_code == 408:- exception_mapping_worked = True- raise Timeout(- message=f"GeminiException - {error_str}",- llm_provider=custom_llm_provider,- model=model,- exception_status_code=original_exception.status_code,- )- if original_exception.status_code == 429:- exception_mapping_worked = True- raise RateLimitError(- message=f"GeminiException - {error_str}",- model=model,- llm_provider=custom_llm_provider,- response=getattr(original_exception, "response", None),- )- if original_exception.status_code == 500:- exception_mapping_worked = True- raise InternalServerError(- message=f"GeminiException - {error_str}",- model=model,- llm_provider=custom_llm_provider,- response=getattr(original_exception, "response", None),- )- if original_exception.status_code >= 500:- exception_mapping_worked = True- raise InternalServerError(- message=f"GeminiException - {error_str}",- model=model,- llm_provider=custom_llm_provider,- response=getattr(original_exception, "response", None),- )- # Dailed: Error occurred: 400 Request payload size exceeds the limit: 20000 byteselif custom_llm_provider == "cloudflare":if "Authentication error" in error_str:exception_mapping_worked = True