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): map 403 to PermissionDeniedError in openai-like mapper
Cursor Agente2e16d7e2db1
diff --git a/litellm/litellm_core_utils/exception_mapping_utils.py b/litellm/litellm_core_utils/exception_mapping_utils.pyindex b76c97ad2de..cf5e28073f5 100644--- a/litellm/litellm_core_utils/exception_mapping_utils.py+++ b/litellm/litellm_core_utils/exception_mapping_utils.py@@ -755,12 +755,19 @@ def _map_openai_like_exception(llm_provider=custom_llm_provider,model=model,)- elif original_exception.status_code == 401 or original_exception.status_code == 403:+ elif original_exception.status_code == 401:raise AuthenticationError(message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",llm_provider=custom_llm_provider,model=model,)+ elif original_exception.status_code == 403:+ raise PermissionDeniedError(+ message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",+ llm_provider=custom_llm_provider,+ model=model,+ response=getattr(original_exception, "response", None),+ )elif original_exception.status_code == 400:raise BadRequestError(message=f"{custom_llm_provider.capitalize()}Exception - {original_exception.message}",diff --git a/tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py b/tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.pyindex 3eb8094f914..4f000eb18eb 100644--- a/tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py+++ b/tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py@@ -805,7 +805,7 @@ DEVIATIONS_FROM_THE_OPENAI_SHAPE = {503: UPSTREAM_STATUS_DISCARDED,},"databricks": {- 403: (litellm.AuthenticationError, 401),+ 403: (litellm.PermissionDeniedError, 403),422: (litellm.BadRequestError, 400),},"gemini": {@@ -1096,7 +1096,11 @@ def test_bedrock_mantle_context_overflow_maps_to_context_window_exceeded():@pytest.mark.parametrize("status_code, expected_class",- [(401, litellm.AuthenticationError), (429, litellm.RateLimitError)],+ [+ (401, litellm.AuthenticationError),+ (403, litellm.PermissionDeniedError),+ (429, litellm.RateLimitError),+ ],)def test_a_base_llm_exception_without_a_provider_branch_maps_by_status_code(status_code, expected_class, quiet_exception_mapping