diff --git a/litellm/exceptions.py b/litellm/exceptions.py index 6662cf4a2c2..9e9fcbe621a 100644 --- a/litellm/exceptions.py +++ b/litellm/exceptions.py @@ -477,7 +477,7 @@ class PermissionDeniedError(openai.PermissionDeniedError): message, llm_provider, model, - response: httpx.Response, + response: httpx.Response | None = None, litellm_debug_info: str | None = None, max_retries: int | None = None, num_retries: int | None = None, @@ -489,8 +489,15 @@ class PermissionDeniedError(openai.PermissionDeniedError): self.litellm_debug_info = litellm_debug_info self.max_retries = max_retries self.num_retries = num_retries + if response is not None and getattr(response, "request", None) is not None: + self.response = response + else: + self.response = httpx.Response( + status_code=self.status_code, + request=httpx.Request(method="POST", url="https://litellm.ai"), + ) super().__init__( - self.message, response=response, body=None + self.message, response=self.response, body=None ) # Call the base class constructor with the parameters it needs def __str__(self): diff --git a/litellm/litellm_core_utils/exception_mapping_utils.py b/litellm/litellm_core_utils/exception_mapping_utils.py index f2e1eb831ea..51e9ed22f1a 100644 --- a/litellm/litellm_core_utils/exception_mapping_utils.py +++ b/litellm/litellm_core_utils/exception_mapping_utils.py @@ -446,7 +446,6 @@ def _map_openai_exception( model=model, response=response, litellm_debug_info=extra_information, - body=getattr(original_exception, "body", None), ) if invalid_request_status == 404: raise NotFoundError( @@ -532,7 +531,6 @@ def _map_openai_exception( model=model, response=response, litellm_debug_info=extra_information, - body=getattr(original_exception, "body", None), ) elif original_exception.status_code == 404: raise NotFoundError(