ComfyUI API

Why Use the API?

Automation, web/mobile integration, production pipelines, Discord bots, SaaS services, and automated testing.

Architecture

REST API + WebSocket on port 8188.

Key Endpoints

  • POST /prompt — submit a workflow
  • GET /history/{id} — get generation result
  • GET /view?filename=... — download generated image
  • POST /upload/image — upload input image
  • GET /object_info — list all available nodes

Prompt JSON Format

The workflow is described as a JSON graph of nodes with class_type and inputs. Connections use ["node_id", output_index] tuples.

Tip: Create workflows in the GUI, enable Dev Mode, then use Save (API Format) to get the JSON.

Python Integration

Use urllib or requests for REST calls, websocket for real-time progress tracking. The WebSocket provides step-by-step progress and completion notifications.

JavaScript/TypeScript Integration

Use fetch for REST and the ws library for WebSocket connections.

Image Upload

POST to /upload/image with multipart form data, then reference the filename in your workflow.

Production Deployment

  • Docker with --listen 0.0.0.0 --enable-cors-header
  • Nginx reverse proxy with WebSocket support
  • Never expose directly to the internet without authentication
  • Rate limiting and size restrictions

Use Case: Discord Bot

Queue prompts via the API, wait for completion via WebSocket, and send the result as a Discord file attachment.