Skip to main content
This page demonstrates three ways to interact with the ComfyUI Server API, from a simple HTTP submission to a full WebSocket integration with real-time image output. All examples use the default SD1.5 workflow for illustration. Before using the API, you need to export your workflow in API format.
These examples use Python with the standard library and the websocket-client package (pip install websocket-client). The underlying API protocol is the same regardless of language — see the Cloud API Reference for TypeScript and curl equivalents.

Method 1: Submit and Forget (HTTP only)

Source: basic_api_example.py The simplest approach: submit a workflow and don’t wait for results. Useful for fire-and-forget jobs where you check outputs later.
This method uses the SaveImage node, which saves images to disk on the server. To retrieve them, you’d need to follow up with a call to GET /view?filename=....

Method 2: WebSocket + History (Monitor Completion)

Source: websockets_api_example.py Use WebSocket to wait for execution to finish, then retrieve outputs via the /history endpoint. This is the recommended pattern for most use cases.
The WebSocket binary frames contain in-progress preview images during generation. You can decode them for live previews (see the Server Messages page for the binary format).

Method 3: WebSocket with SaveImageWebsocket (Real-time Images)

Source: websockets_api_example_ws_images.py For scenarios where you don’t want images saved to disk, use the SaveImageWebsocket node. Images are delivered directly via WebSocket binary frames.
The workflow must use a node with class_type: "SaveImageWebsocket" (a built-in node) instead of the regular SaveImage node.

Which Method Should I Use?

Method 1: HTTP Only

Fire and forget. Use when you don’t need immediate output, or when retrieving results later is acceptable.

Method 2: WebSocket + History

Recommended. Wait for completion, then download outputs. Best balance of simplicity and reliability.

Method 3: SaveImageWebsocket

Real-time images. Best for interactive apps where you want images delivered without disk writes.
For the full API reference (endpoints, payload formats, error handling), see the Server Routes and Server Messages pages.