ComfyUI with API: Difference between revisions
Jump to navigation
Jump to search
Created page with "ComfyUI allows to execute workflows from the command line using API workflows == Enable API workflows == You have to activate dev mode. In version 0.3.59 you have to click on comfyUI icon at top left, settings. Search for "dev mode" and activate it == Export a workflow in API version == Click on comfyUI icon at top left, File, Export (API) == Script for executing the workflow == <syntaxhighlight lang="python3"> import json from urllib import request, parse import rand..." |
|||
| Line 8: | Line 8: | ||
== Script for executing the workflow == | == Script for executing the workflow == | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="python"> | ||
import json | import json | ||
from urllib import request, parse | from urllib import request, parse | ||
| Line 46: | Line 46: | ||
queue_prompt(prompt_workflow) | queue_prompt(prompt_workflow) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:AI: Generate media locally]] | [[index.php?title=Category:AI: Generate media locally]] | ||
Revision as of 14:57, 3 November 2025
ComfyUI allows to execute workflows from the command line using API workflows
Enable API workflows
You have to activate dev mode. In version 0.3.59 you have to click on comfyUI icon at top left, settings. Search for "dev mode" and activate it
Export a workflow in API version
Click on comfyUI icon at top left, File, Export (API)
Script for executing the workflow
import json
from urllib import request, parse
import random
# load the workflow from file, assign it to variable named prompt_workflow
promptWorkflow = json.load(open('workflow_api.json'))
# give some easy-to-remember names to the nodes
loadImageNode = promptWorkflow["14"]
upscaleImageNode = promptWorkflow["71"]
wanImageToVideoNode = promptWorkflow["10"]
promptPositiveNode = promptWorkflow["13"]
KSamplerAdvancedNode = promptWorkflow["3"]
### Set workflow values from user input (parameter --source-image)
### @TODO: check that file exists before proceeding. If not, display error message
loadImageNode["inputs"]["image"] = @TODO: get from --source-image
sourceImageWidth = @TODO: get from --source-image
sourceImageHeight = @TODO: get from --source-image
# get origin image sizes and use them for the video output
upscaleImagNode["inputs"]["width"] = sourceImageWidth
upscaleImagNode["inputs"]["height"] = sourceImageHeight
wanImageToVideoNode["inputs"]["width"] = sourceImageWidth
wanImageToVideoNode["inputs"]["height"] = sourceImageHeight
# append the input prompt to the prompt list (parameter --prompt)
prompt_list = []
prompt_list.append(@TODO: get from --prompt)
# Set a random noise seed for the sampler
ksampler_node["inputs"]["noise_seed"] = random.randint(1, 18446744073709551614)
# Queue prompt
queue_prompt(prompt_workflow)