ComfyUI : Using the API : Part 1

Controlling ComfyUI via Command Line and Script

Yushan777
7 min readSep 13, 2023

Having used ComfyUI for a few weeks, it was apparent that control flow constructs like loops and conditionals are not easily done out of the box. There are some custom nodes that allow for some level of control such as moving through prompt lists or files etc but I found them to be quite cumbersome.

Lack of information and documentation on the API led me to avoid looking at it until now. So in many ways this is my own documentation for it as I learn how it works.

One particular use case I have after training a model with various saved checkpoints is to produce test images from each one with different prompts, and different image aspect ratios and perhaps different other settings. The only way to do this via the main UI was through a lot of clicking around. But that is one for a future guide.

For this Part 1 guide I will produce a simple script that will:
1. Iterate through a list of 4 prompts
2. Seed will be random for each iteration
3. Default image size will be 512x640
4. Batch size will be 4
4. For the final prompt, I want the image size to be 512x768

--

--

Yushan777

No Click-Baity stuff! This is just my own journal so I can remember how I did stuff 🙂