Event Categories
ComfyUI WebSocket events are divided into two categories:JSON Events
Text-based messages sent as JSON objects for workflow state changes
Binary Events
Binary messages containing preview images and other binary data
JSON Events
JSON events follow this structure:status
Sent when the queue status changes or on initial connection. Contains information about the current execution queue.object
required
string
Session ID (only included in the initial connection message)
Example
executing
Sent when a node begins execution or when execution completes.string | null
required
The ID of the node currently executing.
null indicates that execution has completed.string
The ID of the node to display in the UI (may differ from the executing node for optimization)
string
required
The unique identifier for the workflow execution
Example: Node Execution
Example: Execution Complete
executed
Sent when a node completes execution successfully.string
required
The ID of the node that finished executing
string
The ID of the node displayed in the UI
object
The UI output from the node (e.g., generated images, text)
string
required
The unique identifier for the workflow execution
Example
progress
Sent during node execution to report progress (e.g., sampling steps).integer
required
Current progress value (e.g., current step)
integer
required
Maximum progress value (e.g., total steps)
string
The unique identifier for the workflow execution
string
The ID of the node reporting progress
Example
execution_error
Sent when an error occurs during workflow execution.string
required
The unique identifier for the failed workflow execution
string
The ID of the node that caused the error
string
Human-readable error message
string
The type of exception that occurred
string
Full Python traceback for debugging
Example
feature_flags
Exchanged between client and server to negotiate supported features.object
required
Key-value pairs of feature flags and their support status (boolean)
Example: Server Features
logs
Sent when server logs are available (if log streaming is enabled).array
required
Array of log entry objects
integer
Total size of log data
Example
Binary Events
Binary messages use a structured format:Event Type IDs
Defined inprotocol.py:
PREVIEW_IMAGE (Type 1)
Contains an encoded preview image generated during workflow execution.Format
integer
1: JPEG format2: PNG format
Decoding Example
PREVIEW_IMAGE_WITH_METADATA (Type 4)
Contains a preview image along with metadata (requires feature flag negotiation).Format
integer
Length of the JSON metadata in bytes (big-endian)
object
JSON object containing metadata about the image
Decoding Example
UNENCODED_PREVIEW_IMAGE (Type 2)
Raw unencoded preview image data (rarely used in practice).TEXT (Type 3)
Binary text data (rarely used; most text is sent as JSON).Event Flow Example
Here’s a typical sequence of events when executing a workflow:Complete Integration Example
Here’s a production-ready example that handles all event types:Best Practices
Check Event Types
Check Event Types
Always check the event
type before accessing data properties, as different events have different data structures.Handle Binary Messages
Handle Binary Messages
Use
struct.unpack(">I", data[:4])[0] to read the big-endian event type from binary messages.Match Prompt IDs
Match Prompt IDs
When tracking multiple concurrent workflows, always check
prompt_id to match events with the correct execution.Detect Completion
Detect Completion
Workflow execution is complete when you receive an
executing event with node: null.Error Handling
Error Handling
Listen for
execution_error events and implement retry logic or user notifications.Next Steps
WebSocket Overview
Learn how to establish and manage WebSocket connections
History Endpoint
Retrieve execution results after completion