Skip to content
FramesField
SKILL.md Developer / Local Tooling SKILL.md
Verified Nov 30, 2026

ComfyUI Headless API Batch Runner Skill

How to install this SKILL.md

Install into .claude/skills/, .cursor/skills/, or .agents/skills/ below whenever you want your agent to turn a shotlist.json into unattended overnight local or RunPod ComfyUI video batches.

Installable SKILL.md teaching Claude Code, Cursor, and Codex how to automate local or cloud-GPU (RunPod/Modal) ComfyUI servers programmatically—uploading input PNGs via /upload/image, patching seeds/prompts into API JSON graphs, tracking completion over WebSocket or /history/{prompt_id}, and fetching finished MP4/PNG outputs via /view.

Compatible agent hosts
Claude Code Cursor Codex
Target tool: ComfyUI HTTP / WebSocket API · License: MIT
  1. STEP 01
    Install the ComfyUI batch runner SKILL.md

    Pick Claude Code, Cursor, or Codex below to save the pure raw SKILL.md file.

  2. STEP 02
    Point your agent at a ComfyUI API JSON graph

    Pair with our Wan 2.2 (Skill 04), FLUX (Skill 10), or LTX-2 (Skill 29) raw JSONs plus your shotlist.json.

  3. STEP 03
    Queue unattended local or RunPod batches

    Uploads keyframes via /upload/image, patches nodes cleanly, polls /history/{prompt_id}, and downloads outputs locally.

1. Install for your tool

Pick the app you use below for the exact verified command or config—zero manual guessing.

Direct raw file (SKILL.md) ↓
Claude Code (.claude/skills/) bash
Installs directly into .claude/skills/comfyui-batch-runner/SKILL.md.
mkdir -p .claude/skills/comfyui-batch-runner
curl -fsSL https://framesfield.com/raw/skills/comfyui-headless-batch-runner-skill -o .claude/skills/comfyui-batch-runner/SKILL.md

2. Inspect or download the full SKILL.md file

This is the exact raw file served at /raw/skills/comfyui-headless-batch-runner-skill.

ComfyUI Headless API Batch Runner Skill SKILL.md
---
name: comfyui-batch-runner
description: Automate local or cloud-GPU ComfyUI servers programmatically over HTTP and WebSocket—uploading keyframes via /upload/image, patching API JSON graphs deterministically, polling /history/{prompt_id}, and downloading finished MP4 or PNG outputs via /view.
---

# ComfyUI Headless API Batch Automation Protocol

Whenever writing Python or Node scripts to drive a local (`http://127.0.0.1:8188`) or remote cloud-GPU ComfyUI instance, follow this exact 5-step API lifecycle:

## 1. Health & Checkpoint Pre-Flight (`GET /object_info`)
Before queueing a 20-clip batch, verify the server is reachable and required node classes exist (`GET $COMFY_URL/system_stats` and `GET $COMFY_URL/object_info/SaveVideo`). Fail fast if the remote RunPod/local server is missing a checkpoint or node pack.

## 2. Upload Input Keyframes Cleanly (`POST /upload/image`)
Never assume local disk paths are visible to a remote RunPod/Modal ComfyUI container. Upload each opening PNG via multipart form-data:
```bash
curl -sS -X POST "$COMFY_URL/upload/image" \
  -F "image=@keyframes/shot01.png" \
  -F "overwrite=true"
```
Capture the returned `"name"` field and patch it into your `LoadImage` node's `inputs.image`.

## 3. Wrap Graph in `{"prompt": ..., "client_id": ...}` (`POST /prompt`)
ComfyUI rejects bare node maps unless wrapped inside `"prompt"`:
- Patch positive text, `LoadImage`, dimensions (divisible by `16` for Wan 2.2, `32` for LTX-2), frame count (`4n+1` for Wan 2.2, `8n+1` for LTX-2), and deterministic integer `noise_seed`.
- Verify the graph terminates in `SaveVideo` or `SaveImage` before POSTing.
- Parse returned `{"prompt_id": "..."}` and log it immediately to `comfy-manifest.json`.

## 4. Wait Cleanly via `/history/{prompt_id}` (or WebSocket)
Poll `GET $COMFY_URL/history/$PROMPT_ID` every `5–10s` (or subscribe to `ws://$HOST/ws?clientId=$CLIENT_ID`) until `history[prompt_id]["status"]["completed"] == true` or `status_str == "error"`. On CUDA OOM errors, stop immediately and surface the exact node ID + traceback instead of retrying endlessly.

## 5. Download Output Artifacts (`GET /view`)
Iterate over `history[prompt_id]["outputs"][node_id]` (`videos`, `gifs`, or `images`) and download each rendered artifact via:
```bash
curl -sS "$COMFY_URL/view?filename=$FILENAME&subfolder=$SUBFOLDER&type=$TYPE" \
  -o "renders/${SHOT_ID}_${SEED}_${FILENAME}"
```
Run `ffprobe` on downloaded MP4s and persist seed + output path inside `comfy-manifest.json` so any keeper take is 100% reproducible.

3. Test it right away (sample prompt & result)

Sample prompt / input
"Write a Python batch script that uploads keyframes/shot01..04.png to my RunPod ComfyUI server, runs wan22-dual-expert-i2v.api.json across 2 seeds per shot, and downloads every finished MP4 into ./renders/."
What happens when it runs
- Emits `scripts/run_comfy_batch.py` checking `/system_stats` first, uploading each PNG via `/upload/image`, patching nodes 5/6/9/10 cleanly, and saving `prompt_id` to `comfy-manifest.json`.
- Polls `/history/{prompt_id}` cleanly, catches OOM errors cleanly without blind retries, downloads MP4 outputs via `/view`, and prints an `ffprobe` summary table.

What you need & known limits

Requirements

  • Running local ComfyUI (127.0.0.1:8188) or cloud-GPU ComfyUI endpoint (COMFY_URL)
  • API-format ComfyUI JSON graph ending in SaveVideo or SaveImage (such as Skill 04, Skill 10, or Skill 29)

Watch out for

  • Never expose an unauthenticated ComfyUI port publicly on the open internet—use SSH port forwarding or authenticated proxy URLs for cloud GPUs
  • Remote GPU pods bill per hour even while idle—always shut down or stop RunPod pods immediately once /view downloads complete

Frequently Asked Questions

Why did ComfyUI reject my POST /prompt with a 400 error?
The two most common causes are sending the raw node dictionary without wrapping it inside {"prompt": <graph>}, or referencing a checkpoint filename in UNETLoader / CheckpointLoaderSimple that does not exactly match the file in ComfyUI/models/.
Does this work identically on local RTX 4090 desktops and rented RunPod 24GB pods?
Yes. Because input PNGs upload over HTTP via /upload/image and outputs download via /view, switching from local desktop to a rented cloud GPU requires changing only one COMFY_URL environment variable.
Use this page in AI tools or notes
raw .md