GPU Compute / Recipe

Image generation API

Serve a Diffusers or ComfyUI container as a persistent image generation endpoint using badgr serve --image. Badgr keeps the container running so you get low-latency responses without cold-start delays.

Prerequisites: npm install -g badgr-cli then badgr login. Setup guide →

1. Start the endpoint

Serve your Diffusers API image. Pass model configuration via --env:

badgr serve \
  --image ghcr.io/my-org/diffusers-api:latest \
  --gpu L40S \
  --env MODEL_ID=black-forest-labs/FLUX.1-schnell \
  --env HF_TOKEN=$HF_TOKEN

Badgr prints the endpoint URL once the container starts (typically 2–5 minutes for large diffusion models). The container keeps running until you call badgr down.

Or serve a ComfyUI container:

badgr serve \
  --image ghcr.io/my-org/comfyui-custom:latest \
  --gpu A100 \
  --env COMFY_EXTRA_ARGS="--listen 0.0.0.0"
# badgr auto-detects comfyui images and polls /system_stats for readiness

ComfyUI images are automatically health-checked via /system_stats before the endpoint is marked ready. Use --health-path to specify a custom readiness path for other custom images.

2. Call the endpoint

Python (Diffusers API)

import requests, base64, io
from PIL import Image

resp = requests.post(
    "https://dep-a1b2c3.api.badgr.ai/generate",
    headers={"Authorization": "Bearer your-badgr-api-key"},
    json={
        "prompt": "A futuristic city at sunset, photorealistic",
        "num_inference_steps": 4,
        "width": 1024,
        "height": 1024,
    },
)
resp.raise_for_status()
img = Image.open(io.BytesIO(base64.b64decode(resp.json()["image"])))
img.save("output.png")

curl

curl https://dep-a1b2c3.api.badgr.ai/generate \
  -H "Authorization: Bearer $BADGR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A futuristic city at sunset, photorealistic",
    "num_inference_steps": 4,
    "width": 1024,
    "height": 1024
  }' | jq -r '.image' | base64 -d > output.png

3. Stop billing

badgr down <deployment-id>

Terminates the GPU instance. Use badgr receipts to see cost after.

Options

--image <ref>Your Docker image with Diffusers or ComfyUI and model weights
--gpu <type>L40S or A100 recommended for diffusion models
--env KEY=VALUESet environment variables — repeatable
--max-price 2.00Hard price cap in USD/hr
--max-cost 10.00Auto-stop when total spend reaches this amount
--count <n>Number of GPUs (default: 1)
--health-path <path>Readiness path to poll before marking ready (auto: /system_stats for ComfyUI)
--no-waitReturn immediately; use badgr logs to confirm startup

Next steps