---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://framesfield.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
title: "ComfyUI Headless API Batch Runner Skill"
description: "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`."
canonical: "https://framesfield.com/skills/comfyui-headless-batch-runner-skill"
---

# ComfyUI Headless API Batch Runner Skill

> 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`.

- **Canonical URL:** https://framesfield.com/skills/comfyui-headless-batch-runner-skill
- **Raw Payload URL:** https://framesfield.com/raw/skills/comfyui-headless-batch-runner-skill
- **Asset Type:** SKILL.md
- **Compatible Hosts:** Claude Code, Cursor, Codex
- **Target Creative Tool:** ComfyUI HTTP / WebSocket API
- **License:** MIT
- **Last Verified:** 2026-11-30
- **Source Reference:** https://github.com/comfyanonymous/ComfyUI

## Setup & Install

```bash
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

```

## Copyable Asset (SKILL.md)

````markdown
---
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.
````

## Example Input

```text
"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/."
```

## Expected Output

```text
- 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.
```

## 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)

## Known Limits

- 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

## Implementation Notes

## Drive all three verified FramesField ComfyUI graphs

Pair this batch runner skill with [Skill 04: ComfyUI Wan 2.2 Dual-Expert I2V Graph](/skills/comfyui-character-turnaround), [Skill 10: ComfyUI FLUX.1 Kontext / Dev Keyframe Batch Graph](/skills/comfyui-flux-kontext-keyframe-graph), and [Skill 29: ComfyUI Lightricks LTX-2 Audio-Video Graph](/skills/comfyui-ltx2-audio-video-graph).
