Expand description
Image-generation modality primitive: generate(prompt) -> image behind a
swappable engine seam.
One dispatch (generate) over two engines:
- local stable-diffusion.cpp (default): forwarded to the resident
sd-server’s OpenAI-compatible
/v1/images/generations(a thin HTTP proxy), lazily started via the host’sImageHost::start_local_engine. - cloud (
openrouter/replicate/fal, selected by a"provider"field in the body): routed through the Gateway’s/v1/images/generationswith the per-attributex-ryu-slot-image-providerheader, so the full firewall/budget/metering pipeline governs the call.
Per the Core-vs-Gateway rule the dispatch is a Core concern (it decides
what runs — which media engine renders the pixels); this crate owns the
reusable image-gen abstraction + routing, while the host couplings it cannot
own — the local sd-server base-url, the Gateway url/token, and lazy-starting
the sd.cpp sidecar — are injected via the narrow ImageHost trait. The
crate has ZERO dependency on apps/core (mirrors the ryu-stt seam).
The generic media proxy/gateway-forward helpers (proxy,
forward_to_gateway, cloud_provider, media_client) are pub so the
sibling video data path (which stays in Core, out of this crate’s image
scope) reuses the same routing mechanics rather than duplicating them.
Constants§
- CLOUD_
PROVIDERS - Cloud media providers routed through the Gateway (governed, metered) rather
than the local stable-diffusion.cpp engine. A request selects one via a
"provider"field in the body; anything else (or absent) uses the local engine, so the default local path is unchanged.
Traits§
- Image
Host - Narrow host seam for image generation: the couplings the crate cannot own
because they read Core config/sidecar state (the local sd-server base-url, the
Gateway url + token, and lazy-starting the off-by-default sd.cpp sidecar). Core
implements this in
apps/core/src/image_host.rs.
Functions§
- cloud_
provider - Returns the normalized cloud provider id when the body selects one, else
None(⇒ the local sd-server path). - forward_
to_ gateway - Forward a media request to the Gateway, routing to
providervia the per-request slot header formodality(image/video). The Gateway runs the full firewall/budget/metering pipeline and returns a normalized body. - generate
- Text-to-image dispatch: validate
prompt, default a single-image count, then route to the Gateway (cloud provider selected) or the local sd-server engine. This is the reusable image-gen entry; Core’sPOST /api/images/generatehandler is a thin wrapper over it, injectingImageHost. - media_
client - Diffusion on CPU can take minutes; use a generous client timeout independent
of the short-lived shared
ServerStateclient. - proxy
- Forward a JSON body to a media-engine endpoint (
{base_url}{endpoint}) and pass the response through.base_urlis the local sd-server base (ImageHost::sd_base_url).
Type Aliases§
- Media
Response - A media data-path response: the HTTP status code and the JSON body. Core maps
the
u16back to anaxumStatusCodeand wraps the body inJson, so the wire behavior is byte-identical to the pre-extraction handlers.