app
FastAPI application factory with lifespan management and CORS configuration.
_API_DESCRIPTION
module-attribute
_API_DESCRIPTION = "\nThe **Horde Model Reference API** is the authoritative source of AI model metadata for the\n[AI-Horde](https://aihorde.net) ecosystem. It serves the curated lists of image, text, and\nutility models (CLIP, ControlNet, ESRGAN, …) that workers download and that clients display.\n\n### Who uses this API\n\n- **Workers & clients** read model references - either directly over HTTP or via the\n `horde-model-reference` Python library running in REPLICA mode (which calls this same API,\n falling back to GitHub if the PRIMARY is unreachable).\n- **The AI-Horde backend** runs this service in PRIMARY mode at\n [`models.aihorde.net`](https://models.aihorde.net/api/docs) as the canonical source.\n\n### Two API versions\n\n- **v2** (`/model_references/v2`) - the current format, with search, per-model retrieval,\n statistics, and the full text-model grouping toolkit. Prefer this for new integrations.\n- **v1** (`/model_references/v1`) - the legacy GitHub-compatible format, retained unchanged for\n backward compatibility with existing AI-Horde workers.\n\nBoth versions are readable regardless of deployment configuration. **Reads are open; writes are\nnot.** Write operations require a PRIMARY deployment and a valid `apikey`, and they are not\napplied immediately - they enter a [pending queue](https://models.aihorde.net/api/docs) for\ntwo-person review (propose -> approve -> apply).\n\n### Discovering capabilities\n\nCall [`GET /replicate_mode`](#operations-default-replicate_mode_replicate_mode_get) on startup to\nlearn whether an instance is writable and which canonical format it serves.\n\nFull documentation, tutorials, and guides: <https://github.com/Haidra-Org/horde-model-reference>\n"
_OPENAPI_TAGS
module-attribute
_OPENAPI_TAGS = [
{
"name": "v2",
"description": "Current model-reference format: reads, CRUD, per-model retrieval, and metadata.",
},
{
"name": "v1",
"description": "Legacy GitHub-compatible format, retained unchanged for existing AI-Horde workers.",
},
{
"name": "search",
"description": "Filter, sort, and paginate models within a category or across all categories.",
},
{
"name": "statistics",
"description": "Aggregated per-category counts, baseline/tag distributions, and download statistics.",
},
{
"name": "deletion-risk",
"description": "Live-usage-informed risk analysis identifying models that are candidates for removal.",
},
{
"name": "text_utils",
"description": "Text-generation grouping toolkit: name parsing/composition, groups, aliases, families, and naming schemas.",
},
{
"name": "pending_queue",
"description": "Propose -> approve -> apply workflow for model changes on PRIMARY deployments.",
},
{
"name": "audit",
"description": "Read-only history of pending-queue batches and their net effect.",
},
{
"name": "metadata",
"description": "Per-category last-updated timestamps for change detection by REPLICA clients.",
},
{
"name": "user",
"description": "Authenticated user identity and pending-queue roles (requestor/approver).",
},
]
app
module-attribute
app = FastAPI(
root_path="/api",
lifespan=lifespan,
title="Horde Model Reference API",
summary="Authoritative AI model metadata for the AI-Horde ecosystem.",
description=_API_DESCRIPTION,
version=_SERVICE_VERSION,
openapi_tags=_OPENAPI_TAGS,
contact={
"name": "Haidra-Org / AI-Horde",
"url": "https://github.com/Haidra-Org/horde-model-reference",
},
license_info={
"name": "AGPL-3.0",
"url": "https://www.gnu.org/licenses/agpl-3.0.en.html",
},
servers=[
{
"url": "https://models.aihorde.net/api",
"description": "Public PRIMARY deployment",
},
{
"url": "http://localhost:19800/api",
"description": "Local development server",
},
],
)
AIHordeStatus
Bases: BaseModel
Status of the external AI Horde API connection.
Source code in src/horde_model_reference/service/app.py
HeartbeatResponse
Bases: BaseModel
Enhanced heartbeat response with external service status.
Source code in src/horde_model_reference/service/app.py
lifespan
async
Manage application lifespan events.
Starts background cache hydration on startup and stops it on shutdown.
Source code in src/horde_model_reference/service/app.py
read_root
async
Return a welcome message pointing to the interactive documentation.
Source code in src/horde_model_reference/service/app.py
heartbeat
async
Heartbeat endpoint to check the service status.
Returns overall service status and the state of the external AI Horde API
connection. When the AI Horde API is unreachable, ai_horde.degraded is
True and ai_horde.seconds_until_retry indicates when the next probe
request will be attempted.
Source code in src/horde_model_reference/service/app.py
replicate_mode
async
Get backend configuration and capabilities.
Returns information about the backend's replication mode, canonical format, and whether write operations are supported.
Clients should use this endpoint on startup to determine: - Whether the backend supports write operations (writable=True) - Which API version to use for CRUD operations (based on canonical_format)
Note: For backward compatibility, this endpoint path is retained but now returns a richer BackendInfo response instead of just the ReplicateMode.