Skip to content

sharedkeys

SharedKeySettings

Bases: _BaseSharedKeySettings

Represents the settings for a SharedKey.

v2 API Model: SharedKeyInput

Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
class SharedKeySettings(_BaseSharedKeySettings):
    """Represents the settings for a SharedKey.

    v2 API Model: `SharedKeyInput`
    """

    expiry: int = Field(default=-1, ge=-1)
    """The number of days until this key expires. -1 means never expires."""

expiry class-attribute instance-attribute

expiry: int = Field(default=-1, ge=-1)

The number of days until this key expires. -1 means never expires.

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

kudos instance-attribute

kudos: int

The Kudos limit assigned to this key.

name instance-attribute

name: str

The Shared Key Name.

max_image_pixels instance-attribute

max_image_pixels: int

The maximum amount of image pixels this key can generate per job. -1 means unlimited.

max_image_steps instance-attribute

max_image_steps: int

The maximum amount of image steps this key can use per job. -1 means unlimited.

max_text_tokens instance-attribute

max_text_tokens: int

The maximum amount of text tokens this key can generate per job. -1 means unlimited.

get_api_model_name abstractmethod classmethod

get_api_model_name() -> str | None

Return the name of the model as seen in the published swagger doc.

If none, there is no payload, such as for a GET request.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
@abc.abstractmethod
def get_api_model_name(cls) -> str | None:
    """Return the name of the model as seen in the published swagger doc.

    If none, there is no payload, such as for a GET request.
    """

get_sensitive_fields classmethod

get_sensitive_fields() -> set[str]

Return a set of fields which should be redacted from logs.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_sensitive_fields(cls) -> set[str]:
    """Return a set of fields which should be redacted from logs."""
    return {"apikey"}

get_extra_fields_to_exclude_from_log

get_extra_fields_to_exclude_from_log() -> set[str]

Return an additional set of fields to exclude from the log_safe_model_dump method.

Source code in horde_sdk/generic_api/apimodels.py
def get_extra_fields_to_exclude_from_log(self) -> set[str]:
    """Return an additional set of fields to exclude from the log_safe_model_dump method."""
    return set()

log_safe_model_dump

log_safe_model_dump(
    extra_exclude: set[str] | None = None,
) -> dict[Any, Any]

Return a dict of the model's fields, with any sensitive fields redacted.

Source code in horde_sdk/generic_api/apimodels.py
def log_safe_model_dump(self, extra_exclude: set[str] | None = None) -> dict[Any, Any]:
    """Return a dict of the model's fields, with any sensitive fields redacted."""
    if extra_exclude is None:
        extra_exclude = set()

    if hasattr(self, "model_dump"):
        return self.model_dump(  # type: ignore
            exclude=self.get_sensitive_fields() | self.get_extra_fields_to_exclude_from_log() | extra_exclude,
        )

    logger.warning("Model does not have a model_dump method. Using python native class compatible method.")
    logger.debug(
        "Generally this should not be relied upon. If you're seeing this and you're a developer for the SDK, "
        "consider using pydantic models instead.",
    )
    # Its not a pydantic model, use python native class compatible method
    return {
        key: getattr(self, key)
        for key in self.__dict__
        if key not in self.get_sensitive_fields() | self.get_extra_fields_to_exclude_from_log() | extra_exclude
    }

validate_restriction_values classmethod

validate_restriction_values(v: int) -> int

Validate the restriction values.

Parameters:

  • v (int) –

    The restriction value.

Raises:

  • ValueError

    If the restriction value is invalid.

Returns:

  • int ( int ) –

    The restriction value.

Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@field_validator("max_image_pixels", "max_image_steps", "max_text_tokens", mode="before")
@classmethod
def validate_restriction_values(cls, v: int) -> int:
    """Validate the restriction values.

    Args:
        v (int): The restriction value.

    Raises:
        ValueError: If the restriction value is invalid.

    Returns:
        int: The restriction value.
    """
    if v < -1:
        raise ValueError("Restriction values must be -1 or greater.")
    return v

SharedKeyDetailsResponse

Bases: HordeResponseBaseModel, MessageSpecifiesSharedKeyMixin, SharedKeySettings

Information about a SharedKey, including its creating user, settings and utilization.

The data returned in this response can vary depending on the user's permissions, (creator, owner, or admin).

Represents the data returned from the following endpoints and http status codes
  • /v2/sharedkeys/{sharedkey_id} | SharedKeyModifyRequest [PATCH] -> 200
  • /v2/sharedkeys/{sharedkey_id} | SharedKeyDetailsRequest [GET] -> 200
  • /v2/sharedkeys | SharedKeyCreateRequest [PUT] -> 200

v2 API Model: SharedKeyDetails

Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
class SharedKeyDetailsResponse(HordeResponseBaseModel, MessageSpecifiesSharedKeyMixin, SharedKeySettings):
    """Information about a SharedKey, including its creating user, settings and utilization.

    The data returned in this response can vary depending on the user's permissions, (creator, owner, or admin).

    Represents the data returned from the following endpoints and http status codes:
        - /v2/sharedkeys/{sharedkey_id} | SharedKeyModifyRequest [PATCH] -> 200
        - /v2/sharedkeys/{sharedkey_id} | SharedKeyDetailsRequest [GET] -> 200
        - /v2/sharedkeys | SharedKeyCreateRequest [PUT] -> 200

    v2 API Model: `SharedKeyDetails`
    """

    username: str
    """The owning user's unique Username. It is a combination of their chosen alias plus their ID."""
    utilized: int
    """How much kudos has been utilized via this shared key until now."""

    @override
    @classmethod
    def get_api_model_name(cls) -> str | None:
        return "SharedKeyDetails"

    @field_validator("max_image_pixels", "max_image_steps", "max_text_tokens", mode="before")
    @classmethod
    def validate_restriction_values(cls, v: int) -> int:
        """Validate the restriction values.

        Args:
            v (int): The restriction value.

        Raises:
            ValueError: If the restriction value is invalid.

        Returns:
            int: The restriction value.
        """
        if v < -1:
            raise ValueError("Restriction values must be -1 or greater.")
        return v

username instance-attribute

username: str

The owning user's unique Username. It is a combination of their chosen alias plus their ID.

utilized instance-attribute

utilized: int

How much kudos has been utilized via this shared key until now.

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

kudos instance-attribute

kudos: int

The Kudos limit assigned to this key.

name instance-attribute

name: str

The Shared Key Name.

max_image_pixels instance-attribute

max_image_pixels: int

The maximum amount of image pixels this key can generate per job. -1 means unlimited.

max_image_steps instance-attribute

max_image_steps: int

The maximum amount of image steps this key can use per job. -1 means unlimited.

max_text_tokens instance-attribute

max_text_tokens: int

The maximum amount of text tokens this key can generate per job. -1 means unlimited.

expiry class-attribute instance-attribute

expiry: int = Field(default=-1, ge=-1)

The number of days until this key expires. -1 means never expires.

sharedkey_id class-attribute instance-attribute

sharedkey_id: SharedKeyID = Field(alias='id')

The shared key ID to use for this request.

time_constructed property

time_constructed: float

The time the model was constructed (in epoch time).

get_api_model_name classmethod

get_api_model_name() -> str | None
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_api_model_name(cls) -> str | None:
    return "SharedKeyDetails"

validate_restriction_values classmethod

validate_restriction_values(v: int) -> int

Validate the restriction values.

Parameters:

  • v (int) –

    The restriction value.

Raises:

  • ValueError

    If the restriction value is invalid.

Returns:

  • int ( int ) –

    The restriction value.

Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@field_validator("max_image_pixels", "max_image_steps", "max_text_tokens", mode="before")
@classmethod
def validate_restriction_values(cls, v: int) -> int:
    """Validate the restriction values.

    Args:
        v (int): The restriction value.

    Raises:
        ValueError: If the restriction value is invalid.

    Returns:
        int: The restriction value.
    """
    if v < -1:
        raise ValueError("Restriction values must be -1 or greater.")
    return v

get_sensitive_fields classmethod

get_sensitive_fields() -> set[str]

Return a set of fields which should be redacted from logs.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_sensitive_fields(cls) -> set[str]:
    """Return a set of fields which should be redacted from logs."""
    return {"apikey"}

get_extra_fields_to_exclude_from_log

get_extra_fields_to_exclude_from_log() -> set[str]

Return an additional set of fields to exclude from the log_safe_model_dump method.

Source code in horde_sdk/generic_api/apimodels.py
def get_extra_fields_to_exclude_from_log(self) -> set[str]:
    """Return an additional set of fields to exclude from the log_safe_model_dump method."""
    return set()

log_safe_model_dump

log_safe_model_dump(
    extra_exclude: set[str] | None = None,
) -> dict[Any, Any]

Return a dict of the model's fields, with any sensitive fields redacted.

Source code in horde_sdk/generic_api/apimodels.py
def log_safe_model_dump(self, extra_exclude: set[str] | None = None) -> dict[Any, Any]:
    """Return a dict of the model's fields, with any sensitive fields redacted."""
    if extra_exclude is None:
        extra_exclude = set()

    if hasattr(self, "model_dump"):
        return self.model_dump(  # type: ignore
            exclude=self.get_sensitive_fields() | self.get_extra_fields_to_exclude_from_log() | extra_exclude,
        )

    logger.warning("Model does not have a model_dump method. Using python native class compatible method.")
    logger.debug(
        "Generally this should not be relied upon. If you're seeing this and you're a developer for the SDK, "
        "consider using pydantic models instead.",
    )
    # Its not a pydantic model, use python native class compatible method
    return {
        key: getattr(self, key)
        for key in self.__dict__
        if key not in self.get_sensitive_fields() | self.get_extra_fields_to_exclude_from_log() | extra_exclude
    }

validate_sharedkey_id

validate_sharedkey_id(
    v: str | SharedKeyID,
) -> SharedKeyID | str

Ensure that the shared key ID is not empty.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
@field_validator("sharedkey_id", mode="before")
def validate_sharedkey_id(cls, v: str | SharedKeyID) -> SharedKeyID | str:
    """Ensure that the shared key ID is not empty."""
    if isinstance(v, str) and v == "":
        logger.warning("Shared key ID is empty")

    return v

ExpiryStrSharedKeyDetailsResponse

Bases: HordeResponseBaseModel, MessageSpecifiesSharedKeyMixin, _BaseSharedKeySettings

The shared key details for a style.

Represents the data returned from the following endpoints and http status codes
  • /v2/sharedkeys/{sharedkey_id} | SharedKeyModifyRequest [PATCH] -> 200
  • /v2/sharedkeys/{sharedkey_id} | SharedKeyDetailsRequest [GET] -> 200
  • /v2/sharedkeys | SharedKeyCreateRequest [PUT] -> 200

v2 API Model: _OVERLOADED_MODEL

Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
class ExpiryStrSharedKeyDetailsResponse(
    HordeResponseBaseModel,
    MessageSpecifiesSharedKeyMixin,
    _BaseSharedKeySettings,
):
    """The shared key details for a style.

    Represents the data returned from the following endpoints and http status codes:
        - /v2/sharedkeys/{sharedkey_id} | SharedKeyModifyRequest [PATCH] -> 200
        - /v2/sharedkeys/{sharedkey_id} | SharedKeyDetailsRequest [GET] -> 200
        - /v2/sharedkeys | SharedKeyCreateRequest [PUT] -> 200

    v2 API Model: `_OVERLOADED_MODEL`
    """

    expiry: str | None = None  # FIXME - duplicated in SharedKeyDetailsResponse due to overloaded model
    """The expiry date of the shared key."""
    username: str  # FIXME - duplicated in SharedKeyDetailsResponse due to overloaded model
    """The owning user's unique Username. It is a combination of their chosen alias plus their ID."""
    utilized: int  # FIXME - duplicated in SharedKeyDetailsResponse due to overloaded model
    """How much kudos has been utilized via this shared key until now."""

    @override
    @classmethod
    def get_api_model_name(cls) -> str:
        return _OVERLOADED_MODEL

expiry class-attribute instance-attribute

expiry: str | None = None

The expiry date of the shared key.

username instance-attribute

username: str

The owning user's unique Username. It is a combination of their chosen alias plus their ID.

utilized instance-attribute

utilized: int

How much kudos has been utilized via this shared key until now.

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

kudos instance-attribute

kudos: int

The Kudos limit assigned to this key.

name instance-attribute

name: str

The Shared Key Name.

max_image_pixels instance-attribute

max_image_pixels: int

The maximum amount of image pixels this key can generate per job. -1 means unlimited.

max_image_steps instance-attribute

max_image_steps: int

The maximum amount of image steps this key can use per job. -1 means unlimited.

max_text_tokens instance-attribute

max_text_tokens: int

The maximum amount of text tokens this key can generate per job. -1 means unlimited.

sharedkey_id class-attribute instance-attribute

sharedkey_id: SharedKeyID = Field(alias='id')

The shared key ID to use for this request.

time_constructed property

time_constructed: float

The time the model was constructed (in epoch time).

get_api_model_name classmethod

get_api_model_name() -> str
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_api_model_name(cls) -> str:
    return _OVERLOADED_MODEL

get_sensitive_fields classmethod

get_sensitive_fields() -> set[str]

Return a set of fields which should be redacted from logs.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_sensitive_fields(cls) -> set[str]:
    """Return a set of fields which should be redacted from logs."""
    return {"apikey"}

get_extra_fields_to_exclude_from_log

get_extra_fields_to_exclude_from_log() -> set[str]

Return an additional set of fields to exclude from the log_safe_model_dump method.

Source code in horde_sdk/generic_api/apimodels.py
def get_extra_fields_to_exclude_from_log(self) -> set[str]:
    """Return an additional set of fields to exclude from the log_safe_model_dump method."""
    return set()

log_safe_model_dump

log_safe_model_dump(
    extra_exclude: set[str] | None = None,
) -> dict[Any, Any]

Return a dict of the model's fields, with any sensitive fields redacted.

Source code in horde_sdk/generic_api/apimodels.py
def log_safe_model_dump(self, extra_exclude: set[str] | None = None) -> dict[Any, Any]:
    """Return a dict of the model's fields, with any sensitive fields redacted."""
    if extra_exclude is None:
        extra_exclude = set()

    if hasattr(self, "model_dump"):
        return self.model_dump(  # type: ignore
            exclude=self.get_sensitive_fields() | self.get_extra_fields_to_exclude_from_log() | extra_exclude,
        )

    logger.warning("Model does not have a model_dump method. Using python native class compatible method.")
    logger.debug(
        "Generally this should not be relied upon. If you're seeing this and you're a developer for the SDK, "
        "consider using pydantic models instead.",
    )
    # Its not a pydantic model, use python native class compatible method
    return {
        key: getattr(self, key)
        for key in self.__dict__
        if key not in self.get_sensitive_fields() | self.get_extra_fields_to_exclude_from_log() | extra_exclude
    }

validate_restriction_values classmethod

validate_restriction_values(v: int) -> int

Validate the restriction values.

Parameters:

  • v (int) –

    The restriction value.

Raises:

  • ValueError

    If the restriction value is invalid.

Returns:

  • int ( int ) –

    The restriction value.

Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@field_validator("max_image_pixels", "max_image_steps", "max_text_tokens", mode="before")
@classmethod
def validate_restriction_values(cls, v: int) -> int:
    """Validate the restriction values.

    Args:
        v (int): The restriction value.

    Raises:
        ValueError: If the restriction value is invalid.

    Returns:
        int: The restriction value.
    """
    if v < -1:
        raise ValueError("Restriction values must be -1 or greater.")
    return v

validate_sharedkey_id

validate_sharedkey_id(
    v: str | SharedKeyID,
) -> SharedKeyID | str

Ensure that the shared key ID is not empty.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
@field_validator("sharedkey_id", mode="before")
def validate_sharedkey_id(cls, v: str | SharedKeyID) -> SharedKeyID | str:
    """Ensure that the shared key ID is not empty."""
    if isinstance(v, str) and v == "":
        logger.warning("Shared key ID is empty")

    return v

SharedKeyDetailsRequest

Bases: BaseAIHordeRequest, MessageSpecifiesSharedKeyMixin

Request the details of a SharedKey, including its creating user, settings, and utilization.

The response data can vary depending on the user's permissions, (e.g., if they are a creator, owner, or admin).

Represents a GET request to the /v2/sharedkeys/{sharedkey_id} endpoint.

Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
class SharedKeyDetailsRequest(BaseAIHordeRequest, MessageSpecifiesSharedKeyMixin):
    """Request the details of a SharedKey, including its creating user, settings, and utilization.

    The response data can vary depending on the user's permissions, (e.g., if they are a creator, owner, or admin).

    Represents a GET request to the /v2/sharedkeys/{sharedkey_id} endpoint.
    """

    @override
    @classmethod
    def get_api_model_name(cls) -> str | None:
        return None

    @override
    @classmethod
    def get_http_method(cls) -> HTTPMethod:
        return HTTPMethod.GET

    @override
    @classmethod
    def get_api_endpoint_subpath(cls) -> AI_HORDE_API_ENDPOINT_SUBPATH:
        return AI_HORDE_API_ENDPOINT_SUBPATH.v2_sharedkeys

    @override
    @classmethod
    def get_default_success_response_type(cls) -> type[ExpiryStrSharedKeyDetailsResponse]:
        return ExpiryStrSharedKeyDetailsResponse

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

sharedkey_id class-attribute instance-attribute

sharedkey_id: SharedKeyID = Field(alias='id')

The shared key ID to use for this request.

accept class-attribute instance-attribute

accept: GenericAcceptTypes = json

The 'accept' header field.

client_agent class-attribute instance-attribute

client_agent: str = Field(
    default=default_bridge_agent_string,
    alias="Client-Agent",
)

The requesting client's agent. You should set this to reflect the name, version and contact information for your client.

get_api_model_name classmethod

get_api_model_name() -> str | None
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_api_model_name(cls) -> str | None:
    return None

get_http_method classmethod

get_http_method() -> HTTPMethod
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_http_method(cls) -> HTTPMethod:
    return HTTPMethod.GET

get_api_endpoint_subpath classmethod

get_api_endpoint_subpath() -> AI_HORDE_API_ENDPOINT_SUBPATH
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_api_endpoint_subpath(cls) -> AI_HORDE_API_ENDPOINT_SUBPATH:
    return AI_HORDE_API_ENDPOINT_SUBPATH.v2_sharedkeys

get_default_success_response_type classmethod

get_default_success_response_type() -> (
    type[ExpiryStrSharedKeyDetailsResponse]
)
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_default_success_response_type(cls) -> type[ExpiryStrSharedKeyDetailsResponse]:
    return ExpiryStrSharedKeyDetailsResponse

validate_sharedkey_id

validate_sharedkey_id(
    v: str | SharedKeyID,
) -> SharedKeyID | str

Ensure that the shared key ID is not empty.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
@field_validator("sharedkey_id", mode="before")
def validate_sharedkey_id(cls, v: str | SharedKeyID) -> SharedKeyID | str:
    """Ensure that the shared key ID is not empty."""
    if isinstance(v, str) and v == "":
        logger.warning("Shared key ID is empty")

    return v

get_sensitive_fields classmethod

get_sensitive_fields() -> set[str]
Source code in horde_sdk/generic_api/apimodels.py
@override
@classmethod
def get_sensitive_fields(cls) -> set[str]:
    return {"apikey"}

get_extra_fields_to_exclude_from_log

get_extra_fields_to_exclude_from_log() -> set[str]

Return an additional set of fields to exclude from the log_safe_model_dump method.

Source code in horde_sdk/generic_api/apimodels.py
def get_extra_fields_to_exclude_from_log(self) -> set[str]:
    """Return an additional set of fields to exclude from the log_safe_model_dump method."""
    return set()

log_safe_model_dump

log_safe_model_dump(
    extra_exclude: set[str] | None = None,
) -> dict[Any, Any]

Return a dict of the model's fields, with any sensitive fields redacted.

Source code in horde_sdk/generic_api/apimodels.py
def log_safe_model_dump(self, extra_exclude: set[str] | None = None) -> dict[Any, Any]:
    """Return a dict of the model's fields, with any sensitive fields redacted."""
    if extra_exclude is None:
        extra_exclude = set()

    if hasattr(self, "model_dump"):
        return self.model_dump(  # type: ignore
            exclude=self.get_sensitive_fields() | self.get_extra_fields_to_exclude_from_log() | extra_exclude,
        )

    logger.warning("Model does not have a model_dump method. Using python native class compatible method.")
    logger.debug(
        "Generally this should not be relied upon. If you're seeing this and you're a developer for the SDK, "
        "consider using pydantic models instead.",
    )
    # Its not a pydantic model, use python native class compatible method
    return {
        key: getattr(self, key)
        for key in self.__dict__
        if key not in self.get_sensitive_fields() | self.get_extra_fields_to_exclude_from_log() | extra_exclude
    }

get_api_endpoint_url classmethod

get_api_endpoint_url() -> str

Return the endpoint URL, including the path to the specific API action defined by this object.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_api_endpoint_url(cls) -> str:
    """Return the endpoint URL, including the path to the specific API action defined by this object."""
    return url_with_path(base_url=cls.get_api_url(), path=cls.get_api_endpoint_subpath())

get_api_url classmethod

get_api_url() -> str
Source code in horde_sdk/ai_horde_api/apimodels/base.py
@override
@classmethod
def get_api_url(cls) -> str:
    return AI_HORDE_BASE_URL

get_success_status_response_pairs classmethod

get_success_status_response_pairs() -> (
    dict[HTTPStatusCode, type[HordeResponseTypes]]
)

Return a dict of HTTP status codes and the expected HordeResponse.

Defaults to {HTTPStatusCode.OK: cls.get_expected_response_type()}, but may be overridden to support other status codes.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_success_status_response_pairs(
    cls,
) -> dict[HTTPStatusCode, type[HordeResponseTypes]]:
    """Return a dict of HTTP status codes and the expected `HordeResponse`.

    Defaults to `{HTTPStatusCode.OK: cls.get_expected_response_type()}`, but may be overridden to support other
    status codes.
    """
    return {HTTPStatusCode.OK: cls.get_default_success_response_type()}

get_header_fields classmethod

get_header_fields() -> list[str]

Return a list of field names from this request object that should be sent as header fields.

This is in addition to GenericHeaderFields's values, and possibly the API specific class which inherits from GenericHeaderFields, typically found in the horde_sdk.<api_name>_api.metadata module.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_header_fields(cls) -> list[str]:
    """Return a list of field names from this request object that should be sent as header fields.

    This is in addition to `GenericHeaderFields`'s values, and possibly the API specific class
    which inherits from `GenericHeaderFields`, typically found in the `horde_sdk.<api_name>_api.metadata` module.
    """
    return []

get_query_fields classmethod

get_query_fields() -> list[str]

Return a list of field names from this request object that should be sent as query parameters.

This is in addition to GenericQueryFields's values, and possibly the API specific class which inherits from GenericQueryFields, typically found in the horde_sdk.<api_name>_api.metadata module.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_query_fields(cls) -> list[str]:
    """Return a list of field names from this request object that should be sent as query parameters.

    This is in addition to `GenericQueryFields`'s values, and possibly the API specific class
    which inherits from `GenericQueryFields`, typically found in the `horde_sdk.<api_name>_api.metadata` module.
    """
    return []

get_number_of_results_expected

get_number_of_results_expected() -> int

Return the number of (job) results expected from this request.

Defaults to 1, but may be overridden to dynamically change the number of results expected.

This is factored into context management; if the number of results expected is not met, the job is considered unhandled on an exception and followed up on to attempt to close it.

Source code in horde_sdk/generic_api/apimodels.py
def get_number_of_results_expected(self) -> int:
    """Return the number of (job) results expected from this request.

    Defaults to `1`, but may be overridden to dynamically change the number of results expected.

    This is factored into context management; if the number of results expected is not met, the job is considered
    unhandled on an exception and followed up on to attempt to close it.
    """
    return 1

get_requires_follow_up

get_requires_follow_up() -> bool

Return whether this request requires a follow up request(s).

Returns:

  • bool ( bool ) –

    Whether this request requires a follow up request to close the job on the server.

Source code in horde_sdk/generic_api/apimodels.py
def get_requires_follow_up(self) -> bool:
    """Return whether this request requires a follow up request(s).

    Returns:
        bool: Whether this request requires a follow up request to close the job on the server.
    """
    for response_type in self.get_success_status_response_pairs().values():
        if issubclass(response_type, ResponseRequiringFollowUpMixin):
            return True
    return False

SharedKeyDeleteResponse

Bases: HordeResponseBaseModel, ContainsMessageResponseMixin

Indicates that a SharedKey was successfully deleted.

Represents the data returned from the /v2/sharedkeys/{sharedkey_id} endpoint with http status code 200.

v2 API Model: SimpleResponse

Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
class SharedKeyDeleteResponse(HordeResponseBaseModel, ContainsMessageResponseMixin):
    """Indicates that a SharedKey was successfully deleted.

    Represents the data returned from the /v2/sharedkeys/{sharedkey_id} endpoint with http status code 200.

    v2 API Model: `SimpleResponse`
    """

    @override
    @classmethod
    def get_api_model_name(cls) -> str | None:
        return "SimpleResponse"

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

message class-attribute instance-attribute

message: str = ''

A message from the API. This is typically an error or warning message, but may also be informational.

time_constructed property

time_constructed: float

The time the model was constructed (in epoch time).

get_api_model_name classmethod

get_api_model_name() -> str | None
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_api_model_name(cls) -> str | None:
    return "SimpleResponse"

get_sensitive_fields classmethod

get_sensitive_fields() -> set[str]

Return a set of fields which should be redacted from logs.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_sensitive_fields(cls) -> set[str]:
    """Return a set of fields which should be redacted from logs."""
    return {"apikey"}

get_extra_fields_to_exclude_from_log

get_extra_fields_to_exclude_from_log() -> set[str]

Return an additional set of fields to exclude from the log_safe_model_dump method.

Source code in horde_sdk/generic_api/apimodels.py
def get_extra_fields_to_exclude_from_log(self) -> set[str]:
    """Return an additional set of fields to exclude from the log_safe_model_dump method."""
    return set()

log_safe_model_dump

log_safe_model_dump(
    extra_exclude: set[str] | None = None,
) -> dict[Any, Any]

Return a dict of the model's fields, with any sensitive fields redacted.

Source code in horde_sdk/generic_api/apimodels.py
def log_safe_model_dump(self, extra_exclude: set[str] | None = None) -> dict[Any, Any]:
    """Return a dict of the model's fields, with any sensitive fields redacted."""
    if extra_exclude is None:
        extra_exclude = set()

    if hasattr(self, "model_dump"):
        return self.model_dump(  # type: ignore
            exclude=self.get_sensitive_fields() | self.get_extra_fields_to_exclude_from_log() | extra_exclude,
        )

    logger.warning("Model does not have a model_dump method. Using python native class compatible method.")
    logger.debug(
        "Generally this should not be relied upon. If you're seeing this and you're a developer for the SDK, "
        "consider using pydantic models instead.",
    )
    # Its not a pydantic model, use python native class compatible method
    return {
        key: getattr(self, key)
        for key in self.__dict__
        if key not in self.get_sensitive_fields() | self.get_extra_fields_to_exclude_from_log() | extra_exclude
    }

SharedKeyDeleteRequest

Bases: BaseAIHordeRequest, MessageSpecifiesSharedKeyMixin, APIKeyAllowedInRequestMixin

Request to delete a SharedKey.

This is a privileged operation that requires the user to be the owner, a moderator, or an admin.

Represents a DELETE request to the /v2/sharedkeys/{sharedkey_id} endpoint.

Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
class SharedKeyDeleteRequest(
    BaseAIHordeRequest,
    MessageSpecifiesSharedKeyMixin,
    APIKeyAllowedInRequestMixin,
):
    """Request to delete a SharedKey.

    This is a privileged operation that requires the user to be the owner, a moderator, or an admin.

    Represents a DELETE request to the /v2/sharedkeys/{sharedkey_id} endpoint.
    """

    @override
    @classmethod
    def get_api_model_name(cls) -> str | None:
        return None

    @override
    @classmethod
    def get_http_method(cls) -> HTTPMethod:
        return HTTPMethod.DELETE

    @override
    @classmethod
    def get_api_endpoint_subpath(cls) -> AI_HORDE_API_ENDPOINT_SUBPATH:
        return AI_HORDE_API_ENDPOINT_SUBPATH.v2_sharedkeys

    @override
    @classmethod
    def get_default_success_response_type(cls) -> type[SharedKeyDeleteResponse]:
        return SharedKeyDeleteResponse

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

apikey class-attribute instance-attribute

apikey: str | None = None

Defaults to ANON_API_KEY. See also .is_api_key_required()

sharedkey_id class-attribute instance-attribute

sharedkey_id: SharedKeyID = Field(alias='id')

The shared key ID to use for this request.

accept class-attribute instance-attribute

accept: GenericAcceptTypes = json

The 'accept' header field.

client_agent class-attribute instance-attribute

client_agent: str = Field(
    default=default_bridge_agent_string,
    alias="Client-Agent",
)

The requesting client's agent. You should set this to reflect the name, version and contact information for your client.

get_api_model_name classmethod

get_api_model_name() -> str | None
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_api_model_name(cls) -> str | None:
    return None

get_http_method classmethod

get_http_method() -> HTTPMethod
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_http_method(cls) -> HTTPMethod:
    return HTTPMethod.DELETE

get_api_endpoint_subpath classmethod

get_api_endpoint_subpath() -> AI_HORDE_API_ENDPOINT_SUBPATH
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_api_endpoint_subpath(cls) -> AI_HORDE_API_ENDPOINT_SUBPATH:
    return AI_HORDE_API_ENDPOINT_SUBPATH.v2_sharedkeys

get_default_success_response_type classmethod

get_default_success_response_type() -> (
    type[SharedKeyDeleteResponse]
)
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_default_success_response_type(cls) -> type[SharedKeyDeleteResponse]:
    return SharedKeyDeleteResponse

get_sensitive_fields classmethod

get_sensitive_fields() -> set[str]
Source code in horde_sdk/generic_api/apimodels.py
@override
@classmethod
def get_sensitive_fields(cls) -> set[str]:
    return {"apikey"}

get_extra_fields_to_exclude_from_log

get_extra_fields_to_exclude_from_log() -> set[str]

Return an additional set of fields to exclude from the log_safe_model_dump method.

Source code in horde_sdk/generic_api/apimodels.py
def get_extra_fields_to_exclude_from_log(self) -> set[str]:
    """Return an additional set of fields to exclude from the log_safe_model_dump method."""
    return set()

log_safe_model_dump

log_safe_model_dump(
    extra_exclude: set[str] | None = None,
) -> dict[Any, Any]

Return a dict of the model's fields, with any sensitive fields redacted.

Source code in horde_sdk/generic_api/apimodels.py
def log_safe_model_dump(self, extra_exclude: set[str] | None = None) -> dict[Any, Any]:
    """Return a dict of the model's fields, with any sensitive fields redacted."""
    if extra_exclude is None:
        extra_exclude = set()

    if hasattr(self, "model_dump"):
        return self.model_dump(  # type: ignore
            exclude=self.get_sensitive_fields() | self.get_extra_fields_to_exclude_from_log() | extra_exclude,
        )

    logger.warning("Model does not have a model_dump method. Using python native class compatible method.")
    logger.debug(
        "Generally this should not be relied upon. If you're seeing this and you're a developer for the SDK, "
        "consider using pydantic models instead.",
    )
    # Its not a pydantic model, use python native class compatible method
    return {
        key: getattr(self, key)
        for key in self.__dict__
        if key not in self.get_sensitive_fields() | self.get_extra_fields_to_exclude_from_log() | extra_exclude
    }

is_api_key_required classmethod

is_api_key_required() -> bool

Return whether this endpoint requires an API key.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def is_api_key_required(cls) -> bool:
    """Return whether this endpoint requires an API key."""
    return True

validate_api_key_length

validate_api_key_length(v: str) -> str

Validate that the API key is the correct length, or is the special ANON_API_KEY.

Source code in horde_sdk/generic_api/apimodels.py
@field_validator("apikey", mode="before")
def validate_api_key_length(cls, v: str) -> str:
    """Validate that the API key is the correct length, or is the special ANON_API_KEY."""
    if v is None:
        return ANON_API_KEY
    if v == ANON_API_KEY:
        return v
    if len(v) == 36:
        try:
            uuid.UUID(v)
            return v
        except ValueError as e:
            raise ValueError("API key must be a valid UUID") from e
        return v
    if len(v) != 22:
        raise ValueError("API key must be 22 characters long")
    return v

validate_sharedkey_id

validate_sharedkey_id(
    v: str | SharedKeyID,
) -> SharedKeyID | str

Ensure that the shared key ID is not empty.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
@field_validator("sharedkey_id", mode="before")
def validate_sharedkey_id(cls, v: str | SharedKeyID) -> SharedKeyID | str:
    """Ensure that the shared key ID is not empty."""
    if isinstance(v, str) and v == "":
        logger.warning("Shared key ID is empty")

    return v

get_api_endpoint_url classmethod

get_api_endpoint_url() -> str

Return the endpoint URL, including the path to the specific API action defined by this object.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_api_endpoint_url(cls) -> str:
    """Return the endpoint URL, including the path to the specific API action defined by this object."""
    return url_with_path(base_url=cls.get_api_url(), path=cls.get_api_endpoint_subpath())

get_api_url classmethod

get_api_url() -> str
Source code in horde_sdk/ai_horde_api/apimodels/base.py
@override
@classmethod
def get_api_url(cls) -> str:
    return AI_HORDE_BASE_URL

get_success_status_response_pairs classmethod

get_success_status_response_pairs() -> (
    dict[HTTPStatusCode, type[HordeResponseTypes]]
)

Return a dict of HTTP status codes and the expected HordeResponse.

Defaults to {HTTPStatusCode.OK: cls.get_expected_response_type()}, but may be overridden to support other status codes.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_success_status_response_pairs(
    cls,
) -> dict[HTTPStatusCode, type[HordeResponseTypes]]:
    """Return a dict of HTTP status codes and the expected `HordeResponse`.

    Defaults to `{HTTPStatusCode.OK: cls.get_expected_response_type()}`, but may be overridden to support other
    status codes.
    """
    return {HTTPStatusCode.OK: cls.get_default_success_response_type()}

get_header_fields classmethod

get_header_fields() -> list[str]

Return a list of field names from this request object that should be sent as header fields.

This is in addition to GenericHeaderFields's values, and possibly the API specific class which inherits from GenericHeaderFields, typically found in the horde_sdk.<api_name>_api.metadata module.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_header_fields(cls) -> list[str]:
    """Return a list of field names from this request object that should be sent as header fields.

    This is in addition to `GenericHeaderFields`'s values, and possibly the API specific class
    which inherits from `GenericHeaderFields`, typically found in the `horde_sdk.<api_name>_api.metadata` module.
    """
    return []

get_query_fields classmethod

get_query_fields() -> list[str]

Return a list of field names from this request object that should be sent as query parameters.

This is in addition to GenericQueryFields's values, and possibly the API specific class which inherits from GenericQueryFields, typically found in the horde_sdk.<api_name>_api.metadata module.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_query_fields(cls) -> list[str]:
    """Return a list of field names from this request object that should be sent as query parameters.

    This is in addition to `GenericQueryFields`'s values, and possibly the API specific class
    which inherits from `GenericQueryFields`, typically found in the `horde_sdk.<api_name>_api.metadata` module.
    """
    return []

get_number_of_results_expected

get_number_of_results_expected() -> int

Return the number of (job) results expected from this request.

Defaults to 1, but may be overridden to dynamically change the number of results expected.

This is factored into context management; if the number of results expected is not met, the job is considered unhandled on an exception and followed up on to attempt to close it.

Source code in horde_sdk/generic_api/apimodels.py
def get_number_of_results_expected(self) -> int:
    """Return the number of (job) results expected from this request.

    Defaults to `1`, but may be overridden to dynamically change the number of results expected.

    This is factored into context management; if the number of results expected is not met, the job is considered
    unhandled on an exception and followed up on to attempt to close it.
    """
    return 1

get_requires_follow_up

get_requires_follow_up() -> bool

Return whether this request requires a follow up request(s).

Returns:

  • bool ( bool ) –

    Whether this request requires a follow up request to close the job on the server.

Source code in horde_sdk/generic_api/apimodels.py
def get_requires_follow_up(self) -> bool:
    """Return whether this request requires a follow up request(s).

    Returns:
        bool: Whether this request requires a follow up request to close the job on the server.
    """
    for response_type in self.get_success_status_response_pairs().values():
        if issubclass(response_type, ResponseRequiringFollowUpMixin):
            return True
    return False

SharedKeyModifyRequest

Bases: BaseAIHordeRequest, SharedKeySettings, MessageSpecifiesSharedKeyMixin, APIKeyAllowedInRequestMixin

Request to modify a SharedKey.

This is a privileged operation that requires the user to be the owner, a moderator, or an admin.

Represents a PATCH request to the /v2/sharedkeys/{sharedkey_id} endpoint.

v2 API Model: SharedKeyInput

Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
class SharedKeyModifyRequest(
    BaseAIHordeRequest,
    SharedKeySettings,
    MessageSpecifiesSharedKeyMixin,
    APIKeyAllowedInRequestMixin,
):
    """Request to modify a SharedKey.

    This is a privileged operation that requires the user to be the owner, a moderator, or an admin.

    Represents a PATCH request to the /v2/sharedkeys/{sharedkey_id} endpoint.

    v2 API Model: `SharedKeyInput`
    """

    @override
    @classmethod
    def get_api_model_name(cls) -> str | None:
        return "SharedKeyInput"

    @override
    @classmethod
    def get_http_method(cls) -> HTTPMethod:
        return HTTPMethod.PATCH

    @override
    @classmethod
    def get_api_endpoint_subpath(cls) -> AI_HORDE_API_ENDPOINT_SUBPATH:
        return AI_HORDE_API_ENDPOINT_SUBPATH.v2_sharedkeys

    @override
    @classmethod
    def get_default_success_response_type(cls) -> type[ExpiryStrSharedKeyDetailsResponse]:
        return ExpiryStrSharedKeyDetailsResponse

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

apikey class-attribute instance-attribute

apikey: str | None = None

Defaults to ANON_API_KEY. See also .is_api_key_required()

sharedkey_id class-attribute instance-attribute

sharedkey_id: SharedKeyID = Field(alias='id')

The shared key ID to use for this request.

kudos instance-attribute

kudos: int

The Kudos limit assigned to this key.

name instance-attribute

name: str

The Shared Key Name.

max_image_pixels instance-attribute

max_image_pixels: int

The maximum amount of image pixels this key can generate per job. -1 means unlimited.

max_image_steps instance-attribute

max_image_steps: int

The maximum amount of image steps this key can use per job. -1 means unlimited.

max_text_tokens instance-attribute

max_text_tokens: int

The maximum amount of text tokens this key can generate per job. -1 means unlimited.

expiry class-attribute instance-attribute

expiry: int = Field(default=-1, ge=-1)

The number of days until this key expires. -1 means never expires.

accept class-attribute instance-attribute

accept: GenericAcceptTypes = json

The 'accept' header field.

client_agent class-attribute instance-attribute

client_agent: str = Field(
    default=default_bridge_agent_string,
    alias="Client-Agent",
)

The requesting client's agent. You should set this to reflect the name, version and contact information for your client.

get_api_model_name classmethod

get_api_model_name() -> str | None
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_api_model_name(cls) -> str | None:
    return "SharedKeyInput"

get_http_method classmethod

get_http_method() -> HTTPMethod
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_http_method(cls) -> HTTPMethod:
    return HTTPMethod.PATCH

get_api_endpoint_subpath classmethod

get_api_endpoint_subpath() -> AI_HORDE_API_ENDPOINT_SUBPATH
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_api_endpoint_subpath(cls) -> AI_HORDE_API_ENDPOINT_SUBPATH:
    return AI_HORDE_API_ENDPOINT_SUBPATH.v2_sharedkeys

get_default_success_response_type classmethod

get_default_success_response_type() -> (
    type[ExpiryStrSharedKeyDetailsResponse]
)
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_default_success_response_type(cls) -> type[ExpiryStrSharedKeyDetailsResponse]:
    return ExpiryStrSharedKeyDetailsResponse

get_sensitive_fields classmethod

get_sensitive_fields() -> set[str]
Source code in horde_sdk/generic_api/apimodels.py
@override
@classmethod
def get_sensitive_fields(cls) -> set[str]:
    return {"apikey"}

get_extra_fields_to_exclude_from_log

get_extra_fields_to_exclude_from_log() -> set[str]

Return an additional set of fields to exclude from the log_safe_model_dump method.

Source code in horde_sdk/generic_api/apimodels.py
def get_extra_fields_to_exclude_from_log(self) -> set[str]:
    """Return an additional set of fields to exclude from the log_safe_model_dump method."""
    return set()

log_safe_model_dump

log_safe_model_dump(
    extra_exclude: set[str] | None = None,
) -> dict[Any, Any]

Return a dict of the model's fields, with any sensitive fields redacted.

Source code in horde_sdk/generic_api/apimodels.py
def log_safe_model_dump(self, extra_exclude: set[str] | None = None) -> dict[Any, Any]:
    """Return a dict of the model's fields, with any sensitive fields redacted."""
    if extra_exclude is None:
        extra_exclude = set()

    if hasattr(self, "model_dump"):
        return self.model_dump(  # type: ignore
            exclude=self.get_sensitive_fields() | self.get_extra_fields_to_exclude_from_log() | extra_exclude,
        )

    logger.warning("Model does not have a model_dump method. Using python native class compatible method.")
    logger.debug(
        "Generally this should not be relied upon. If you're seeing this and you're a developer for the SDK, "
        "consider using pydantic models instead.",
    )
    # Its not a pydantic model, use python native class compatible method
    return {
        key: getattr(self, key)
        for key in self.__dict__
        if key not in self.get_sensitive_fields() | self.get_extra_fields_to_exclude_from_log() | extra_exclude
    }

is_api_key_required classmethod

is_api_key_required() -> bool

Return whether this endpoint requires an API key.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def is_api_key_required(cls) -> bool:
    """Return whether this endpoint requires an API key."""
    return True

validate_api_key_length

validate_api_key_length(v: str) -> str

Validate that the API key is the correct length, or is the special ANON_API_KEY.

Source code in horde_sdk/generic_api/apimodels.py
@field_validator("apikey", mode="before")
def validate_api_key_length(cls, v: str) -> str:
    """Validate that the API key is the correct length, or is the special ANON_API_KEY."""
    if v is None:
        return ANON_API_KEY
    if v == ANON_API_KEY:
        return v
    if len(v) == 36:
        try:
            uuid.UUID(v)
            return v
        except ValueError as e:
            raise ValueError("API key must be a valid UUID") from e
        return v
    if len(v) != 22:
        raise ValueError("API key must be 22 characters long")
    return v

validate_sharedkey_id

validate_sharedkey_id(
    v: str | SharedKeyID,
) -> SharedKeyID | str

Ensure that the shared key ID is not empty.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
@field_validator("sharedkey_id", mode="before")
def validate_sharedkey_id(cls, v: str | SharedKeyID) -> SharedKeyID | str:
    """Ensure that the shared key ID is not empty."""
    if isinstance(v, str) and v == "":
        logger.warning("Shared key ID is empty")

    return v

validate_restriction_values classmethod

validate_restriction_values(v: int) -> int

Validate the restriction values.

Parameters:

  • v (int) –

    The restriction value.

Raises:

  • ValueError

    If the restriction value is invalid.

Returns:

  • int ( int ) –

    The restriction value.

Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@field_validator("max_image_pixels", "max_image_steps", "max_text_tokens", mode="before")
@classmethod
def validate_restriction_values(cls, v: int) -> int:
    """Validate the restriction values.

    Args:
        v (int): The restriction value.

    Raises:
        ValueError: If the restriction value is invalid.

    Returns:
        int: The restriction value.
    """
    if v < -1:
        raise ValueError("Restriction values must be -1 or greater.")
    return v

get_api_endpoint_url classmethod

get_api_endpoint_url() -> str

Return the endpoint URL, including the path to the specific API action defined by this object.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_api_endpoint_url(cls) -> str:
    """Return the endpoint URL, including the path to the specific API action defined by this object."""
    return url_with_path(base_url=cls.get_api_url(), path=cls.get_api_endpoint_subpath())

get_api_url classmethod

get_api_url() -> str
Source code in horde_sdk/ai_horde_api/apimodels/base.py
@override
@classmethod
def get_api_url(cls) -> str:
    return AI_HORDE_BASE_URL

get_success_status_response_pairs classmethod

get_success_status_response_pairs() -> (
    dict[HTTPStatusCode, type[HordeResponseTypes]]
)

Return a dict of HTTP status codes and the expected HordeResponse.

Defaults to {HTTPStatusCode.OK: cls.get_expected_response_type()}, but may be overridden to support other status codes.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_success_status_response_pairs(
    cls,
) -> dict[HTTPStatusCode, type[HordeResponseTypes]]:
    """Return a dict of HTTP status codes and the expected `HordeResponse`.

    Defaults to `{HTTPStatusCode.OK: cls.get_expected_response_type()}`, but may be overridden to support other
    status codes.
    """
    return {HTTPStatusCode.OK: cls.get_default_success_response_type()}

get_header_fields classmethod

get_header_fields() -> list[str]

Return a list of field names from this request object that should be sent as header fields.

This is in addition to GenericHeaderFields's values, and possibly the API specific class which inherits from GenericHeaderFields, typically found in the horde_sdk.<api_name>_api.metadata module.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_header_fields(cls) -> list[str]:
    """Return a list of field names from this request object that should be sent as header fields.

    This is in addition to `GenericHeaderFields`'s values, and possibly the API specific class
    which inherits from `GenericHeaderFields`, typically found in the `horde_sdk.<api_name>_api.metadata` module.
    """
    return []

get_query_fields classmethod

get_query_fields() -> list[str]

Return a list of field names from this request object that should be sent as query parameters.

This is in addition to GenericQueryFields's values, and possibly the API specific class which inherits from GenericQueryFields, typically found in the horde_sdk.<api_name>_api.metadata module.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_query_fields(cls) -> list[str]:
    """Return a list of field names from this request object that should be sent as query parameters.

    This is in addition to `GenericQueryFields`'s values, and possibly the API specific class
    which inherits from `GenericQueryFields`, typically found in the `horde_sdk.<api_name>_api.metadata` module.
    """
    return []

get_number_of_results_expected

get_number_of_results_expected() -> int

Return the number of (job) results expected from this request.

Defaults to 1, but may be overridden to dynamically change the number of results expected.

This is factored into context management; if the number of results expected is not met, the job is considered unhandled on an exception and followed up on to attempt to close it.

Source code in horde_sdk/generic_api/apimodels.py
def get_number_of_results_expected(self) -> int:
    """Return the number of (job) results expected from this request.

    Defaults to `1`, but may be overridden to dynamically change the number of results expected.

    This is factored into context management; if the number of results expected is not met, the job is considered
    unhandled on an exception and followed up on to attempt to close it.
    """
    return 1

get_requires_follow_up

get_requires_follow_up() -> bool

Return whether this request requires a follow up request(s).

Returns:

  • bool ( bool ) –

    Whether this request requires a follow up request to close the job on the server.

Source code in horde_sdk/generic_api/apimodels.py
def get_requires_follow_up(self) -> bool:
    """Return whether this request requires a follow up request(s).

    Returns:
        bool: Whether this request requires a follow up request to close the job on the server.
    """
    for response_type in self.get_success_status_response_pairs().values():
        if issubclass(response_type, ResponseRequiringFollowUpMixin):
            return True
    return False

SharedKeyCreateRequest

Bases: BaseAIHordeRequest, SharedKeySettings, APIKeyAllowedInRequestMixin

Request to create a new SharedKey.

Represents a PUT request to the /v2/sharedkeys endpoint.

v2 API Model: SharedKeyInput

Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
class SharedKeyCreateRequest(
    BaseAIHordeRequest,
    SharedKeySettings,
    APIKeyAllowedInRequestMixin,
):
    """Request to create a new SharedKey.

    Represents a PUT request to the /v2/sharedkeys endpoint.

    v2 API Model: `SharedKeyInput`
    """

    @override
    @classmethod
    def get_api_model_name(cls) -> str | None:
        return "SharedKeyInput"

    @override
    @classmethod
    def get_http_method(cls) -> HTTPMethod:
        return HTTPMethod.PUT

    @override
    @classmethod
    def get_api_endpoint_subpath(cls) -> AI_HORDE_API_ENDPOINT_SUBPATH:
        return AI_HORDE_API_ENDPOINT_SUBPATH.v2_sharedkeys_create

    @override
    @classmethod
    def get_default_success_response_type(cls) -> type[ExpiryStrSharedKeyDetailsResponse]:
        return ExpiryStrSharedKeyDetailsResponse

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

apikey class-attribute instance-attribute

apikey: str | None = None

Defaults to ANON_API_KEY. See also .is_api_key_required()

kudos instance-attribute

kudos: int

The Kudos limit assigned to this key.

name instance-attribute

name: str

The Shared Key Name.

max_image_pixels instance-attribute

max_image_pixels: int

The maximum amount of image pixels this key can generate per job. -1 means unlimited.

max_image_steps instance-attribute

max_image_steps: int

The maximum amount of image steps this key can use per job. -1 means unlimited.

max_text_tokens instance-attribute

max_text_tokens: int

The maximum amount of text tokens this key can generate per job. -1 means unlimited.

expiry class-attribute instance-attribute

expiry: int = Field(default=-1, ge=-1)

The number of days until this key expires. -1 means never expires.

accept class-attribute instance-attribute

accept: GenericAcceptTypes = json

The 'accept' header field.

client_agent class-attribute instance-attribute

client_agent: str = Field(
    default=default_bridge_agent_string,
    alias="Client-Agent",
)

The requesting client's agent. You should set this to reflect the name, version and contact information for your client.

get_api_model_name classmethod

get_api_model_name() -> str | None
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_api_model_name(cls) -> str | None:
    return "SharedKeyInput"

get_http_method classmethod

get_http_method() -> HTTPMethod
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_http_method(cls) -> HTTPMethod:
    return HTTPMethod.PUT

get_api_endpoint_subpath classmethod

get_api_endpoint_subpath() -> AI_HORDE_API_ENDPOINT_SUBPATH
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_api_endpoint_subpath(cls) -> AI_HORDE_API_ENDPOINT_SUBPATH:
    return AI_HORDE_API_ENDPOINT_SUBPATH.v2_sharedkeys_create

get_default_success_response_type classmethod

get_default_success_response_type() -> (
    type[ExpiryStrSharedKeyDetailsResponse]
)
Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@override
@classmethod
def get_default_success_response_type(cls) -> type[ExpiryStrSharedKeyDetailsResponse]:
    return ExpiryStrSharedKeyDetailsResponse

get_sensitive_fields classmethod

get_sensitive_fields() -> set[str]
Source code in horde_sdk/generic_api/apimodels.py
@override
@classmethod
def get_sensitive_fields(cls) -> set[str]:
    return {"apikey"}

get_extra_fields_to_exclude_from_log

get_extra_fields_to_exclude_from_log() -> set[str]

Return an additional set of fields to exclude from the log_safe_model_dump method.

Source code in horde_sdk/generic_api/apimodels.py
def get_extra_fields_to_exclude_from_log(self) -> set[str]:
    """Return an additional set of fields to exclude from the log_safe_model_dump method."""
    return set()

log_safe_model_dump

log_safe_model_dump(
    extra_exclude: set[str] | None = None,
) -> dict[Any, Any]

Return a dict of the model's fields, with any sensitive fields redacted.

Source code in horde_sdk/generic_api/apimodels.py
def log_safe_model_dump(self, extra_exclude: set[str] | None = None) -> dict[Any, Any]:
    """Return a dict of the model's fields, with any sensitive fields redacted."""
    if extra_exclude is None:
        extra_exclude = set()

    if hasattr(self, "model_dump"):
        return self.model_dump(  # type: ignore
            exclude=self.get_sensitive_fields() | self.get_extra_fields_to_exclude_from_log() | extra_exclude,
        )

    logger.warning("Model does not have a model_dump method. Using python native class compatible method.")
    logger.debug(
        "Generally this should not be relied upon. If you're seeing this and you're a developer for the SDK, "
        "consider using pydantic models instead.",
    )
    # Its not a pydantic model, use python native class compatible method
    return {
        key: getattr(self, key)
        for key in self.__dict__
        if key not in self.get_sensitive_fields() | self.get_extra_fields_to_exclude_from_log() | extra_exclude
    }

is_api_key_required classmethod

is_api_key_required() -> bool

Return whether this endpoint requires an API key.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def is_api_key_required(cls) -> bool:
    """Return whether this endpoint requires an API key."""
    return True

validate_api_key_length

validate_api_key_length(v: str) -> str

Validate that the API key is the correct length, or is the special ANON_API_KEY.

Source code in horde_sdk/generic_api/apimodels.py
@field_validator("apikey", mode="before")
def validate_api_key_length(cls, v: str) -> str:
    """Validate that the API key is the correct length, or is the special ANON_API_KEY."""
    if v is None:
        return ANON_API_KEY
    if v == ANON_API_KEY:
        return v
    if len(v) == 36:
        try:
            uuid.UUID(v)
            return v
        except ValueError as e:
            raise ValueError("API key must be a valid UUID") from e
        return v
    if len(v) != 22:
        raise ValueError("API key must be 22 characters long")
    return v

validate_restriction_values classmethod

validate_restriction_values(v: int) -> int

Validate the restriction values.

Parameters:

  • v (int) –

    The restriction value.

Raises:

  • ValueError

    If the restriction value is invalid.

Returns:

  • int ( int ) –

    The restriction value.

Source code in horde_sdk/ai_horde_api/apimodels/sharedkeys.py
@field_validator("max_image_pixels", "max_image_steps", "max_text_tokens", mode="before")
@classmethod
def validate_restriction_values(cls, v: int) -> int:
    """Validate the restriction values.

    Args:
        v (int): The restriction value.

    Raises:
        ValueError: If the restriction value is invalid.

    Returns:
        int: The restriction value.
    """
    if v < -1:
        raise ValueError("Restriction values must be -1 or greater.")
    return v

get_api_endpoint_url classmethod

get_api_endpoint_url() -> str

Return the endpoint URL, including the path to the specific API action defined by this object.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_api_endpoint_url(cls) -> str:
    """Return the endpoint URL, including the path to the specific API action defined by this object."""
    return url_with_path(base_url=cls.get_api_url(), path=cls.get_api_endpoint_subpath())

get_api_url classmethod

get_api_url() -> str
Source code in horde_sdk/ai_horde_api/apimodels/base.py
@override
@classmethod
def get_api_url(cls) -> str:
    return AI_HORDE_BASE_URL

get_success_status_response_pairs classmethod

get_success_status_response_pairs() -> (
    dict[HTTPStatusCode, type[HordeResponseTypes]]
)

Return a dict of HTTP status codes and the expected HordeResponse.

Defaults to {HTTPStatusCode.OK: cls.get_expected_response_type()}, but may be overridden to support other status codes.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_success_status_response_pairs(
    cls,
) -> dict[HTTPStatusCode, type[HordeResponseTypes]]:
    """Return a dict of HTTP status codes and the expected `HordeResponse`.

    Defaults to `{HTTPStatusCode.OK: cls.get_expected_response_type()}`, but may be overridden to support other
    status codes.
    """
    return {HTTPStatusCode.OK: cls.get_default_success_response_type()}

get_header_fields classmethod

get_header_fields() -> list[str]

Return a list of field names from this request object that should be sent as header fields.

This is in addition to GenericHeaderFields's values, and possibly the API specific class which inherits from GenericHeaderFields, typically found in the horde_sdk.<api_name>_api.metadata module.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_header_fields(cls) -> list[str]:
    """Return a list of field names from this request object that should be sent as header fields.

    This is in addition to `GenericHeaderFields`'s values, and possibly the API specific class
    which inherits from `GenericHeaderFields`, typically found in the `horde_sdk.<api_name>_api.metadata` module.
    """
    return []

get_query_fields classmethod

get_query_fields() -> list[str]

Return a list of field names from this request object that should be sent as query parameters.

This is in addition to GenericQueryFields's values, and possibly the API specific class which inherits from GenericQueryFields, typically found in the horde_sdk.<api_name>_api.metadata module.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
def get_query_fields(cls) -> list[str]:
    """Return a list of field names from this request object that should be sent as query parameters.

    This is in addition to `GenericQueryFields`'s values, and possibly the API specific class
    which inherits from `GenericQueryFields`, typically found in the `horde_sdk.<api_name>_api.metadata` module.
    """
    return []

get_number_of_results_expected

get_number_of_results_expected() -> int

Return the number of (job) results expected from this request.

Defaults to 1, but may be overridden to dynamically change the number of results expected.

This is factored into context management; if the number of results expected is not met, the job is considered unhandled on an exception and followed up on to attempt to close it.

Source code in horde_sdk/generic_api/apimodels.py
def get_number_of_results_expected(self) -> int:
    """Return the number of (job) results expected from this request.

    Defaults to `1`, but may be overridden to dynamically change the number of results expected.

    This is factored into context management; if the number of results expected is not met, the job is considered
    unhandled on an exception and followed up on to attempt to close it.
    """
    return 1

get_requires_follow_up

get_requires_follow_up() -> bool

Return whether this request requires a follow up request(s).

Returns:

  • bool ( bool ) –

    Whether this request requires a follow up request to close the job on the server.

Source code in horde_sdk/generic_api/apimodels.py
def get_requires_follow_up(self) -> bool:
    """Return whether this request requires a follow up request(s).

    Returns:
        bool: Whether this request requires a follow up request to close the job on the server.
    """
    for response_type in self.get_success_status_response_pairs().values():
        if issubclass(response_type, ResponseRequiringFollowUpMixin):
            return True
    return False