How to Use the ComfyUI API

Back
Team Aquanode

Team Aquanode

Ansh Saxena

NOVEMBER 13, 2026

ComfyUI has a built-in HTTP API on the same port as the UI. To run a workflow from code, export it in API format, then POST it to /prompt as {"prompt": <workflow>}.

Steps

  1. Export the workflow. The official example says to use File, then Export (API) in the interface to get the API-format JSON for a specific workflow.
  2. Queue it. From the repo's basic_api_example.py:
import json
from urllib import request

def queue_prompt(prompt):
    p = {"prompt": prompt}
    data = json.dumps(p).encode("utf-8")
    req = request.Request("http://127.0.0.1:8188/prompt", data=data)
    request.urlopen(req)

prompt = json.load(open("workflow_api.json"))
queue_prompt(prompt)
  1. Edit inputs first if you need to: the exported JSON is keyed by node id, so a script changes a prompt or a seed by setting, for example, prompt["6"]["inputs"]["text"], as the example does.

Other routes in server.py

RouteUse
GET /history/{prompt_id}Result and outputs of a queued prompt
GET /viewFetch an output image
GET /queueRunning and pending jobs
POST /interruptStop the current run
GET /object_infoEvery node and its inputs
POST /upload/imageUpload an input image
POST /freeUnload models and free memory
GET /wsWebSocket for live progress

The repo's websockets_api_example.py shows the WebSocket flow. The port is 8188 unless you change it (ComfyUI default port), and you decide who can reach it. For freeing memory from a script see how to clear VRAM in ComfyUI. Workflows that use custom nodes need those nodes installed on the server: the ComfyUI custom node install guide.

Sources

#comfyui questions#comfyui api

ComfyUI on our compute

Rent a GPU with ComfyUI already installed. Your custom nodes and models are there next time. $29 a month, or pay as you go.

Start ComfyUI

Start ComfyUI on a rented GPU.

Sign up in 60 seconds. Pay for the GPU minutes you actually use.

© 2026 Aquanode. All rights reserved.

All trademarks, logos and brand names are the property of their respective owners.