Today, I will share with you a post by a guru Philipp Doll on using websocket with СomfyUI. I have previously experimented with the API with ComfyUI.
I can't say how much this might be needed for the regular ComfyUI user, but it's cool that this option is there.
Let us proceed.
Motivation
This article focuses on leveraging ComfyUI beyond its basic workflow capabilities. You have created a fantastic Workflow and want to share it with the world or build an application around it. By hosting your projects and utilizing this WebSocket API concept, you can dynamically process user input to create an incredible style transfer or stunning photo effect.
Introduction
This post describes the basic structure of a WebSocket API that communicates with ComfyUI. Generating images through ComfyUI typically takes several seconds, and depending on the complexity of the workflow,
this time can increase. We utilize a WebSocket connection to track progress and allow us to give real-time feedback to the user. Using these endpoints without a WebSocket connection is possible, but this will cost you the benefits of real-time updates.
Code for a basic WebSocket API structure can be found here: Basic WebSocket API.
Utilized ComfyUI endpoints
ComfyUI already has predefined endpoints ComfyUI endpoints, which we can target. Furthermore, ComfyUI also offers a WebSocket interface. For the API described later in this blog post, we do not need to modify this file, as it already provides everything we need.
⦁ @routes.get('/ws') ⇒ Returns the WebSocket object, sends status and executing messages
⦁ @routes.post("/prompt") ⇒ Queues prompt to workflow, returns prompt_id or error
⦁ @routes.get("/history/{prompt_id}") ⇒ Returns the queue or output for the given prompt_id
⦁ @routes.get("/view") ⇒ Returns an Image given a filename, subfolder, and type ("input", "output", "temp")
⦁ @routes.post("/upload/image") ⇒ Uploads an image to ComfyUI, given image_data and type ("input", "output", "temp")




















