If you run ComfyUI on your own machine, you know the rhythm: build or paste a workflow graph, wire the sampler, pick a checkpoint, queue it, wait, and then hunt through the output folder. It is powerful — and it is exactly the kind of repetitive, deterministic work that an AI agent should be doing for you. The problem is that a coding agent usually tries to "reason" its way through ComfyUI's REST API every single time, drafting a fresh node graph in JSON and burning thousands of tokens on something that never changes.
gen.py is a one-file Python Blueprint from Agent Media Tools that collapses that whole flow into a single command: you pass a prompt, it builds the standard txt2img workflow, queues it on your ComfyUI server, waits for completion, and downloads the finished image into a local output folder. It is a free download — no account, no hosted GPU, no per-image credits — and this post walks through what the script actually does, how to grab it, and how to call it from curl, Python, or an agent loop.
The script (v1.2.1 at the time of writing, about 13 KB and 400 lines) is a thin client for ComfyUI's standard HTTP API. Reading through it, the flow is:
GET /system_stats on the primary URL (default http://127.0.0.1:8188), then falls back to http://localhost:8188 if that fails.CheckpointLoaderSimple → two CLIPTextEncode nodes (positive and negative) → EmptyLatentImage → KSampler → VAEDecode → SaveImage./prompt with a fresh client_id, then polls GET /history/{prompt_id} once per second until the job finishes (300-second timeout).GET /view?filename=...&subfolder=...&type=output, saving PNGs to ./outputs/.Defaults are tuned for speed rather than perfection: 30 sampling steps, CFG 7.0, 1024×1024, Euler sampler with the normal scheduler. The default checkpoint name is animeModel.safetensors, so on first run you will almost certainly want --model to point at a checkpoint that actually exists on your server. A sensible negative prompt ships as the default, and every run prints progress to stderr while writing a structured JSON result to stdout — which is what makes the script easy for an agent to consume.
Blueprint downloads are served from a public endpoint that requires no account and no API key. One command grabs the file:
curl -fL -o gen.py "https://agentmediatools.com/api/shop/download/gen.py" python3 gen.py --help
The equivalent Python download looks like this:
import requests
url = "https://agentmediatools.com/api/shop/download/gen.py"
r = requests.get(url, timeout=30)
r.raise_for_status()
open("gen.py", "wb").write(r.content)
print(f"Saved gen.py ({len(r.content):,} bytes)")
Agents that want to discover what is available before downloading can hit the public catalog — this is the same endpoint behind the MCP list_shop_items tool:
curl -s "https://agentmediatools.com/api/shop/items" \ | python3 -c "import json,sys; d=json.load(sys.stdin); print([s['id'] for s in d['scripts']])"
Each entry in the response includes an id (for example gen), a filename, a description, dependency hints, and a download_url. The API explicitly notes that Blueprint downloads require no account or purchase — gen.py, gen-sd.py, web-scrape.py, deliver.py, and the rest of the library are all free to fetch this way.
The script assumes ComfyUI is already running somewhere you control — it is a local workflow tool, not a hosted render farm. If your instance is not on the default localhost port, set the URL explicitly:
export COMFY_URL="http://192.168.1.50:8188" python3 gen.py --prompt "neon city street at night, rain, cinematic" \ --model "dreamshaperXL"
Everything is configurable through flags or environment variables:
--steps, --cfg, --sampler, --scheduler, --seed — sampler controls for reproducible runs.--width, --height — output dimensions (default 1024×1024).--count N — generate N variations of the same prompt.--output-dir and --prefix — where files land (default ./outputs/gen_*.png).--jpeg with --jpeg-quality (default 92) — convert the PNG to a much smaller JPEG, handy when the image is headed into chat or a web UI. This flag needs Pillow installed.COMFY_URL, COMFY_FALLBACK_URL, COMFY_MODEL, COMFY_OUTPUT_DIR — environment overrides, useful when the same script is shared across machines.Basic single image:
python3 gen.py --prompt "1girl, blue hair, sunset, masterpiece" \ --width 1024 --height 1024 --steps 30
Four variations of the same idea with a fixed seed so you can compare:
python3 gen.py --prompt "mossy forest, god rays" --count 4 --seed 12345
For pipelines that need many different prompts, read them from stdin, one per line:
printf '%s\n' \ "cyberpunk alley, neon signs" \ "abandoned space station, volumetric light" \ "tiny dragon on a desk, macro" | python3 gen.py --prompts-from-stdin
Because each run returns JSON on stdout, the script slots into automation without scraping logs:
{"results": [{"success": true, "outputs": ["outputs/gen_20260903_142301.png"], "seed": 842913, "model": "dreamshaperXL"}]}
There are two ways an agent can talk to ComfyUI. The expensive way is to have the model improvise a workflow JSON on every call — teaching it the node schema, babysitting malformed graphs, and paying for thousands of tokens of trial and error. The cheap way is to give the agent one deterministic command that already encodes the correct workflow. The script's own header estimates this at 3,000–5,000 tokens saved per image versus having an LLM plan the workflow by hand, which lines up with what we see in practice: the workflow never changes, so the tokens should not either.
That makes gen.py a natural fit for agent tool use. An agent can download it once, discover it later through list_shop_items if it forgets, and then treat python3 gen.py --prompt "..." as a black-box tool that returns structured output — no SDK to install, no API key to rotate, no rate limit to hit on your own GPU.
A few things worth knowing before you adopt it:
requests is used when installed, and Pillow is required only for --jpeg conversion.If you already run ComfyUI, the fastest way to test the idea is also the simplest: download gen.py, point it at your server, and generate an image from your terminal in the next sixty seconds. Once it works once, hand the same command to your agent and let it start producing.
Browse the whole Blueprint library — image generators, scrapers, context tools, and delivery scripts — and download any of them in one click.
Open Blueprints