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 fn has_api_key(&self) -> bool
pub fn has_api_key(&self) -> bool
Whether this client actually installed a non-empty API-key header.
Sourcepub async fn create_reference_upload_session(
&self,
request: &ReferenceUploadSessionRequest,
) -> Result<ReferenceUploadSessionResponse>
pub async fn create_reference_upload_session( &self, request: &ReferenceUploadSessionRequest, ) -> Result<ReferenceUploadSessionResponse>
Create a request-bound MiniMax H3 reference upload session.
The server applies authentication and legal activation before it allocates staging. Error bodies (including HTTP 451 policy details) are retained verbatim for callers instead of being collapsed to a generic reqwest status error.
Sourcepub async fn upload_reference_file(
&self,
handle: &str,
path: &Path,
mime_type: &str,
) -> Result<ReferenceUploadCompleteResponse>
pub async fn upload_reference_file( &self, handle: &str, path: &Path, mime_type: &str, ) -> Result<ReferenceUploadCompleteResponse>
Stream one local reference file through a one-use bearer handle.
The handle stays in a header, while the opened file’s exact length is
sent as Content-Length. ReaderStream keeps large video references
out of process-sized buffers; the server independently hashes, probes,
and checks the declared descriptor before admission.
Sourcepub async fn upload_reference_open_file(
&self,
handle: &str,
file: File,
mime_type: &str,
) -> Result<ReferenceUploadCompleteResponse>
pub async fn upload_reference_open_file( &self, handle: &str, file: File, mime_type: &str, ) -> Result<ReferenceUploadCompleteResponse>
Stream an already-open reference file through a one-use bearer handle.
Keeping the descriptor probe and upload tied to clones of the same file descriptor prevents a path or symlink replacement between inspection and upload. The local pathname never enters the request or this method’s errors.
Sourcepub async fn upload_reference_bytes(
&self,
handle: &str,
bytes: Vec<u8>,
mime_type: &str,
) -> Result<ReferenceUploadCompleteResponse>
pub async fn upload_reference_bytes( &self, handle: &str, bytes: Vec<u8>, mime_type: &str, ) -> Result<ReferenceUploadCompleteResponse>
Upload one bounded in-memory attachment through a one-use bearer handle.
Discord already owns attachment bytes in memory after its download-size gate. Taking ownership here guarantees the uploaded body is exactly the body that was hashed and probed, without a second URL fetch.
Sourcepub async fn cancel_reference_upload_session(&self, handle: &str) -> Result<()>
pub async fn cancel_reference_upload_session(&self, handle: &str) -> Result<()>
Best-effort cleanup for an unconsumed reference upload session.
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 async fn list_loras(&self, model: Option<&str>) -> Result<Vec<LoraInfo>>
pub async fn list_loras(&self, model: Option<&str>) -> Result<Vec<LoraInfo>>
List installed LoRAs from the server, optionally filtered to a model’s family.
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 generate_chain(&self, req: &ChainRequest) -> Result<ChainResponse>
pub async fn generate_chain(&self, req: &ChainRequest) -> Result<ChainResponse>
Submit a chained video generation request (non-streaming).
The server normalises the auto-expand form into stages, runs each
stage sequentially with motion-tail latent carryover, stitches the
result into a single video, and returns a ChainResponse. Large
chains take minutes — prefer Self::generate_chain_stream for
interactive clients that want progress updates.
Sourcepub async fn generate_chain_stream(
&self,
req: &ChainRequest,
progress_tx: UnboundedSender<ChainProgressEvent>,
) -> Result<Option<ChainResponse>>
pub async fn generate_chain_stream( &self, req: &ChainRequest, progress_tx: UnboundedSender<ChainProgressEvent>, ) -> Result<Option<ChainResponse>>
Submit a chained video generation request with SSE progress streaming.
Returns:
Ok(Some(response))— streaming succeeded and thecompleteevent carried the stitched video.Ok(None)— server doesn’t have the chain endpoint (empty 404). Callers can fall back toSelf::generate_chainor error.Err(_)— validation, model-not-found, or mid-stream server error.
pub async fn create_chain_job( &self, req: &ChainRequest, ) -> Result<CreateChainJobResponse>
pub async fn list_chain_jobs(&self) -> Result<ChainJobListing>
pub async fn get_chain_job(&self, id: &str) -> Result<ChainJobDetail>
pub async fn resume_chain_job(&self, id: &str) -> Result<ChainJobSummary>
pub async fn retake_chain_job( &self, id: &str, req: &RetakeRequest, ) -> Result<ChainJobSummary>
pub async fn cancel_chain_job(&self, id: &str) -> Result<ChainJobSummary>
pub async fn delete_chain_job(&self, id: &str) -> Result<()>
pub async fn gc_chain_jobs(&self) -> Result<GcOutcome>
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 unload_model_target( &self, model: Option<&str>, gpu: Option<usize>, ) -> Result<String>
pub async fn server_status(&self) -> Result<ServerStatus>
Sourcepub async fn server_capabilities(&self) -> Result<ServerCapabilities>
pub async fn server_capabilities(&self) -> Result<ServerCapabilities>
Feature-detect optional server contracts before rendering controls.
Sourcepub async fn devices(&self) -> Result<DeviceState>
pub async fn devices(&self) -> Result<DeviceState>
Read the server’s stable, runtime-visible device inventory.
Sourcepub async fn capabilities(&self) -> Result<ServerCapabilities>
pub async fn capabilities(&self) -> Result<ServerCapabilities>
Alias used by clients that preflight optional administrative actions.
Sourcepub async fn set_device_enabled(
&self,
device_id: &str,
enabled: bool,
) -> Result<DeviceInfo>
pub async fn set_device_enabled( &self, device_id: &str, enabled: bool, ) -> Result<DeviceInfo>
Enable or disable one stable device. The server may return a draining or starting state while the owner transition completes.
Sourcepub async fn list_queue(&self) -> Result<QueueListingWire>
pub async fn list_queue(&self) -> Result<QueueListingWire>
Snapshot the server’s generation queue (GET /api/queue).
The listing covers everything currently queued or running — completed
jobs live in the gallery, not here. Entries are wire-shaped twins of
the server’s job_registry::JobEntry; see QueueListingWire for
the forward-compat rules (plain-string state, defaulted additive
fields), which let this client talk to both older and newer servers.
Sourcepub async fn cancel_queue_job(&self, id: &str) -> Result<()>
pub async fn cancel_queue_job(&self, id: &str) -> Result<()>
Cancel a still-queued job (DELETE /api/queue/{id}).
The server answers 204 on success, 404 for unknown ids, and 409
when the job is already running on a GPU worker (running jobs are not
cancelable — there is no safe preemption point). Non-2xx responses
surface as errors carrying the response body text, so the 409 reason
reaches the caller verbatim.
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_preview(
&self,
filename: &str,
) -> Result<Option<Vec<u8>>>
pub async fn get_gallery_preview( &self, filename: &str, ) -> Result<Option<Vec<u8>>>
Download a cached animated GIF preview for a video gallery entry.
Returns Ok(None) when the server responds with 404 (no preview
has been generated for this filename yet). Callers are expected to
fall back to the full get_gallery_image path in that case.
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 remix_prompt(&self, req: &RemixRequest) -> Result<RemixResponse>
pub async fn remix_prompt(&self, req: &RemixRequest) -> Result<RemixResponse>
Generate subject-preserving prompt alternatives. A distinct endpoint is intentional: older hosts return 404 instead of silently expanding.
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.
Source§impl MoldClient
impl MoldClient
Sourcepub async fn bind_reference_uploads_v2(
&self,
request: &GenerateRequest,
sources: Vec<ReferenceUploadSource>,
) -> Result<ReferenceUploadLease>
pub async fn bind_reference_uploads_v2( &self, request: &GenerateRequest, sources: Vec<ReferenceUploadSource>, ) -> Result<ReferenceUploadLease>
Create and fill one canonical upload-V2 lease. A returned request may be submitted exactly once; callers must re-open/re-download original media to retry after any generation attempt.
Trait Implementations§
Source§impl Clone for MoldClient
impl Clone for MoldClient
Source§fn clone(&self) -> MoldClient
fn clone(&self) -> MoldClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more