Skip to main content

Python SDK for running ComfyUI workflows on RunPod — serverless endpoints and persistent pods.

Project description

RunPod Comfy SDK

A Python SDK for running ComfyUI workflows on RunPod — supports both serverless endpoints and persistent pod instances through a single unified client.

Installation

pip install runpod-comfy-sdk

Quick Start

from runpod_comfy import RunPodComfyClient

client = RunPodComfyClient()

# Serverless endpoint
sl = client.serverless(api_key="YOUR_KEY", endpoint_id="YOUR_ENDPOINT_ID")

# Persistent pod
pod = client.pod(pod_id="YOUR_POD_ID", api_key="YOUR_KEY")

Serverless Usage

Use this when your ComfyUI is deployed as a RunPod serverless endpoint.

Initialize

from runpod_comfy import RunPodComfyClient

client = RunPodComfyClient()
sl = client.serverless(
    api_key="YOUR_RUNPOD_API_KEY",
    endpoint_id="YOUR_RUNPOD_ENDPOINT_ID",
)

Check Health

health = sl.get_health()
print(health)

Example response:

{ "workers": { "idle": 2, "running": 0 } }

Run a Workflow

Pass a path to a workflow_api.json file (ComfyUI API format) and any input images:

# Images as a list — filenames are used as ComfyUI node identifiers
result = sl.run_sync(
    workflow="workflow_api.json",
    images=["image1.jpg", "image2.jpg"],
)

# Images as a dict — map custom ComfyUI node names to local paths
result = sl.run_sync(
    workflow="workflow_api.json",
    images={"my_input.jpg": "path/to/local/image.jpg"},
)

Full Serverless Example

from runpod_comfy import RunPodComfyClient

client = RunPodComfyClient()
sl = client.serverless(
    api_key="YOUR_RUNPOD_API_KEY",
    endpoint_id="YOUR_RUNPOD_ENDPOINT_ID",
)

print("Health:", sl.get_health())

try:
    result = sl.run_sync(
        workflow="workflow_api.json",
        images=["image1.jpg"],
    )
    print("Output images (base64):", result["output"]["images"])
except Exception as e:
    print(f"Error: {e}")

Pod Usage

Use this when your ComfyUI is running on a persistent RunPod pod (always-on GPU).

Initialize

from runpod_comfy import RunPodComfyClient

client = RunPodComfyClient()
pod = client.pod(
    pod_id="YOUR_POD_ID",          # e.g. "abc123xyz" — the -8188 suffix is handled automatically
    api_key="YOUR_RUNPOD_API_KEY", # optional if the pod proxy port is public
)

Check Health

health = pod.get_health()
print(health)

Example response:

{ "status": "HEALTHY", "message": "ComfyUI Server is active and warming VRAM." }

Run a Workflow

# Images as a list
result = pod.run_sync(
    workflow="workflow_api.json",
    images=["image1.jpg", "image2.jpg"],
    timeout_seconds=300,  # optional, default 240
)

# Images as a dict
result = pod.run_sync(
    workflow="workflow_api.json",
    images={"my_input.jpg": "path/to/local/image.jpg"},
)

Full Pod Example

from runpod_comfy import RunPodComfyClient

client = RunPodComfyClient()
pod = client.pod(pod_id="abc123xyz", api_key="YOUR_RUNPOD_API_KEY")

print("Health:", pod.get_health())

try:
    result = pod.run_sync(
        workflow="workflow_api.json",
        images=["image1.jpg"],
        timeout_seconds=300,
    )
    print("Output images (base64):", result["output"]["images"])
except TimeoutError:
    print("Workflow timed out.")
except Exception as e:
    print(f"Error: {e}")

API Reference

RunPodComfyClient

A stateless factory. No credentials are stored on this object.

Method Returns Description
.serverless(api_key, endpoint_id) ServerlessClient Client for a serverless endpoint
.pod(pod_id, api_key=None) PodClient Client for a persistent pod

ServerlessClient

Obtained via client.serverless(...).

Constructor

Parameter Type Required Description
api_key str Your RunPod API key
endpoint_id str Your RunPod serverless endpoint ID

Methods

get_health() → dict Check the health status of the serverless endpoint.

run_sync(workflow, images) → dict

Parameter Type Required Description
workflow str | dict Path to workflow_api.json or a pre-loaded dict
images list[str] | dict[str, str] List of local paths or {node_name: local_path} dict

PodClient

Obtained via client.pod(...).

Constructor

Parameter Type Required Description
pod_id str Your RunPod pod ID (e.g. "abc123xyz")
api_key str API key — only needed for private proxy ports

Methods

get_health() → dict Check whether the ComfyUI server on the pod is alive.

run_sync(workflow, images, timeout_seconds=240) → dict

Parameter Type Required Description
workflow str | dict Path to workflow_api.json or a pre-loaded dict
images list[str] | dict[str, str] List of local paths or {comfyui_filename: local_path} dict
timeout_seconds int Max wait time before TimeoutError (default: 240)

Response Format

Both ServerlessClient.run_sync() and PodClient.run_sync() return a compatible response shape:

{
  "id": "prompt-uuid",
  "status": "COMPLETED",
  "delayTime": 1200,
  "executionTime": 8500,
  "output": {
    "message": "Generation completed successfully.",
    "images": ["<base64-string>", "..."]
  }
}

Error Handling

try:
    result = sl.run_sync(workflow="workflow_api.json", images=["input.jpg"])
except TimeoutError:
    print("Execution timed out.")
except requests.HTTPError as e:
    print(f"HTTP error: {e.response.status_code}")
except Exception as e:
    print(f"Unexpected error: {e}")

Requirements

  • Python 3.9+
  • requests >= 2.32.0
  • Active RunPod account
  • A deployed ComfyUI serverless endpoint and/or a running ComfyUI pod

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

runpod_comfy_sdk-0.1.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

runpod_comfy_sdk-0.1.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file runpod_comfy_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: runpod_comfy_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for runpod_comfy_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 14be16c34dbe0ba4e7d3f70cc0047da61ac44815ae6853385a71fd6e10f135db
MD5 82bac0e5680791dc5136abadfd334f1f
BLAKE2b-256 88695efe2ae7cb7a880d9ae08e9e156bd71d03799c88fc9344ab8be36c4df7f5

See more details on using hashes here.

File details

Details for the file runpod_comfy_sdk-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for runpod_comfy_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e8f538306ef488e54eb922432c89742e73df33f8ab9223236dcf4cdcf6da00d7
MD5 c0fac3ef23f946252570ecff44b53b8c
BLAKE2b-256 00cca117d73abe4e3c9823af81a8c54ea559100bf502734bf78ae8121e19b8fd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page