Skip to content

base

The base classes for all AI Horde API requests/responses.

__all__ module-attribute

__all__ = [
    "ActiveModel",
    "ActiveModelLite",
    "BaseAIHordeRequest",
    "ExtraSourceImageEntry",
    "ExtraTextEntry",
    "GenMetadataEntry",
    "ImageGenerateParamMixin",
    "JobRequestMixin",
    "JobResponseMixin",
    "JobSubmitResponse",
    "LorasPayloadEntry",
    "MessageSpecifiesSharedKeyMixin",
    "SingleWarningEntry",
    "TIPayloadEntry",
    "WorkerRequestMixin",
    "WorkerRequestNameMixin",
    "_BaseImageGenerateParamMixin",
]

BaseAIHordeRequest

Bases: HordeRequest

Base class for all AI Horde API requests.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
class BaseAIHordeRequest(HordeRequest):
    """Base class for all AI Horde API requests."""

    @override
    @classmethod
    def get_api_url(cls) -> str:
        return AI_HORDE_BASE_URL

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

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_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_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]
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_http_method abstractmethod classmethod

get_http_method() -> HTTPMethod

Return the HTTP method (verb) this request uses.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
@abc.abstractmethod
def get_http_method(cls) -> HTTPMethod:
    """Return the HTTP method (verb) this request uses."""

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_endpoint_subpath abstractmethod classmethod

get_api_endpoint_subpath() -> GENERIC_API_ENDPOINT_SUBPATH

Return the subpath to the specific API action defined by this object.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
@abc.abstractmethod
def get_api_endpoint_subpath(cls) -> GENERIC_API_ENDPOINT_SUBPATH:
    """Return the subpath to the specific API action defined by this object."""

get_default_success_response_type abstractmethod classmethod

get_default_success_response_type() -> (
    type[HordeResponseTypes]
)

Return the type of the response expected in the ordinary case of success.

Source code in horde_sdk/generic_api/apimodels.py
@classmethod
@abc.abstractmethod
def get_default_success_response_type(cls) -> type[HordeResponseTypes]:
    """Return the `type` of the response expected in the ordinary case of success."""

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

JobRequestMixin

Bases: HordeAPIData

Mix-in class for data relating to any generation jobs.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
class JobRequestMixin(HordeAPIData):
    """Mix-in class for data relating to any generation jobs."""

    id_: GenerationID = Field(alias="id")
    """The UUID for this job. Use this to post the results in the future."""

    @field_validator("id_", mode="before")
    def validate_id(cls, v: str | GenerationID) -> GenerationID | str:
        """Ensure that the job ID is not empty."""
        if isinstance(v, str) and v == "":
            logger.warning("Job ID is empty")
            return GenerationID(root=uuid.uuid4())

        return v

    def __eq__(self, __value: object) -> bool:
        if isinstance(__value, JobRequestMixin):
            return self.id_ == __value.id_
        return False

    def __hash__(self) -> int:
        return hash(JobRequestMixin.__name__) + hash(self.id_)

id_ class-attribute instance-attribute

id_: GenerationID = Field(alias='id')

The UUID for this job. Use this to post the results in the future.

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

validate_id

validate_id(v: str | GenerationID) -> GenerationID | str

Ensure that the job ID is not empty.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
@field_validator("id_", mode="before")
def validate_id(cls, v: str | GenerationID) -> GenerationID | str:
    """Ensure that the job ID is not empty."""
    if isinstance(v, str) and v == "":
        logger.warning("Job ID is empty")
        return GenerationID(root=uuid.uuid4())

    return v

__eq__

__eq__(__value: object) -> bool
Source code in horde_sdk/ai_horde_api/apimodels/base.py
def __eq__(self, __value: object) -> bool:
    if isinstance(__value, JobRequestMixin):
        return self.id_ == __value.id_
    return False

__hash__

__hash__() -> int
Source code in horde_sdk/ai_horde_api/apimodels/base.py
def __hash__(self) -> int:
    return hash(JobRequestMixin.__name__) + hash(self.id_)

JobResponseMixin

Bases: HordeAPIData

Mix-in class for data relating to any generation jobs.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
class JobResponseMixin(HordeAPIData):
    """Mix-in class for data relating to any generation jobs."""

    id_: GenerationID = Field(alias="id")
    """The UUID for this job."""

    @field_validator("id_", mode="before")
    def validate_id(cls, v: str | GenerationID) -> GenerationID | str:
        """Ensure that the job ID is not empty."""
        if isinstance(v, str) and v == "":
            logger.warning("Job ID is empty")
            return GenerationID(root=uuid.uuid4())

        return v

id_ class-attribute instance-attribute

id_: GenerationID = Field(alias='id')

The UUID for this job.

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

validate_id

validate_id(v: str | GenerationID) -> GenerationID | str

Ensure that the job ID is not empty.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
@field_validator("id_", mode="before")
def validate_id(cls, v: str | GenerationID) -> GenerationID | str:
    """Ensure that the job ID is not empty."""
    if isinstance(v, str) and v == "":
        logger.warning("Job ID is empty")
        return GenerationID(root=uuid.uuid4())

    return v

WorkerRequestMixin

Bases: HordeAPIData

Mix-in class for data relating to worker requests.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
class WorkerRequestMixin(HordeAPIData):
    """Mix-in class for data relating to worker requests."""

    worker_id: str | WorkerID
    """The UUID of the worker in question for this request."""

worker_id instance-attribute

worker_id: str | WorkerID

The UUID of the worker in question for this request.

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

WorkerRequestNameMixin

Bases: HordeAPIData

Mix-in class for data relating to worker requests.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
class WorkerRequestNameMixin(HordeAPIData):
    """Mix-in class for data relating to worker requests."""

    worker_name: str
    """The name of the worker in question for this request."""

worker_name instance-attribute

worker_name: str

The name of the worker in question for this request.

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

LorasPayloadEntry

Bases: HordeAPIObjectBaseModel

Represents a single lora parameter.

v2 API Model: ModelPayloadLorasStable

Source code in horde_sdk/ai_horde_api/apimodels/base.py
class LorasPayloadEntry(HordeAPIObjectBaseModel):
    """Represents a single lora parameter.

    v2 API Model: `ModelPayloadLorasStable`
    """

    name: str = Field(min_length=1, max_length=255)
    """The name of the LoRa model to use."""
    model: float = Field(default=1, ge=-5, le=5)
    """The strength of the LoRa against the stable diffusion model."""
    clip: float = Field(default=1, ge=-5, le=5)
    """The strength of the LoRa against the clip model."""
    inject_trigger: str | None = Field(default=None, min_length=1, max_length=30)
    """Any trigger required to activate the LoRa model."""
    is_version: bool = Field(default=False)
    """If true, will treat the lora name as a version ID."""

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

name class-attribute instance-attribute

name: str = Field(min_length=1, max_length=255)

The name of the LoRa model to use.

model class-attribute instance-attribute

model: float = Field(default=1, ge=-5, le=5)

The strength of the LoRa against the stable diffusion model.

clip class-attribute instance-attribute

clip: float = Field(default=1, ge=-5, le=5)

The strength of the LoRa against the clip model.

inject_trigger class-attribute instance-attribute

inject_trigger: str | None = Field(
    default=None, min_length=1, max_length=30
)

Any trigger required to activate the LoRa model.

is_version class-attribute instance-attribute

is_version: bool = Field(default=False)

If true, will treat the lora name as a version ID.

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

get_api_model_name classmethod

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

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
    }

TIPayloadEntry

Bases: HordeAPIObjectBaseModel

Represents a single textual inversion (embedding) parameter.

v2 API Model: ModelPayloadTextualInversionsStable

Source code in horde_sdk/ai_horde_api/apimodels/base.py
class TIPayloadEntry(HordeAPIObjectBaseModel):
    """Represents a single textual inversion (embedding) parameter.

    v2 API Model: `ModelPayloadTextualInversionsStable`
    """

    name: str = Field(min_length=1, max_length=255)
    """The name or ID of the textual inversion model to use."""
    inject_ti: str | None = None
    """Whether to automatically insert the TI into the prompt or negprompt."""
    strength: float = Field(default=1, ge=-5, le=5)
    """The strength to apply the textual inversion model."""

    @field_validator("inject_ti")
    def validate_inject_ti(cls, v: str | None) -> str | None:
        """Ensure that the inject_ti is either 'prompt' or 'negprompt'."""
        if v is None:
            return None
        if v not in ["prompt", "negprompt"]:
            raise ValueError("inject_ti must be either 'prompt' or 'negprompt'")
        return v

    @field_validator("strength")
    def validate_strength(cls, v: float) -> float:
        """Ensure that the strength is non-zero."""
        if v == 0:
            logger.debug("strength should be non-zero")

        return v

    @model_validator(mode="after")
    def strength_only_if_inject_ti(self) -> TIPayloadEntry:
        """Ensure that the strength is only set if the inject_ti is set."""
        if self.strength and self.inject_ti is None:
            logger.debug("strength is only valid when inject_ti is set")
        return self

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

name class-attribute instance-attribute

name: str = Field(min_length=1, max_length=255)

The name or ID of the textual inversion model to use.

inject_ti class-attribute instance-attribute

inject_ti: str | None = None

Whether to automatically insert the TI into the prompt or negprompt.

strength class-attribute instance-attribute

strength: float = Field(default=1, ge=-5, le=5)

The strength to apply the textual inversion model.

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

validate_inject_ti

validate_inject_ti(v: str | None) -> str | None

Ensure that the inject_ti is either 'prompt' or 'negprompt'.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
@field_validator("inject_ti")
def validate_inject_ti(cls, v: str | None) -> str | None:
    """Ensure that the inject_ti is either 'prompt' or 'negprompt'."""
    if v is None:
        return None
    if v not in ["prompt", "negprompt"]:
        raise ValueError("inject_ti must be either 'prompt' or 'negprompt'")
    return v

validate_strength

validate_strength(v: float) -> float

Ensure that the strength is non-zero.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
@field_validator("strength")
def validate_strength(cls, v: float) -> float:
    """Ensure that the strength is non-zero."""
    if v == 0:
        logger.debug("strength should be non-zero")

    return v

strength_only_if_inject_ti

strength_only_if_inject_ti() -> TIPayloadEntry

Ensure that the strength is only set if the inject_ti is set.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
@model_validator(mode="after")
def strength_only_if_inject_ti(self) -> TIPayloadEntry:
    """Ensure that the strength is only set if the inject_ti is set."""
    if self.strength and self.inject_ti is None:
        logger.debug("strength is only valid when inject_ti is set")
    return self

get_api_model_name classmethod

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

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
    }

ExtraSourceImageEntry

Bases: HordeAPIObjectBaseModel

Represents a single extra source image.

v2 API Model: ExtraSourceImage

Source code in horde_sdk/ai_horde_api/apimodels/base.py
class ExtraSourceImageEntry(HordeAPIObjectBaseModel):
    """Represents a single extra source image.

    v2 API Model: `ExtraSourceImage`
    """

    original_url: str | None = None
    """The URL of the original image after it was downloaded."""

    image: str = Field(min_length=1)
    """The URL of the image to download, or the base64 string once downloaded."""
    strength: float = Field(default=1, ge=-5, le=5)
    """The strength to apply to this image on various operations."""

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

original_url class-attribute instance-attribute

original_url: str | None = None

The URL of the original image after it was downloaded.

image class-attribute instance-attribute

image: str = Field(min_length=1)

The URL of the image to download, or the base64 string once downloaded.

strength class-attribute instance-attribute

strength: float = Field(default=1, ge=-5, le=5)

The strength to apply to this image on various operations.

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

get_api_model_name classmethod

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

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
    }

ExtraTextEntry

Bases: HordeAPIObjectBaseModel

Represents a single extra text.

v2 API Model: ExtraText

Source code in horde_sdk/ai_horde_api/apimodels/base.py
class ExtraTextEntry(HordeAPIObjectBaseModel):
    """Represents a single extra text.

    v2 API Model: `ExtraText`
    """

    text: str = Field(min_length=1)
    """Extra text required for this generation."""
    reference: str = Field(min_length=3)
    """Reference pointing to how this text is to be used."""

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

text class-attribute instance-attribute

text: str = Field(min_length=1)

Extra text required for this generation.

reference class-attribute instance-attribute

reference: str = Field(min_length=3)

Reference pointing to how this text is to be used.

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

get_api_model_name classmethod

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

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
    }

SingleWarningEntry

Bases: HordeAPIObjectBaseModel

Represents a single warning.

v2 API Model: RequestSingleWarning

Source code in horde_sdk/ai_horde_api/apimodels/base.py
class SingleWarningEntry(HordeAPIObjectBaseModel):
    """Represents a single warning.

    v2 API Model: `RequestSingleWarning`
    """

    code: WarningCode | str = Field(min_length=1)
    """The code uniquely identifying this warning."""
    message: str = Field(min_length=1)
    """The human-readable description of this warning"""

    @field_validator("code")
    def code_must_be_known(cls, v: str | WarningCode) -> str | WarningCode:
        """Ensure that the warning code is in this list of supported warning codes."""
        if isinstance(v, WarningCode):
            return v
        if v not in WarningCode.__members__ or v not in WarningCode.__members__.values():
            logger.warning(f"Unknown warning code {v}. Is your SDK out of date or did the API change?")

        return v

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

code class-attribute instance-attribute

code: WarningCode | str = Field(min_length=1)

The code uniquely identifying this warning.

message class-attribute instance-attribute

message: str = Field(min_length=1)

The human-readable description of this warning

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

code_must_be_known

code_must_be_known(
    v: str | WarningCode,
) -> str | WarningCode

Ensure that the warning code is in this list of supported warning codes.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
@field_validator("code")
def code_must_be_known(cls, v: str | WarningCode) -> str | WarningCode:
    """Ensure that the warning code is in this list of supported warning codes."""
    if isinstance(v, WarningCode):
        return v
    if v not in WarningCode.__members__ or v not in WarningCode.__members__.values():
        logger.warning(f"Unknown warning code {v}. Is your SDK out of date or did the API change?")

    return v

get_api_model_name classmethod

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

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
    }

ImageGenerateParamMixin

Bases: _BaseImageGenerateParamMixin

Contains basic and api-specific parameters for image generation.

v2 API Model: ModelPayloadRootStable

Source code in horde_sdk/ai_horde_api/apimodels/base.py
class ImageGenerateParamMixin(_BaseImageGenerateParamMixin):
    """Contains basic and api-specific parameters for image generation.

    v2 API Model: `ModelPayloadRootStable`
    """

    model_config = (
        ConfigDict(frozen=True, extra="allow")
        if not os.getenv("TESTS_ONGOING")
        else ConfigDict(frozen=True, extra="forbid")
    )

    seed: str | None = None
    """The seed to use for this generation. If not provided, a random seed will be used."""
    seed_variation: int | None = Field(default=None, ge=1, le=1000)
    """Deprecated."""

    control_type: str | KNOWN_IMAGE_CONTROLNETS | None = None
    """The type of control net type to use."""
    image_is_control: bool | None = None
    """Set to True if the image is a control image."""
    return_control_map: bool | None = None
    """Set to True if you want the ControlNet map returned instead of a generated image."""

    extra_texts: list[ExtraTextEntry] | None = None
    """A list of extra texts and prompts to use in the comfyUI workflow."""
    use_nsfw_censor: bool = False
    """If the request is SFW, and the worker accidentally generates NSFW, it will send back a censored image."""

    # @model_validator(mode="after")
    # def validate_hires_fix(self) -> ImageGenerateParamMixin:
    #     if self.hires_fix and (self.width < 512 or self.height < 512):
    #         raise ValueError("hires_fix is only valid when width and height are both >= 512")
    #     return self

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

    @field_validator("seed")
    def random_seed_if_none(cls, v: str | None) -> str | None:
        """If the seed is None, generate a random seed."""
        if v is None:
            random_seed = str(random.randint(1, 1000000000))
            logger.debug(f"Using random seed ({random_seed})")
            return random_seed

        return v

    @field_validator("control_type")
    def control_type_must_be_known(
        cls,
        v: str | KNOWN_IMAGE_CONTROLNETS | None,
    ) -> str | KNOWN_IMAGE_CONTROLNETS | None:
        """Ensure that the control type is in this list of supported control types."""
        if v is None:
            return None
        if isinstance(v, KNOWN_IMAGE_CONTROLNETS):
            return v

        try:
            KNOWN_IMAGE_CONTROLNETS(v)
        except ValueError:
            logger.warning(f"Unknown control type {v}. Is your SDK out of date or did the API change?")

        return v

model_config class-attribute instance-attribute

model_config = (
    ConfigDict(frozen=True, extra="allow")
    if not getenv("TESTS_ONGOING")
    else ConfigDict(frozen=True, extra="forbid")
)

seed class-attribute instance-attribute

seed: str | None = None

The seed to use for this generation. If not provided, a random seed will be used.

seed_variation class-attribute instance-attribute

seed_variation: int | None = Field(
    default=None, ge=1, le=1000
)

Deprecated.

control_type class-attribute instance-attribute

control_type: str | KNOWN_IMAGE_CONTROLNETS | None = None

The type of control net type to use.

image_is_control class-attribute instance-attribute

image_is_control: bool | None = None

Set to True if the image is a control image.

return_control_map class-attribute instance-attribute

return_control_map: bool | None = None

Set to True if you want the ControlNet map returned instead of a generated image.

extra_texts class-attribute instance-attribute

extra_texts: list[ExtraTextEntry] | None = None

A list of extra texts and prompts to use in the comfyUI workflow.

use_nsfw_censor class-attribute instance-attribute

use_nsfw_censor: bool = False

If the request is SFW, and the worker accidentally generates NSFW, it will send back a censored image.

height class-attribute instance-attribute

height: int = Field(
    default=512, ge=64, le=3072, multiple_of=64
)

The desired output image height.

width class-attribute instance-attribute

width: int = Field(
    default=512, ge=64, le=3072, multiple_of=64
)

The desired output image width.

sampler_name class-attribute instance-attribute

sampler_name: KNOWN_IMAGE_SAMPLERS | str = k_euler

The sampler to use for this generation. Defaults to KNOWN_IMAGE_SAMPLERS.k_lms.

karras class-attribute instance-attribute

karras: bool = True

Set to True if you want to use the Karras scheduling.

cfg_scale class-attribute instance-attribute

cfg_scale: float = Field(default=7.5, ge=0, le=10)

The cfg_scale to use for this generation. Defaults to 7.5.

denoising_strength class-attribute instance-attribute

denoising_strength: float | None = Field(
    default=1, ge=0, le=1
)

The denoising strength to use for this generation. Defaults to 1.

clip_skip class-attribute instance-attribute

clip_skip: int = Field(default=1, ge=1, le=12)

The number of clip layers to skip.

post_processing class-attribute instance-attribute

post_processing: list[
    str
    | KNOWN_UPSCALERS
    | KNOWN_FACEFIXERS
    | KNOWN_MISC_POST_PROCESSORS
] = Field(default_factory=list)

A list of post-processing models to use.

post_processing_order class-attribute instance-attribute

post_processing_order: POST_PROCESSOR_ORDER_TYPE = (
    facefixers_first
)

The order in which to apply post-processing models. Applying upscalers or removing backgrounds before facefixers costs less kudos.

facefixer_strength class-attribute instance-attribute

facefixer_strength: float | None = Field(
    default=None, ge=0, le=1
)

The strength of the facefixer model.

hires_fix class-attribute instance-attribute

hires_fix: bool = False

Set to True if you want to use the hires fix.

hires_fix_denoising_strength class-attribute instance-attribute

hires_fix_denoising_strength: float | None = Field(
    default=None, ge=0, le=1
)

The strength of the denoising for the hires fix second pass.

loras class-attribute instance-attribute

loras: list[LorasPayloadEntry] | None = None

A list of lora parameters to use.

tis class-attribute instance-attribute

tis: list[TIPayloadEntry] | None = None

A list of textual inversion (embedding) parameters to use.

workflow class-attribute instance-attribute

workflow: str | KNOWN_IMAGE_WORKFLOWS | None = None

The specific comfyUI workflow to use.

transparent class-attribute instance-attribute

transparent: bool | None = None

When true, will generate an image with a transparent background

tiling class-attribute instance-attribute

tiling: bool = False

Set to True if you want to use seamless tiling.

special class-attribute instance-attribute

special: dict[Any, Any] | None = None

Reserved for future use.

get_api_model_name classmethod

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

random_seed_if_none

random_seed_if_none(v: str | None) -> str | None

If the seed is None, generate a random seed.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
@field_validator("seed")
def random_seed_if_none(cls, v: str | None) -> str | None:
    """If the seed is None, generate a random seed."""
    if v is None:
        random_seed = str(random.randint(1, 1000000000))
        logger.debug(f"Using random seed ({random_seed})")
        return random_seed

    return v

control_type_must_be_known

control_type_must_be_known(
    v: str | KNOWN_IMAGE_CONTROLNETS | None,
) -> str | KNOWN_IMAGE_CONTROLNETS | None

Ensure that the control type is in this list of supported control types.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
@field_validator("control_type")
def control_type_must_be_known(
    cls,
    v: str | KNOWN_IMAGE_CONTROLNETS | None,
) -> str | KNOWN_IMAGE_CONTROLNETS | None:
    """Ensure that the control type is in this list of supported control types."""
    if v is None:
        return None
    if isinstance(v, KNOWN_IMAGE_CONTROLNETS):
        return v

    try:
        KNOWN_IMAGE_CONTROLNETS(v)
    except ValueError:
        logger.warning(f"Unknown control type {v}. Is your SDK out of date or did the API change?")

    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
    }

post_processors_must_be_known

post_processors_must_be_known(
    v: list[
        str
        | KNOWN_UPSCALERS
        | KNOWN_FACEFIXERS
        | KNOWN_MISC_POST_PROCESSORS
    ],
) -> list[
    str
    | KNOWN_UPSCALERS
    | KNOWN_FACEFIXERS
    | KNOWN_MISC_POST_PROCESSORS
]

Ensure that the post processors are in this list of supported post processors.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
@field_validator("post_processing")
def post_processors_must_be_known(
    cls,
    v: list[str | KNOWN_UPSCALERS | KNOWN_FACEFIXERS | KNOWN_MISC_POST_PROCESSORS],
) -> list[str | KNOWN_UPSCALERS | KNOWN_FACEFIXERS | KNOWN_MISC_POST_PROCESSORS]:
    """Ensure that the post processors are in this list of supported post processors."""
    _valid_types: list[type] = [str, KNOWN_UPSCALERS, KNOWN_FACEFIXERS, KNOWN_MISC_POST_PROCESSORS]
    for post_processor in v:
        if post_processor not in _all_valid_post_processors_names_and_values or (
            type(post_processor) not in _valid_types
        ):
            logger.warning(
                f"Unknown post processor {post_processor}. Is your SDK out of date or did the API change?",
            )
    return v

sampler_name_must_be_known

sampler_name_must_be_known(
    v: str | KNOWN_IMAGE_SAMPLERS,
) -> str | KNOWN_IMAGE_SAMPLERS

Ensure that the sampler name is in this list of supported samplers.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
@field_validator("sampler_name")
def sampler_name_must_be_known(cls, v: str | KNOWN_IMAGE_SAMPLERS) -> str | KNOWN_IMAGE_SAMPLERS:
    """Ensure that the sampler name is in this list of supported samplers."""
    if isinstance(v, KNOWN_IMAGE_SAMPLERS):
        return v

    try:
        KNOWN_IMAGE_SAMPLERS(v)
    except ValueError:
        logger.warning(f"Unknown sampler name {v}. Is your SDK out of date or did the API change?")

    return v

JobSubmitResponse

Bases: HordeResponseBaseModel

Indicates that a generation job was successfully submitted and the amount of kudos gained.

Represents the data returned from the following endpoints and http status codes
  • /v2/generate/text/submit | TextGenerationJobSubmitRequest [POST] -> 200
  • /v2/generate/submit | ImageGenerationJobSubmitRequest [POST] -> 200

v2 API Model: GenerationSubmitted

Source code in horde_sdk/ai_horde_api/apimodels/base.py
class JobSubmitResponse(HordeResponseBaseModel):
    """Indicates that a generation job was successfully submitted and the amount of kudos gained.

    Represents the data returned from the following endpoints and http status codes:
        - /v2/generate/text/submit | TextGenerationJobSubmitRequest [POST] -> 200
        - /v2/generate/submit | ImageGenerationJobSubmitRequest [POST] -> 200

    v2 API Model: `GenerationSubmitted`
    """

    reward: float
    """The amount of kudos gained for submitting this request."""

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

reward instance-attribute

reward: float

The amount of kudos gained for submitting this request.

time_constructed property

time_constructed: float

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

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

get_api_model_name classmethod

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

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
    }

GenMetadataEntry

Bases: HordeAPIObjectBaseModel

Represents a single generation metadata entry.

v2 API Model: GenerationMetadataStable

Source code in horde_sdk/ai_horde_api/apimodels/base.py
class GenMetadataEntry(HordeAPIObjectBaseModel):
    """Represents a single generation metadata entry.

    v2 API Model: `GenerationMetadataStable`
    """

    type_: METADATA_TYPE | str = Field(alias="type")
    """The relevance of the metadata field."""
    value: METADATA_VALUE | str = Field()
    """The value of the metadata field."""
    ref: str | None = Field(default=None, max_length=255)
    """Optionally a reference for the metadata (e.g. a lora ID)"""

    @field_validator("type_")
    def validate_type(cls, v: str | METADATA_TYPE) -> str | METADATA_TYPE:
        """Ensure that the type is in this list of supported types."""
        if isinstance(v, METADATA_TYPE):
            return v
        if isinstance(v, str) and v not in METADATA_TYPE.__members__:
            logger.warning(f"Unknown metadata type {v}. Is your SDK out of date or did the API change?")
        return v

    @field_validator("value")
    def validate_value(cls, v: str | METADATA_VALUE) -> str | METADATA_VALUE:
        """Ensure that the value is in this list of supported values."""
        if isinstance(v, METADATA_VALUE):
            return v
        if isinstance(v, str) and v not in METADATA_VALUE.__members__:
            logger.warning(f"Unknown metadata value {v}. Is your SDK out of date or did the API change?")
        return v

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

type_ class-attribute instance-attribute

type_: METADATA_TYPE | str = Field(alias='type')

The relevance of the metadata field.

value class-attribute instance-attribute

value: METADATA_VALUE | str = Field()

The value of the metadata field.

ref class-attribute instance-attribute

ref: str | None = Field(default=None, max_length=255)

Optionally a reference for the metadata (e.g. a lora ID)

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

validate_type

validate_type(
    v: str | METADATA_TYPE,
) -> str | METADATA_TYPE

Ensure that the type is in this list of supported types.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
@field_validator("type_")
def validate_type(cls, v: str | METADATA_TYPE) -> str | METADATA_TYPE:
    """Ensure that the type is in this list of supported types."""
    if isinstance(v, METADATA_TYPE):
        return v
    if isinstance(v, str) and v not in METADATA_TYPE.__members__:
        logger.warning(f"Unknown metadata type {v}. Is your SDK out of date or did the API change?")
    return v

validate_value

validate_value(
    v: str | METADATA_VALUE,
) -> str | METADATA_VALUE

Ensure that the value is in this list of supported values.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
@field_validator("value")
def validate_value(cls, v: str | METADATA_VALUE) -> str | METADATA_VALUE:
    """Ensure that the value is in this list of supported values."""
    if isinstance(v, METADATA_VALUE):
        return v
    if isinstance(v, str) and v not in METADATA_VALUE.__members__:
        logger.warning(f"Unknown metadata value {v}. Is your SDK out of date or did the API change?")
    return v

get_api_model_name classmethod

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

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
    }

MessageSpecifiesSharedKeyMixin

Bases: HordeAPIData

Mix-in class to describe an endpoint for which you can specify a shared key.

Source code in horde_sdk/ai_horde_api/apimodels/base.py
class MessageSpecifiesSharedKeyMixin(HordeAPIData):
    """Mix-in class to describe an endpoint for which you can specify a shared key."""

    sharedkey_id: SharedKeyID = Field(alias="id")
    """The shared key ID to use for this request."""

    @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

sharedkey_id class-attribute instance-attribute

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

The shared key ID to use for this request.

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

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

ActiveModelLite

Bases: HordeAPIObjectBaseModel

Represents a single active model.

v2 API Model: ActiveModelLite

Source code in horde_sdk/ai_horde_api/apimodels/base.py
class ActiveModelLite(HordeAPIObjectBaseModel):
    """Represents a single active model.

    v2 API Model: `ActiveModelLite`
    """

    count: int | None = Field(
        default=None,
    )
    """How many of workers in this horde are running this model."""
    name: str | None = Field(
        default=None,
    )
    """The Name of a model available by workers in this horde."""

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

count class-attribute instance-attribute

count: int | None = Field(default=None)

How many of workers in this horde are running this model.

name class-attribute instance-attribute

name: str | None = Field(default=None)

The Name of a model available by workers in this horde.

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

get_api_model_name classmethod

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

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
    }

ActiveModel

Bases: ActiveModelLite

Represents a single active model.

v2 API Model: ActiveModel

Source code in horde_sdk/ai_horde_api/apimodels/base.py
class ActiveModel(ActiveModelLite):
    """Represents a single active model.

    v2 API Model: `ActiveModel`
    """

    eta: int | None = Field(
        default=None,
    )
    """Estimated time in seconds for this model's queue to be cleared."""
    jobs: float | None = Field(
        default=None,
    )
    """The job count waiting to be generated by this model."""
    performance: float | None = Field(
        default=None,
    )
    """The average speed of generation for this model."""
    queued: float | None = Field(
        default=None,
    )
    """The amount waiting to be generated by this model."""
    type_: MODEL_TYPE | None = Field(
        examples=[MODEL_TYPE.image, MODEL_TYPE.text],
        alias="type",
    )
    """The model type (text or image)."""

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

eta class-attribute instance-attribute

eta: int | None = Field(default=None)

Estimated time in seconds for this model's queue to be cleared.

jobs class-attribute instance-attribute

jobs: float | None = Field(default=None)

The job count waiting to be generated by this model.

performance class-attribute instance-attribute

performance: float | None = Field(default=None)

The average speed of generation for this model.

queued class-attribute instance-attribute

queued: float | None = Field(default=None)

The amount waiting to be generated by this model.

type_ class-attribute instance-attribute

type_: MODEL_TYPE | None = Field(
    examples=[image, text], alias="type"
)

The model type (text or image).

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

count class-attribute instance-attribute

count: int | None = Field(default=None)

How many of workers in this horde are running this model.

name class-attribute instance-attribute

name: str | None = Field(default=None)

The Name of a model available by workers in this horde.

get_api_model_name classmethod

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

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
    }