Skip to main content

Crate comfyui_rs

Crate comfyui_rs 

Source
Expand description

§comfyui-rs

Async Rust client for ComfyUI — the node-based Stable Diffusion GUI/backend.

Provides a typed client for REST operations, WebSocket-based real-time progress tracking with automatic polling fallback, model discovery, and a workflow builder for common generation patterns.

§Quick Start

use comfyui_rs::{ComfyClient, Txt2ImgRequest, GenerationOutcome};
use std::time::Duration;

let client = ComfyClient::new("http://127.0.0.1:8188");

// Discover models
let checkpoints = client.checkpoints().await?;
let checkpoint = &checkpoints[0];

// Build a workflow
let (workflow, seed) = Txt2ImgRequest::new("a sunset over mountains", checkpoint)
    .negative("lowres, blurry")
    .steps(25)
    .build();

// Queue and wait with real-time progress
let prompt_id = client.queue_prompt(&workflow).await?;
let result = client.wait_for_completion_ws(
    &prompt_id,
    Duration::from_secs(120),
    |p| println!("Step {}/{}", p.current_step, p.total_steps),
).await?;

if let GenerationOutcome::Completed { images } = result {
    for img in &images {
        let bytes = client.image(img).await?;
        std::fs::write(&img.filename, &bytes).unwrap();
    }
}

Re-exports§

pub use client::ComfyClient;
pub use error::ComfyError;
pub use error::Result;
pub use types::ComfyProgress;
pub use types::ComfyStatus;
pub use types::DownloadLimits;
pub use types::GenerationOutcome;
pub use types::ImageRef;
pub use types::ProgressUpdate;
pub use types::PromptHistory;
pub use types::QueueStatus;
pub use types::WsConfig;
pub use workflow::Txt2ImgRequest;

Modules§

client
error
types
workflow