pub struct MoldClient { /* private fields */ }Implementations§
Source§impl MoldClient
impl MoldClient
pub fn new(base_url: &str) -> Self
Sourcepub fn with_api_key(base_url: &str, api_key: String) -> Self
pub fn with_api_key(base_url: &str, api_key: String) -> Self
Create a client with an explicit API key for authentication.
pub fn from_env() -> Self
Sourcepub async fn generate_raw(&self, req: &GenerateRequest) -> Result<Vec<u8>>
pub async fn generate_raw(&self, req: &GenerateRequest) -> Result<Vec<u8>>
Generate an image. Returns raw image bytes (PNG or JPEG). The server returns raw bytes, not JSON — callers are responsible for writing the bytes to disk or further processing.
Sourcepub async fn generate(&self, req: GenerateRequest) -> Result<GenerateResponse>
pub async fn generate(&self, req: GenerateRequest) -> Result<GenerateResponse>
Generate an image or video and return the response wrapping the raw bytes.
For video responses the server sends x-mold-video-* metadata headers
alongside the raw video bytes so we can reconstruct VideoData.
pub async fn list_models(&self) -> Result<Vec<ModelInfo>>
pub async fn list_models_extended(&self) -> Result<Vec<ModelInfoExtended>>
Sourcepub fn is_connection_error(err: &Error) -> bool
pub fn is_connection_error(err: &Error) -> bool
Check whether an error is a connection error (e.g. “connection refused”). Useful for deciding whether to fall back to local inference.
Sourcepub fn is_model_not_found(err: &Error) -> bool
pub fn is_model_not_found(err: &Error) -> bool
Check whether an error is a 404 “model not found” from the server. Useful for triggering a server-side pull when the model isn’t downloaded.
Sourcepub async fn generate_stream(
&self,
req: &GenerateRequest,
progress_tx: UnboundedSender<SseProgressEvent>,
) -> Result<Option<GenerateResponse>>
pub async fn generate_stream( &self, req: &GenerateRequest, progress_tx: UnboundedSender<SseProgressEvent>, ) -> Result<Option<GenerateResponse>>
Generate an image via SSE streaming, receiving progress events.
Returns:
Ok(Some(response))— streaming succeededOk(None)— server doesn’t support SSE (endpoint returned 404 with empty body)Err(e)— generation error, model not found, or connection error
Sourcepub async fn pull_model(&self, model: &str) -> Result<String>
pub async fn pull_model(&self, model: &str) -> Result<String>
Ask the server to pull (download) a model. Blocks until the download completes on the server side. The server updates its in-memory config so subsequent generate/load requests can find the model.
Sourcepub async fn shutdown_server(&self) -> Result<()>
pub async fn shutdown_server(&self) -> Result<()>
Request graceful server shutdown.
Sourcepub async fn pull_model_stream(
&self,
model: &str,
progress_tx: UnboundedSender<SseProgressEvent>,
) -> Result<()>
pub async fn pull_model_stream( &self, model: &str, progress_tx: UnboundedSender<SseProgressEvent>, ) -> Result<()>
Pull a model via SSE streaming, receiving download progress events.
Sends Accept: text/event-stream to request SSE from the server.
Falls back to blocking pull if the server doesn’t support SSE.
pub fn host(&self) -> &str
pub async fn unload_model(&self) -> Result<String>
pub async fn server_status(&self) -> Result<ServerStatus>
Sourcepub async fn list_gallery(&self) -> Result<Vec<GalleryImage>>
pub async fn list_gallery(&self) -> Result<Vec<GalleryImage>>
List gallery images from the server’s output directory.
Sourcepub async fn get_gallery_image(&self, filename: &str) -> Result<Vec<u8>>
pub async fn get_gallery_image(&self, filename: &str) -> Result<Vec<u8>>
Download a gallery image by filename.
Sourcepub async fn delete_gallery_image(&self, filename: &str) -> Result<()>
pub async fn delete_gallery_image(&self, filename: &str) -> Result<()>
Delete a gallery image on the server.
Sourcepub async fn get_gallery_thumbnail(&self, filename: &str) -> Result<Vec<u8>>
pub async fn get_gallery_thumbnail(&self, filename: &str) -> Result<Vec<u8>>
Download a gallery thumbnail by filename. Smaller/faster than full image.
Sourcepub async fn expand_prompt(&self, req: &ExpandRequest) -> Result<ExpandResponse>
pub async fn expand_prompt(&self, req: &ExpandRequest) -> Result<ExpandResponse>
Expand a prompt using the server’s LLM prompt expansion endpoint.
Sourcepub async fn upscale(&self, req: &UpscaleRequest) -> Result<UpscaleResponse>
pub async fn upscale(&self, req: &UpscaleRequest) -> Result<UpscaleResponse>
Upscale an image using a super-resolution model on the server.
Sourcepub async fn upscale_stream(
&self,
req: &UpscaleRequest,
progress_tx: UnboundedSender<SseProgressEvent>,
) -> Result<Option<UpscaleResponse>>
pub async fn upscale_stream( &self, req: &UpscaleRequest, progress_tx: UnboundedSender<SseProgressEvent>, ) -> Result<Option<UpscaleResponse>>
Upscale an image via SSE streaming – progress events are sent to progress_tx,
returns the final UpscaleResponse on success.