ComfyUI
ComfyUI copied to clipboard
Implement Synchronous API Hooks
This PR allows ComfyUI to fulfill one of my last remaining uses for automatic1111's web UI -- easy integration with external tools.
The existing websocket-based API is ideal for interactive workflows, but is more complex than necessary for simple procedural uses (particularly those involving languages like C++ with sub-par support for websockets). This PR adds the necessary hooks for a custom node pack to add synchronous APIs.
Of note, this PR (along with the custom nodes at https://github.com/BadCafeCode/apitools-comfyui) allows ComfyUI to act as a drop-in replacement for the Automatic1111 API in tools like:
- oobabooga's Text WebUI (with the sd_api_pictures extension)
- Blender (with my fork of the dream-textures extension)
- GIMP (via a plugin like https://github.com/thndrbrrr/gimp-stable-boy)
New endpoints can also be easily prototyped and used with the apitools nodes.
I've tried to strike a balance here between adding full HTTP API support to the base ComfyUI (which I think goes beyond the intended scope) and making no changes to the base ComfyUI (which would require overriding a lot of core functionality from custom nodes and cause frequent bugs when the overwritten code is changed).
I'll include some of my specific reasoning in inline comments on this PR.
Note that although these requests look synchronous to the client, they do still use async functions behind the scenes and will properly queue up if multiple requests are received at once. Each request will return a result once the associated workflow has completed. Standard browsers will generally wait up to 5 minutes if the request is simply performed via CORS, but HTTP client libraries can just about always be configured to wait longer. (More info on long-polling available here.)
Is where a documents like a1111?
I tried it out and it works great! Thanks for this. Really makes ComfyUI a lot more easy to use for custom api workflows. No more injecting my arguments into a giant json document!
+1 would like to see this ability in Comfy
This will be awesome for app devs. Pair it with Runpod, and you have your self a fully customizable image generation api!
+1 for adding this in comfy!
Can you guys tell me how to test it? I understand I need to add both https://github.com/BadCafeCode/apitools-comfyui and https://github.com/BadCafeCode/masquerade-nodes-comfyui repos to the custom_nodes folder. Is that correct?
its awesome!! I really hope it will be in the master
This is fantastic and works great. Thanks! Would it be possible to return the promptId with the sync request to fetch the image when the first request ends? The request response is empty as of now.
Closing this PR as I'm no longer maintaining it. The apitools-comfyui repository has been updated to work against my Node Expansion PR (https://github.com/comfyanonymous/ComfyUI/pull/931) instead. The lazy evaluation functionality provided by that PR is a better alternative to the hacks I had been doing within the apitools-comfyui repository. (I haven't updated the A1111 analog workflows within there yet though.)