While AUTOMATIC1111 can generate images based on prompt variations, I haven’t found the same possibility in ComfyUI. However, you can achieve the same result thanks to ComfyUI API and curl.

When you click “queue prompt” in ComfyUI, it actually sends a POST request with the whole workflow as JSON data to http://127.0.0.1:8188/prompt .

To get the workflow as JSON, go to the UI and click on the settings icon, then enable Dev mode Options and click close. You will now see a new button Save (API format).

When you have a workflow you are happy with, save it in API format.

You need to enclose the whole prompt in a JSON field “prompt” like so:

Remember to add a closing bracket at the end of the file and save it.

You can now send this with curl as follows and ComfyUI will render your prompt as if you sent it through the web UI:

curl -X POST --data @workflow.json http://127.0.0.1:8188/prompt

What if you want to send a different prompt?

Well, you need to find the node with your prompt and replace the prompt with a placeholder, for example _POSITIVEPROMPT_. Like so:

Then, you can write prompt(s) in a text file and use the usual tools to sequentially run your prompts:

cat prompts | while read prompt  
do  
    sed -e "s/_POSITIVEPROMPT_/$prompt/" workflow.json > /dev/shm/data.json  
    curl -X POST --data @/dev/shm/data.json http://127.0.0.1:8188/prompt  
done

If you run ComfyUI on Windows and you don’t have a native curl, you can run the Powershell command Invoke-RestMethod. You can also make ComfyUI listen on another (or all) IP addresses using the --listen option and run curl from WSL2 or another computer.

python main.py --directml --listen

You can of course change other fields in the workflow by repeating the same operation:

  • replace the value with a placeholder
  • add a replace operation in sed
  • run curl
sed -e "s/toto/tata/" -e "s/titi/tutu/" -e etc