"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from .openroutererror import OpenRouterError
from typing import TYPE_CHECKING
from importlib import import_module
import builtins
import sys

if TYPE_CHECKING:
    from .badgatewayresponse_error import (
        BadGatewayResponseError,
        BadGatewayResponseErrorData,
    )
    from .badrequestresponse_error import (
        BadRequestResponseError,
        BadRequestResponseErrorData,
    )
    from .conflictresponse_error import ConflictResponseError, ConflictResponseErrorData
    from .edgenetworktimeoutresponse_error import (
        EdgeNetworkTimeoutResponseError,
        EdgeNetworkTimeoutResponseErrorData,
    )
    from .forbiddenresponse_error import (
        ForbiddenResponseError,
        ForbiddenResponseErrorData,
    )
    from .internalserverresponse_error import (
        InternalServerResponseError,
        InternalServerResponseErrorData,
    )
    from .no_response_error import NoResponseError
    from .notfoundresponse_error import NotFoundResponseError, NotFoundResponseErrorData
    from .openrouterdefaulterror import OpenRouterDefaultError
    from .payloadtoolargeresponse_error import (
        PayloadTooLargeResponseError,
        PayloadTooLargeResponseErrorData,
    )
    from .paymentrequiredresponse_error import (
        PaymentRequiredResponseError,
        PaymentRequiredResponseErrorData,
    )
    from .provideroverloadedresponse_error import (
        ProviderOverloadedResponseError,
        ProviderOverloadedResponseErrorData,
    )
    from .requesttimeoutresponse_error import (
        RequestTimeoutResponseError,
        RequestTimeoutResponseErrorData,
    )
    from .responsevalidationerror import ResponseValidationError
    from .serviceunavailableresponse_error import (
        ServiceUnavailableResponseError,
        ServiceUnavailableResponseErrorData,
    )
    from .toomanyrequestsresponse_error import (
        TooManyRequestsResponseError,
        TooManyRequestsResponseErrorData,
    )
    from .unauthorizedresponse_error import (
        UnauthorizedResponseError,
        UnauthorizedResponseErrorData,
    )
    from .unprocessableentityresponse_error import (
        UnprocessableEntityResponseError,
        UnprocessableEntityResponseErrorData,
    )

__all__ = [
    "BadGatewayResponseError",
    "BadGatewayResponseErrorData",
    "BadRequestResponseError",
    "BadRequestResponseErrorData",
    "ConflictResponseError",
    "ConflictResponseErrorData",
    "EdgeNetworkTimeoutResponseError",
    "EdgeNetworkTimeoutResponseErrorData",
    "ForbiddenResponseError",
    "ForbiddenResponseErrorData",
    "InternalServerResponseError",
    "InternalServerResponseErrorData",
    "NoResponseError",
    "NotFoundResponseError",
    "NotFoundResponseErrorData",
    "OpenRouterDefaultError",
    "OpenRouterError",
    "PayloadTooLargeResponseError",
    "PayloadTooLargeResponseErrorData",
    "PaymentRequiredResponseError",
    "PaymentRequiredResponseErrorData",
    "ProviderOverloadedResponseError",
    "ProviderOverloadedResponseErrorData",
    "RequestTimeoutResponseError",
    "RequestTimeoutResponseErrorData",
    "ResponseValidationError",
    "ServiceUnavailableResponseError",
    "ServiceUnavailableResponseErrorData",
    "TooManyRequestsResponseError",
    "TooManyRequestsResponseErrorData",
    "UnauthorizedResponseError",
    "UnauthorizedResponseErrorData",
    "UnprocessableEntityResponseError",
    "UnprocessableEntityResponseErrorData",
]

_dynamic_imports: dict[str, str] = {
    "BadGatewayResponseError": ".badgatewayresponse_error",
    "BadGatewayResponseErrorData": ".badgatewayresponse_error",
    "BadRequestResponseError": ".badrequestresponse_error",
    "BadRequestResponseErrorData": ".badrequestresponse_error",
    "ConflictResponseError": ".conflictresponse_error",
    "ConflictResponseErrorData": ".conflictresponse_error",
    "EdgeNetworkTimeoutResponseError": ".edgenetworktimeoutresponse_error",
    "EdgeNetworkTimeoutResponseErrorData": ".edgenetworktimeoutresponse_error",
    "ForbiddenResponseError": ".forbiddenresponse_error",
    "ForbiddenResponseErrorData": ".forbiddenresponse_error",
    "InternalServerResponseError": ".internalserverresponse_error",
    "InternalServerResponseErrorData": ".internalserverresponse_error",
    "NoResponseError": ".no_response_error",
    "NotFoundResponseError": ".notfoundresponse_error",
    "NotFoundResponseErrorData": ".notfoundresponse_error",
    "OpenRouterDefaultError": ".openrouterdefaulterror",
    "PayloadTooLargeResponseError": ".payloadtoolargeresponse_error",
    "PayloadTooLargeResponseErrorData": ".payloadtoolargeresponse_error",
    "PaymentRequiredResponseError": ".paymentrequiredresponse_error",
    "PaymentRequiredResponseErrorData": ".paymentrequiredresponse_error",
    "ProviderOverloadedResponseError": ".provideroverloadedresponse_error",
    "ProviderOverloadedResponseErrorData": ".provideroverloadedresponse_error",
    "RequestTimeoutResponseError": ".requesttimeoutresponse_error",
    "RequestTimeoutResponseErrorData": ".requesttimeoutresponse_error",
    "ResponseValidationError": ".responsevalidationerror",
    "ServiceUnavailableResponseError": ".serviceunavailableresponse_error",
    "ServiceUnavailableResponseErrorData": ".serviceunavailableresponse_error",
    "TooManyRequestsResponseError": ".toomanyrequestsresponse_error",
    "TooManyRequestsResponseErrorData": ".toomanyrequestsresponse_error",
    "UnauthorizedResponseError": ".unauthorizedresponse_error",
    "UnauthorizedResponseErrorData": ".unauthorizedresponse_error",
    "UnprocessableEntityResponseError": ".unprocessableentityresponse_error",
    "UnprocessableEntityResponseErrorData": ".unprocessableentityresponse_error",
}


def dynamic_import(modname, retries=3):
    for attempt in range(retries):
        try:
            return import_module(modname, __package__)
        except KeyError:
            # Clear any half-initialized module and retry
            sys.modules.pop(modname, None)
            if attempt == retries - 1:
                break
    raise KeyError(f"Failed to import module '{modname}' after {retries} attempts")


def __getattr__(attr_name: str) -> object:
    module_name = _dynamic_imports.get(attr_name)
    if module_name is None:
        raise AttributeError(
            f"No {attr_name} found in _dynamic_imports for module name -> {__name__} "
        )

    try:
        module = dynamic_import(module_name)
        result = getattr(module, attr_name)
        return result
    except ImportError as e:
        raise ImportError(
            f"Failed to import {attr_name} from {module_name}: {e}"
        ) from e
    except AttributeError as e:
        raise AttributeError(
            f"Failed to get {attr_name} from {module_name}: {e}"
        ) from e


def __dir__():
    lazy_attrs = builtins.list(_dynamic_imports.keys())
    return builtins.sorted(lazy_attrs)
