RunComfy offers two API approaches to suit various integration needs: RunComfy Server API and ComfyUI Backend API These APIs lets you spin up and fully control a dedicated ComfyUI backend. Start by using the Server API to manage machines through simple calls: POST to generate a server_id, poll the status endpoint until it reaches "Ready", and then access the ComfyUI Backend API directly for tasks like executing workflows, managing nodes, and retrieving outputs. This approach is perfect when you need complete oversight of the ComfyUI backend, such as for in-depth integrations with creative software like Krita, Photoshop, Blender, iClone, or other tools. RunComfy Serverless API This API turns any ComfyUI workflow into an on-demand, autoscaling endpoint, enabling simple API calls without any server setup or maintenance. It includes asynchronous job monitoring and versioning for rapid updates, making it ideal for efficient, scalable production setups that can be easily integrated into your apps. For more details, check our Serverless API documentation.
Get ComfyUI Backend URL
- From RunComfy website in the browser
- The url appears as
https://www.runcomfy.com/comfyui/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/servers/yyyyyyy-yyyy-yyyy-yyyyyyyyyyyy. - The actual ComfyUI URL can be found in here, in a format of
https://yyyyyyy-yyyy-yyyy-yyyyyyyyyyyy-comfyui.runcomfy.com. - From RunComfy API
- It is the main_service_url in this response.
Note: Please use this ComfyUI URL in a trusted environment, DO NOT SHARE IT publicly.
Activate Development Mode
Ensure that "Enable Development Mode Options" is activated in the Settings menu.
Download the workflow_api.json file by clicking on the Save (API Format) button.
The following file is AnimateDiff + ControlNet + Auto Mask | Restyle Video, which will be used as an example.
workflow_api.json7.3KB
Upload Image as Input
Upload Video as Input
The response will be something like:
{
"name": "zzzz.mp4",
"subfolder": "",
"type": "input"
}The zzzz.mp4 is the file you uploaded via the API in the input folder. Sometimes it may contain suffixes like '(1)' or '(1)(1)' if a file with the same name already exists.
Queue prompt
Basic HTTP API:
- Generate client_id
import uuid
client_id = str(uuid.uuid4())- Load
workflow_api.jsonfrom your local disk and change the input to the file name which you just uploaded ininputfolder, and also modify the prompt text in the json if you need to.
import json
prompt_data = json.load(open("workflow_api.json"))
prompt_data['89']['inputs']['video'] = 'zzzz.mp4'- Call the queue prompt api
- check status
- Reference to https://github.com/comfyanonymous/ComfyUI/blob/master/script_examples/websockets_api_example.py for more details
import websocket
import uuid
ws = websocket.WebSocket()
ws.connect("ws://{}/ws?clientId={}".format('yyyyyyy-yyyy-yyyy-yyyyyyyyyyyy-comfyui.runcomfy.com', client_id))
while True:
out = ws.recv()
print(out)status.txt426.2KB
- Get Result
- Explanation on the url path
- If you want to get the file from the following path, /ComfyUI/output/subfolder1/subfolder2/test_00001_.png, try GET the following url, https://xxx-comfyui.runcomfy.com/api/view?filename=test_00001_.png&subfolder=subfolder1%2Fsubfolder2&type=output