shared
httpx_client
module-attribute
PathVariables
Bases: StrEnum
Path variables used in the router.
Source code in src/horde_model_reference/service/shared.py
RouteNames
Bases: StrEnum
Route names used in the router.
Source code in src/horde_model_reference/service/shared.py
get_text_generation_reference
class-attribute
instance-attribute
update_image_generation_model
class-attribute
instance-attribute
update_text_generation_model
class-attribute
instance-attribute
get_legacy_category_last_updated
class-attribute
instance-attribute
get_legacy_category_metadata
class-attribute
instance-attribute
get_v2_category_last_updated
class-attribute
instance-attribute
RouteRegistry
Registry for routes.
Routes are stored with a composite key of (prefix, route_name) to support multiple API versions (v1, v2) with overlapping route names.
Source code in src/horde_model_reference/service/shared.py
__init__
register_route
Register a route with its path.
Parameters:
-
prefix(str) –The prefix to use for the route (e.g., "/model_references/v1").
-
route_name(RouteNames) –The name of the route to register.
-
path(str) –The path of the route.
Source code in src/horde_model_reference/service/shared.py
url_for
Get the URL for a registered route.
Parameters:
-
route_name(RouteNames) –The name of the route to get the URL for.
-
path_params(dict[str, str]) –The path parameters to include in the URL.
-
prefix(str | None) –The API prefix (e.g., "/model_references/v2"). If None, defaults to v2_prefix for backward compatibility.
Returns:
-
str(str) –The complete URL path with parameters substituted.
Raises:
-
ValueError–If the route is not registered.
Source code in src/horde_model_reference/service/shared.py
Operation
Bases: StrEnum
CRUD operation types.
Source code in src/horde_model_reference/service/shared.py
HordeUserContext
dataclass
Immutable details about the authenticated Horde user.
Source code in src/horde_model_reference/service/shared.py
APIKeyInvalidException
Bases: HTTPException
Exception raised when an API key is invalid.
Source code in src/horde_model_reference/service/shared.py
__init__
ErrorDetail
Bases: BaseModel
Detail about a specific error.
Source code in src/horde_model_reference/service/shared.py
ErrorResponse
Bases: BaseModel
Standardized error response.
Source code in src/horde_model_reference/service/shared.py
auth_against_horde
async
auth_against_horde(
apikey: str,
client: AsyncClient,
*,
allowed_user_ids: Collection[str] | None = None,
) -> HordeUserContext | None
Authenticate the provided API key against the AI-Horde.
This uses the endpoint defined by AI_HORDE_URL by AIHordeClientSettings in haidra_core.
Parameters:
-
apikey(str) –The API key to authenticate.
-
client(AsyncClient) –The HTTP client to use for the request.
-
allowed_user_ids(Collection[str] | None, default:None) –Optional allowlist of Horde user IDs permitted for the caller.
Returns:
-
HordeUserContext | None–HordeUserContext | None: User details if authentication is successful, None otherwise.
Raises:
-
HTTPException–503 if the Horde auth service is unreachable or times out.
Source code in src/horde_model_reference/service/shared.py
_normalize_ids
_fallback_allowed_users
Return an empty set and log a warning when no allowlist is configured.
Fails closed: if no allowlist is configured, no users are authorized.
Source code in src/horde_model_reference/service/shared.py
_queue_requestor_allowlist
Source code in src/horde_model_reference/service/shared.py
_queue_approver_allowlist
Source code in src/horde_model_reference/service/shared.py
authenticate_queue_requestor
async
Authenticate a queue requestor using the configured allowlist.
Raises:
-
APIKeyInvalidException–If no allowlist is configured or the user is not authorized.
-
HTTPException–503 if the Horde auth service is unreachable.
Source code in src/horde_model_reference/service/shared.py
authenticate_queue_approver
async
Authenticate a queue approver using the configured allowlist.
Raises:
-
APIKeyInvalidException–If no allowlist is configured or the user is not authorized.
-
HTTPException–503 if the Horde auth service is unreachable.
Source code in src/horde_model_reference/service/shared.py
get_user_roles
async
Authenticate a user and determine their roles based on configured allowlists.
This function authenticates the user without enforcing any specific role requirement, then checks which roles the user has been granted.
Parameters:
-
apikey(str) –The API key to authenticate.
Returns:
-
HordeUserContext | None–A tuple of (user_context, roles) where:
-
set[str]–- user_context: The authenticated user details, or None if authentication failed.
-
tuple[HordeUserContext | None, set[str]]–- roles: A set of role names the user has (e.g., {'approver', 'requestor'}).
Source code in src/horde_model_reference/service/shared.py
validate_model_name
Reject model names that are empty, whitespace-only, or contain path separators.
Raises:
-
HTTPException–422 if the model name is invalid.
Source code in src/horde_model_reference/service/shared.py
get_model_reference_manager
Dependency helper that returns the singleton model reference manager.
assert_canonical_write_enabled
assert_canonical_write_enabled(
manager: ModelReferenceManager,
*,
canonical_format: CanonicalFormat,
) -> None
Ensure that writes are attempted only when the canonical format allows them.
Source code in src/horde_model_reference/service/shared.py
assert_pending_queue_write_enabled
Ensure pending-queue operations are allowed for the active canonical format.