# Python 3.10+: pip install comfy-sdk==0.4.0
import os
from comfy_sdk import Comfy
api_key = os.environ.get("COMFY_API_KEY", "").strip()
if not api_key: raise RuntimeError("Set COMFY_API_KEY")
os.environ.setdefault("COMFY_BASE_URL", "https://cloud.comfy.org")
client = Comfy(api_key=api_key)
workflow = client.workflows.from_json({
"81": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"82": {
"class_type": "QuadrupleCLIPLoader",
"inputs": {
"clip_name1": "clip_l_hidream.safetensors",
"clip_name2": "clip_g_hidream.safetensors",
"clip_name3": "t5xxl_fp8_e4m3fn_scaled.safetensors",
"clip_name4": "llama_3.1_8b_instruct_fp8_scaled.safetensors"
},
"_meta": {
"title": "Load CLIP (Quadruple)"
}
},
"84": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 1024,
"width": 1024
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"85": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"82",
0
],
"text": "A lo-fi, grungy wide shot of a ragged large red tree leaning slightly to one side Polaroid aesthetic. the tree is alone in a desolate landscape, the tree is illuminated by a red light, the background is pitch black"
},
"_meta": {
"title": "Positive Prompt"
}
},
"86": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"94",
0
],
"vae": [
"81",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"88": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"86",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"90": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"82",
0
],
"text": "bad ugly jpeg artifacts"
},
"_meta": {
"title": "Negative Prompt"
}
},
"91": {
"class_type": "ModelSamplingSD3",
"inputs": {
"model": [
"93",
0
],
"shift": 3
},
"_meta": {
"title": "ModelSamplingSD3"
}
},
"93": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "hidream_i1_fast_fp8.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"94": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"84",
0
],
"model": [
"91",
0
],
"negative": [
"90",
0
],
"positive": [
"85",
0
],
"sampler_name": "lcm",
"scheduler": "normal",
"seed": 833271177511441,
"steps": 16
},
"_meta": {
"title": "KSampler"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)