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 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 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 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 server_status(&self) -> Result<ServerStatus>

List gallery images from the server’s output directory.

Download a gallery image by filename.

Delete a gallery image on the server.

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 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.

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> 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: 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: 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, 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