Skip to main content

MoldClient

Struct MoldClient 

Source
pub struct MoldClient { /* private fields */ }

Implementations§

Source§

impl MoldClient

Source

pub fn new(base_url: &str) -> Self

Source

pub fn with_api_key(base_url: &str, api_key: String) -> Self

Create a client with an explicit API key for authentication.

Source

pub fn from_env() -> Self

Source

pub fn has_api_key(&self) -> bool

Whether this client actually installed a non-empty API-key header.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn cancel_reference_upload_session(&self, handle: &str) -> Result<()>

Best-effort cleanup for an unconsumed reference upload session.

Source

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.

Source

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.

Source

pub async fn list_models(&self) -> Result<Vec<ModelInfo>>

Source

pub async fn list_models_extended(&self) -> Result<Vec<ModelInfoExtended>>

Source

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.

Source

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.

Source

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.

Source

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 succeeded
  • Ok(None) — server doesn’t support SSE (endpoint returned 404 with empty body)
  • Err(e) — generation error, model not found, or connection error
Source

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.

Source

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 the complete event carried the stitched video.
  • Ok(None) — server doesn’t have the chain endpoint (empty 404). Callers can fall back to Self::generate_chain or error.
  • Err(_) — validation, model-not-found, or mid-stream server error.
Source

pub async fn create_chain_job( &self, req: &ChainRequest, ) -> Result<CreateChainJobResponse>

Source

pub async fn list_chain_jobs(&self) -> Result<ChainJobListing>

Source

pub async fn get_chain_job(&self, id: &str) -> Result<ChainJobDetail>

Source

pub async fn resume_chain_job(&self, id: &str) -> Result<ChainJobSummary>

Source

pub async fn retake_chain_job( &self, id: &str, req: &RetakeRequest, ) -> Result<ChainJobSummary>

Source

pub async fn cancel_chain_job(&self, id: &str) -> Result<ChainJobSummary>

Source

pub async fn delete_chain_job(&self, id: &str) -> Result<()>

Source

pub async fn gc_chain_jobs(&self) -> Result<GcOutcome>

Source

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.

Source

pub async fn shutdown_server(&self) -> Result<()>

Request graceful server shutdown.

Source

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.

Source

pub fn host(&self) -> &str

Source

pub async fn unload_model(&self) -> Result<String>

Source

pub async fn unload_model_target( &self, model: Option<&str>, gpu: Option<usize>, ) -> Result<String>

Source

pub async fn server_status(&self) -> Result<ServerStatus>

Source

pub async fn server_capabilities(&self) -> Result<ServerCapabilities>

Feature-detect optional server contracts before rendering controls.

Source

pub async fn devices(&self) -> Result<DeviceState>

Read the server’s stable, runtime-visible device inventory.

Source

pub async fn capabilities(&self) -> Result<ServerCapabilities>

Alias used by clients that preflight optional administrative actions.

Source

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.

Source

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.

Source

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.

List gallery images from the server’s output directory.

Download a gallery image by filename.

Delete a gallery image on the server.

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.

Download a gallery thumbnail by filename. Smaller/faster than full image.

Source

pub async fn expand_prompt(&self, req: &ExpandRequest) -> Result<ExpandResponse>

Expand a prompt using the server’s LLM prompt expansion endpoint.

Source

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.

Source

pub async fn upscale(&self, req: &UpscaleRequest) -> Result<UpscaleResponse>

Upscale an image using a super-resolution model on the server.

Source

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

Source

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

Source§

fn clone(&self) -> MoldClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more