Skip to main content

ComfyClient

Struct ComfyClient 

Source
pub struct ComfyClient { /* private fields */ }
Expand description

Async client for a ComfyUI server instance.

Provides REST methods for prompt queuing, history retrieval, image download, and model discovery. Supports both WebSocket-based real-time progress tracking and polling-based fallback.

§Example

use comfyui_rs::ComfyClient;

let client = ComfyClient::new("http://127.0.0.1:8188");
let healthy = client.health().await?;

Implementations§

Source§

impl ComfyClient

Source

pub fn new(endpoint: impl Into<String>) -> Self

Create a new client pointing at the given ComfyUI endpoint.

Source

pub fn with_http_client(self, client: Client) -> Self

Use a custom reqwest::Client (for connection pooling, timeouts, TLS).

Source

pub fn with_client_id(self, id: impl Into<String>) -> Self

Set the client ID used for WebSocket filtering and prompt association.

Source

pub fn endpoint(&self) -> &str

Returns the configured endpoint URL.

Source

pub fn client_id(&self) -> &str

Returns the configured client ID.

Source

pub async fn health(&self) -> Result<bool>

Check whether ComfyUI is reachable. Any HTTP response (even 500) means the server is running. Only connection/timeout failures return false.

Source

pub async fn queue_prompt(&self, workflow: &Value) -> Result<String>

Queue a workflow for execution. Returns the prompt_id.

Source

pub async fn history(&self, prompt_id: &str) -> Result<Option<PromptHistory>>

Fetch the history entry for a prompt. Returns None if not yet available.

Source

pub async fn image(&self, img: &ImageRef) -> Result<Vec<u8>>

Download an output image by its reference. Returns raw bytes.

Source

pub async fn queue_status(&self) -> Result<QueueStatus>

Get the current ComfyUI queue state (running + pending counts).

Source

pub async fn free_memory(&self, unload_models: bool) -> Result<()>

Free VRAM. If unload_models is true, all models are unloaded.

Source

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

Interrupt the currently running generation.

Source

pub async fn upload_image( &self, image_bytes: &[u8], filename: &str, overwrite: bool, ) -> Result<String>

Upload an image to ComfyUI’s input directory via /upload/image. Returns the filename as stored by ComfyUI.

Source

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

List available checkpoint models from ComfyUI.

Source

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

List available sampler algorithms from ComfyUI.

Source

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

List available scheduler algorithms from ComfyUI.

Source

pub async fn wait_for_completion( &self, prompt_id: &str, timeout: Duration, ) -> Result<GenerationOutcome>

Poll /history until the prompt completes, fails, or times out.

Source

pub async fn wait_for_completion_ws<F>( &self, prompt_id: &str, timeout: Duration, on_progress: F, ) -> Result<GenerationOutcome>

Wait for completion using ComfyUI’s WebSocket for real-time step progress. Calls on_progress for each sampling step. Falls back to polling automatically if the WebSocket connection fails.

Source

pub async fn queue_prompt_traced( &self, workflow: &Value, trace_ctx: Option<&TraceCtx>, ) -> Result<String>

Queue a workflow for execution with optional trace context.

Behaves identically to queue_prompt but logs the trace ID when a stack_ids::TraceCtx is provided.

Source

pub async fn history_traced( &self, prompt_id: &str, trace_ctx: Option<&TraceCtx>, ) -> Result<Option<PromptHistory>>

Fetch prompt history with optional trace context.

Behaves identically to history but logs the trace ID when a stack_ids::TraceCtx is provided.

Source

pub async fn image_traced( &self, img: &ImageRef, trace_ctx: Option<&TraceCtx>, ) -> Result<Vec<u8>>

Download an output image with optional trace context.

Behaves identically to image but logs the trace ID when a stack_ids::TraceCtx is provided.

Source

pub async fn queue_status_traced( &self, trace_ctx: Option<&TraceCtx>, ) -> Result<QueueStatus>

Get queue status with optional trace context.

Behaves identically to queue_status but logs the trace ID when a stack_ids::TraceCtx is provided.

Source

pub async fn upload_image_traced( &self, image_bytes: &[u8], filename: &str, overwrite: bool, trace_ctx: Option<&TraceCtx>, ) -> Result<String>

Upload an image with optional trace context.

Behaves identically to upload_image but logs the trace ID when a stack_ids::TraceCtx is provided.

Source

pub async fn interrupt_traced(&self, trace_ctx: Option<&TraceCtx>) -> Result<()>

Interrupt the current generation with optional trace context.

Behaves identically to interrupt but logs the trace ID when a stack_ids::TraceCtx is provided.

Source

pub async fn free_memory_traced( &self, unload_models: bool, trace_ctx: Option<&TraceCtx>, ) -> Result<()>

Free VRAM with optional trace context.

Behaves identically to free_memory but logs the trace ID when a stack_ids::TraceCtx is provided.

Source

pub async fn wait_for_completion_traced( &self, prompt_id: &str, timeout: Duration, trace_ctx: Option<&TraceCtx>, ) -> Result<GenerationOutcome>

Wait for prompt completion (polling) with optional trace context.

Behaves identically to wait_for_completion but logs the trace ID when a stack_ids::TraceCtx is provided.

Source

pub async fn wait_for_completion_ws_traced<F>( &self, prompt_id: &str, timeout: Duration, on_progress: F, trace_ctx: Option<&TraceCtx>, ) -> Result<GenerationOutcome>

Wait for completion via WebSocket with optional trace context.

Behaves identically to wait_for_completion_ws but logs the trace ID when a stack_ids::TraceCtx is provided.

Trait Implementations§

Source§

impl Clone for ComfyClient

Source§

fn clone(&self) -> ComfyClient

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
Source§

impl Debug for ComfyClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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