Skip to content

LLMfyException

llmfy.exception.llmfy_exception

LLMfy Exception Handling

Documentation References:

Example of catching and inspecting an error:

try:
    # _call_llmfy
    pass
except LLMfyException as e:
    print(f"Error: {e.message}")
    print(f"Status Code: {e.status_code}")
    print(f"Provider: {e.provider}")
    print(f"Raw Error: {e.raw_error}")

    # Check specific exception type
    if isinstance(e, RateLimitException):
        print("Rate limited! Implement backoff...")
    elif isinstance(e, TimeoutException):
        print("Request timed out! Retry...")

LLMfyException

Bases: Exception

Base LLMfy Exception

Example of catching and inspecting an error:

try:
    # _call_llmfy
    pass
except LLMfyException as e:
    print(f"Error: {e.message}")
    print(f"Status Code: {e.status_code}")
    print(f"Provider: {e.provider}")
    print(f"Raw Error: {e.raw_error}")

    # Check specific exception type
    if isinstance(e, RateLimitException):
        print("Rate limited! Implement backoff...")
    elif isinstance(e, TimeoutException):
        print("Request timed out! Retry...")

Source code in llmfy/exception/llmfy_exception.py
class LLMfyException(Exception):
    """
    Base LLMfy Exception

    Example of catching and inspecting an error:
    ```python
    try:
        # _call_llmfy
        pass
    except LLMfyException as e:
        print(f"Error: {e.message}")
        print(f"Status Code: {e.status_code}")
        print(f"Provider: {e.provider}")
        print(f"Raw Error: {e.raw_error}")

        # Check specific exception type
        if isinstance(e, RateLimitException):
            print("Rate limited! Implement backoff...")
        elif isinstance(e, TimeoutException):
            print("Request timed out! Retry...")
    ```
    """

    def __init__(
        self,
        message: str,
        status_code: Optional[int] = None,
        raw_error: Optional[Any] = None,
        provider: Optional[str] = None,
    ):
        super().__init__(message)
        self.message = message
        self.status_code = status_code
        self.raw_error = raw_error
        self.provider = provider

    def __repr__(self) -> str:
        return (
            f"{self.__class__.__name__}("
            f"message={self.message!r}, "
            f"status_code={self.status_code}, "
            f"provider={self.provider!r})"
        )

message = message instance-attribute

status_code = status_code instance-attribute

raw_error = raw_error instance-attribute

provider = provider instance-attribute

__init__(message, status_code=None, raw_error=None, provider=None)

Source code in llmfy/exception/llmfy_exception.py
def __init__(
    self,
    message: str,
    status_code: Optional[int] = None,
    raw_error: Optional[Any] = None,
    provider: Optional[str] = None,
):
    super().__init__(message)
    self.message = message
    self.status_code = status_code
    self.raw_error = raw_error
    self.provider = provider

__repr__()

Source code in llmfy/exception/llmfy_exception.py
def __repr__(self) -> str:
    return (
        f"{self.__class__.__name__}("
        f"message={self.message!r}, "
        f"status_code={self.status_code}, "
        f"provider={self.provider!r})"
    )

RateLimitException

Bases: LLMfyException

Rate limit exceeded

Source code in llmfy/exception/llmfy_exception.py
class RateLimitException(LLMfyException):
    """Rate limit exceeded"""

    pass

QuotaExceededException

Bases: LLMfyException

Quota/usage limit exceeded

Source code in llmfy/exception/llmfy_exception.py
class QuotaExceededException(LLMfyException):
    """Quota/usage limit exceeded"""

    pass

TimeoutException

Bases: LLMfyException

Request timed out

Source code in llmfy/exception/llmfy_exception.py
class TimeoutException(LLMfyException):
    """Request timed out"""

    pass

InvalidRequestException

Bases: LLMfyException

Invalid request parameters

Source code in llmfy/exception/llmfy_exception.py
class InvalidRequestException(LLMfyException):
    """Invalid request parameters"""

    pass

AuthenticationException

Bases: LLMfyException

Authentication failed

Source code in llmfy/exception/llmfy_exception.py
class AuthenticationException(LLMfyException):
    """Authentication failed"""

    pass

PermissionDeniedException

Bases: LLMfyException

Permission denied

Source code in llmfy/exception/llmfy_exception.py
class PermissionDeniedException(LLMfyException):
    """Permission denied"""

    pass

ModelNotFoundException

Bases: LLMfyException

Model not found or unavailable

Source code in llmfy/exception/llmfy_exception.py
class ModelNotFoundException(LLMfyException):
    """Model not found or unavailable"""

    pass

ServiceUnavailableException

Bases: LLMfyException

Service temporarily unavailable

Source code in llmfy/exception/llmfy_exception.py
class ServiceUnavailableException(LLMfyException):
    """Service temporarily unavailable"""

    pass

ContentFilterException

Bases: LLMfyException

Content blocked by safety filters

Source code in llmfy/exception/llmfy_exception.py
class ContentFilterException(LLMfyException):
    """Content blocked by safety filters"""

    pass

ModelErrorException

Bases: LLMfyException

Model processing error

Source code in llmfy/exception/llmfy_exception.py
class ModelErrorException(LLMfyException):
    """Model processing error"""

    pass