apimodels
API data model bases applicable across all (or many) horde APIs.
HordeResponseTypes
module-attribute
A type hint for any type of the valid horde response models.
__all__
module-attribute
__all__ = [
"APIKeyAllowedInRequestMixin",
"ContainsMessageResponseMixin",
"ContainsWarningsResponseMixin",
"HordeAPIData",
"HordeAPIMessage",
"HordeAPIObject",
"HordeAPIObjectBaseModel",
"HordeRequest",
"HordeResponse",
"HordeResponseBaseModel",
"HordeResponseRootModel",
"HordeResponseTypes",
"MessageSpecifiesUserIDMixin",
"RequestErrorResponse",
"RequestSingleWarning",
"RequestUsesWorkerMixin",
"ResponseRequiringDownloadMixin",
"ResponseRequiringFollowUpMixin",
"ResponseWithProgressMixin",
]
HordeAPIObject
Bases: ABC
Base class for all Horde API data models, requests, or responses.
This is an abstract class that you probably shouldn't inherit from directly. Instead, inherit from one of the subclasses defined in this module.
Requests generally would inherit from HordeRequest, responses from HordeResponse, and data models from
HordeAPIObjectBaseModel (if it appears on the API as a published model) or HordeAPIDataObject (if it is a
data object that is not specifically defined by the API docs, such as an intermediate class or an anonymous model).
Source code in horde_sdk/generic_api/apimodels.py
get_api_model_name
abstractmethod
classmethod
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_extra_fields_to_exclude_from_log
Return an additional set of fields to exclude from the log_safe_model_dump method.
log_safe_model_dump
Return a dict of the model's fields, with any sensitive fields redacted.
Source code in horde_sdk/generic_api/apimodels.py
HordeAPIObjectBaseModel
Bases: HordeAPIObject, BaseModel
Base class for all Horde API data models (leveraging pydantic).
Source code in horde_sdk/generic_api/apimodels.py
model_config
class-attribute
instance-attribute
get_api_model_name
abstractmethod
classmethod
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_extra_fields_to_exclude_from_log
Return an additional set of fields to exclude from the log_safe_model_dump method.
log_safe_model_dump
Return a dict of the model's fields, with any sensitive fields redacted.
Source code in horde_sdk/generic_api/apimodels.py
HordeAPIData
Bases: BaseModel
Base class for all Horde API data models which appear as objects within other data models.
These are objects which are not specifically defined by the API docs, but (logically or otherwise) are returned by the API. Occasionally, objects derived from this class may also be used as a mixin to compose other models.
Source code in horde_sdk/generic_api/apimodels.py
HordeAPIMessage
Bases: HordeAPIObject
Represents any request or response from any Horde API.
Source code in horde_sdk/generic_api/apimodels.py
get_api_model_name
abstractmethod
classmethod
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_extra_fields_to_exclude_from_log
Return an additional set of fields to exclude from the log_safe_model_dump method.
log_safe_model_dump
Return a dict of the model's fields, with any sensitive fields redacted.
Source code in horde_sdk/generic_api/apimodels.py
HordeResponse
Bases: HordeAPIMessage
Represents any response from any Horde API.
Source code in horde_sdk/generic_api/apimodels.py
time_constructed
property
The time the model was constructed (in epoch time).
get_api_model_name
abstractmethod
classmethod
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_extra_fields_to_exclude_from_log
Return an additional set of fields to exclude from the log_safe_model_dump method.
log_safe_model_dump
Return a dict of the model's fields, with any sensitive fields redacted.
Source code in horde_sdk/generic_api/apimodels.py
HordeResponseRootModel
Bases: RootModel[T], HordeResponse
Base class for all Horde API response data models which model another data type (leveraging pydantic).
A typical example for using this class would be responses which are a list of another data type. Define subclasses of this class with the type of the data model as the type argument.
For example:
Source code in horde_sdk/generic_api/apimodels.py
model_config
class-attribute
instance-attribute
time_constructed
property
The time the model was constructed (in epoch time).
get_api_model_name
abstractmethod
classmethod
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_extra_fields_to_exclude_from_log
Return an additional set of fields to exclude from the log_safe_model_dump method.
log_safe_model_dump
Return a dict of the model's fields, with any sensitive fields redacted.
Source code in horde_sdk/generic_api/apimodels.py
HordeResponseBaseModel
Bases: HordeResponse, BaseModel
Base class for all Horde API response data models (leveraging pydantic).
Source code in horde_sdk/generic_api/apimodels.py
model_config
class-attribute
instance-attribute
time_constructed
property
The time the model was constructed (in epoch time).
get_api_model_name
abstractmethod
classmethod
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_extra_fields_to_exclude_from_log
Return an additional set of fields to exclude from the log_safe_model_dump method.
log_safe_model_dump
Return a dict of the model's fields, with any sensitive fields redacted.
Source code in horde_sdk/generic_api/apimodels.py
ResponseRequiringFollowUpMixin
Bases: ABC
Represents any response from any Horde API which requires a follow up request of some kind.
Source code in horde_sdk/generic_api/apimodels.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
get_follow_up_returned_params
abstractmethod
Return the information required from this response to submit a follow up request.
Note that this dict uses the alias field names (as seen on the API), not the python field names.
GenerationIDs will be returned as {"id": "00000000-0000-0000-0000-000000000000"} instead of
{"id_": "00000000-0000-0000-0000-000000000000"}.
Returns:
-
list[dict[str, Any]]–list[dict[str, object]]: A list of dicts of parameter names and values for each follow up request.
Source code in horde_sdk/generic_api/apimodels.py
get_follow_up_extra_params
Return any additional information required from this response to submit a follow up request.
Source code in horde_sdk/generic_api/apimodels.py
get_follow_up_all_params
Return the required inf from this response to submit any follow up requests warranted from this response.
Note that this dict uses the alias field names (as seen on the API), not the python field names.
get_follow_up_failure_cleanup_params is not included.
This is used for context management.
Returns:
-
list[dict[str, object]]–list[dict[str, object]]: A list of dicts of parameter names and values for each follow up request.
Source code in horde_sdk/generic_api/apimodels.py
get_follow_up_default_request_type
abstractmethod
classmethod
get_follow_up_failure_cleanup_request_type
abstractmethod
classmethod
Return the request type for this response to clean up after a failed follow up request.
Defaults to None, meaning no cleanup request is needed.
Source code in horde_sdk/generic_api/apimodels.py
get_follow_up_failure_cleanup_params
Return any extra information required from this response to clean up after a failed follow up request.
Note that this dict uses the alias field names (as seen on the API), not the python field names.
This is used for context management.
Source code in horde_sdk/generic_api/apimodels.py
get_follow_up_failure_cleanup_request
Return the request for this response to clean up after a failed follow up request.
Source code in horde_sdk/generic_api/apimodels.py
get_follow_up_request_types
classmethod
Return a list of all the possible follow up request types for this response.
ignore_failure
Return if the object is in a state which doesn't require failure follow up.
does_target_request_follow_up
Return whether the target_request would follow up on this request.
Parameters:
-
target_request(HordeRequest) –The request to check if it would follow up on this request.
Returns:
-
bool(bool) –Whether the
target_requestwould follow up on this request.
Source code in horde_sdk/generic_api/apimodels.py
ResponseWithProgressMixin
Bases: HordeAPIData
Represents any response from any Horde API which contains progress information.
Source code in horde_sdk/generic_api/apimodels.py
model_config
class-attribute
instance-attribute
is_job_complete
abstractmethod
Return whether the job is complete.
Parameters:
-
number_of_result_expected(int) –The number of results expected from the job.
Returns:
-
bool(bool) –Whether the job is complete.
Source code in horde_sdk/generic_api/apimodels.py
is_job_possible
abstractmethod
Return whether the job is possible.
Returns:
-
bool(bool) –Whether the job is possible.
is_final_follow_up
classmethod
get_finalize_success_request_type
abstractmethod
classmethod
Return the request type for this response to finalize the job on success, or None if not needed.
ResponseRequiringDownloadMixin
Bases: HordeAPIData
Represents any response which may require downloading additional data.
Source code in horde_sdk/generic_api/apimodels.py
model_config
class-attribute
instance-attribute
download_file_as_base64
async
Download a file and return the value as a base64 string.
Source code in horde_sdk/generic_api/apimodels.py
download_file_to_field_as_base64
async
download_file_to_field_as_base64(
client_session: ClientSession, url: str, field_name: str
) -> None
Download a file from a URL and save it to the field.
Parameters:
-
client_session(ClientSession) –The aiohttp client session to use for the download.
-
url(str) –The URL to download the file from.
-
field_name(str) –The name of the field to save the file to.
Source code in horde_sdk/generic_api/apimodels.py
async_download_additional_data
abstractmethod
async
Asynchronously download any additional data required for this response.
download_additional_data
abstractmethod
ContainsMessageResponseMixin
Bases: HordeAPIData
Represents any response from any Horde API which contains a message.
Source code in horde_sdk/generic_api/apimodels.py
RequestSingleWarning
Bases: HordeAPIObjectBaseModel
Represents a single warning from the API.
Source code in horde_sdk/generic_api/apimodels.py
message
class-attribute
instance-attribute
A message from the API. This is typically an error or warning message, but may also be informational.
code
class-attribute
instance-attribute
The code associated with this warning.
model_config
class-attribute
instance-attribute
get_api_model_name
classmethod
get_sensitive_fields
classmethod
get_extra_fields_to_exclude_from_log
Return an additional set of fields to exclude from the log_safe_model_dump method.
log_safe_model_dump
Return a dict of the model's fields, with any sensitive fields redacted.
Source code in horde_sdk/generic_api/apimodels.py
ContainsWarningsResponseMixin
Bases: HordeAPIData
Represents any response from any Horde API which contains warnings.
Source code in horde_sdk/generic_api/apimodels.py
warnings
class-attribute
instance-attribute
A list of warnings from the API. This is typically an error or warning message, but may also be informational.
RequestErrorResponse
Bases: HordeResponseBaseModel, ContainsMessageResponseMixin
The catch all error response for any request to any Horde API.
v2 API Model: RequestError
Source code in horde_sdk/generic_api/apimodels.py
object_data
class-attribute
instance-attribute
This is a catch all for any additional data that may be returned by the API relevant to the error.
rc
class-attribute
instance-attribute
The return code from the API which maps to a reason for the error.
model_config
class-attribute
instance-attribute
message
class-attribute
instance-attribute
A message from the API. This is typically an error or warning message, but may also be informational.
time_constructed
property
The time the model was constructed (in epoch time).
get_api_model_name
classmethod
get_sensitive_fields
classmethod
get_extra_fields_to_exclude_from_log
Return an additional set of fields to exclude from the log_safe_model_dump method.
log_safe_model_dump
Return a dict of the model's fields, with any sensitive fields redacted.
Source code in horde_sdk/generic_api/apimodels.py
HordeRequest
Bases: HordeAPIMessage, BaseModel
Represents any request to any Horde API.
Source code in horde_sdk/generic_api/apimodels.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 | |
model_config
class-attribute
instance-attribute
accept
class-attribute
instance-attribute
The 'accept' header field.
client_agent
class-attribute
instance-attribute
The requesting client's agent. You should set this to reflect the name, version and contact information for your client.
get_http_method
abstractmethod
classmethod
get_api_endpoint_url
classmethod
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
get_api_url
abstractmethod
classmethod
get_api_endpoint_subpath
abstractmethod
classmethod
Return the subpath to the specific API action defined by this object.
get_default_success_response_type
abstractmethod
classmethod
Return the type of the response expected in the ordinary case of success.
get_success_status_response_pairs
classmethod
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
get_header_fields
classmethod
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
get_query_fields
classmethod
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
get_number_of_results_expected
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
get_requires_follow_up
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
get_sensitive_fields
classmethod
get_api_model_name
abstractmethod
classmethod
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_extra_fields_to_exclude_from_log
Return an additional set of fields to exclude from the log_safe_model_dump method.
log_safe_model_dump
Return a dict of the model's fields, with any sensitive fields redacted.
Source code in horde_sdk/generic_api/apimodels.py
APIKeyAllowedInRequestMixin
Bases: HordeAPIObjectBaseModel
Mix-in class to describe an endpoint which may require authentication.
Source code in horde_sdk/generic_api/apimodels.py
apikey
class-attribute
instance-attribute
Defaults to ANON_API_KEY. See also .is_api_key_required()
model_config
class-attribute
instance-attribute
is_api_key_required
classmethod
validate_api_key_length
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
get_api_model_name
abstractmethod
classmethod
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_extra_fields_to_exclude_from_log
Return an additional set of fields to exclude from the log_safe_model_dump method.
log_safe_model_dump
Return a dict of the model's fields, with any sensitive fields redacted.
Source code in horde_sdk/generic_api/apimodels.py
MessageSpecifiesUserIDMixin
Bases: HordeAPIData
Mix-in class to describe an endpoint for which you can specify a user.
Source code in horde_sdk/generic_api/apimodels.py
user_id
instance-attribute
The user's ID, as a str, but only containing numeric values.
model_config
class-attribute
instance-attribute
user_id_is_numeric
Check if the ID is a numeric string.
The API endpoint expects a string, but the only valid values would be numbers only.
Source code in horde_sdk/generic_api/apimodels.py
RequestUsesWorkerMixin
Bases: HordeAPIData
Mix-in class to describe an endpoint for which you can specify workers.
Source code in horde_sdk/generic_api/apimodels.py
trusted_workers
class-attribute
instance-attribute
When true, only trusted workers will serve this request. When False, Evaluating workers will also be used which can increase speed but adds more risk!
slow_workers
class-attribute
instance-attribute
When True, allows slower workers to pick up this request. Disabling this incurs an extra kudos cost.
extra_slow_workers
class-attribute
instance-attribute
When True, allows extra slow workers to pick up this request.
workers
class-attribute
instance-attribute
A list of worker IDs to use for this request. If empty, any worker can pick up the request. Using this incurs and extra kudos cost.
worker_blacklist
class-attribute
instance-attribute
If true, the worker list will be treated as a blacklist instead of a whitelist.
validated_backends
class-attribute
instance-attribute
When true, only inference backends that are validated by the AI Horde devs will serve this request. When False, non-validated backends will also be used which can increase speed but you may end up with unexpected results.
style
class-attribute
instance-attribute
The style ID to use for the generation.
dry_run
class-attribute
instance-attribute
If true, the request will not be processed, but will return a response with the estimated kudos cost.
webhook
class-attribute
instance-attribute
Provide a URL where the AI Horde will send a POST call after each delivered generation. The request will include the details of the job as well as the request ID.
allow_downgrade
class-attribute
instance-attribute
If true, the request can be modified to lesser parameters if the original request is too expensive.
proxied_account
class-attribute
instance-attribute
The account this request is being proxied for. This requires the sending API to be a service account.
disable_batching
class-attribute
instance-attribute
When true, This request will not use batching. This will allow you to retrieve accurate seeds. Feature is restricted to Trusted users and Patreons.