# 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({
"6": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"42",
0
],
"text": "Let the girl put on the VR glasses full of a sense of technology, just like the scenes in Ready Player One, with CG rendering and ultra-realism."
},
"_meta": {
"title": "Positive"
}
},
"7": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"42",
0
],
"text": "low quality, blurry, distorted"
},
"_meta": {
"title": "Negative"
}
},
"8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"54",
0
],
"vae": [
"43",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"13": {
"class_type": "LoadImage",
"inputs": {
"image": "hidream_e1_full_input_image.jpg"
},
"_meta": {
"title": "Load Image"
}
},
"41": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "hidream_e1_full_bf16.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"42": {
"class_type": "QuadrupleCLIPLoader",
"inputs": {
"clip_name1": "clip_g_hidream.safetensors",
"clip_name2": "clip_l_hidream.safetensors",
"clip_name3": "t5xxl_fp8_e4m3fn_scaled.safetensors",
"clip_name4": "llama_3.1_8b_instruct_fp8_scaled.safetensors"
},
"_meta": {
"title": "Load CLIP (Quadruple)"
}
},
"43": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"44": {
"class_type": "ImageScale",
"inputs": {
"crop": "center",
"height": 768,
"image": [
"13",
0
],
"upscale_method": "bilinear",
"width": 768
},
"_meta": {
"title": "Upscale Image"
}
},
"46": {
"class_type": "KSamplerSelect",
"inputs": {
"sampler_name": "euler"
},
"_meta": {
"title": "KSamplerSelect"
}
},
"47": {
"class_type": "RandomNoise",
"inputs": {
"noise_seed": 705826023365990
},
"_meta": {
"title": "RandomNoise"
}
},
"49": {
"class_type": "BasicScheduler",
"inputs": {
"denoise": 1,
"model": [
"41",
0
],
"scheduler": "normal",
"steps": 28
},
"_meta": {
"title": "BasicScheduler"
}
},
"52": {
"class_type": "InstructPixToPixConditioning",
"inputs": {
"negative": [
"7",
0
],
"pixels": [
"44",
0
],
"positive": [
"6",
0
],
"vae": [
"43",
0
]
},
"_meta": {
"title": "InstructPixToPixConditioning"
}
},
"53": {
"class_type": "DualCFGGuider",
"inputs": {
"cfg_cond2_negative": 2,
"cfg_conds": 5,
"cond1": [
"52",
0
],
"cond2": [
"52",
1
],
"model": [
"41",
0
],
"negative": [
"7",
0
],
"style": "regular"
},
"_meta": {
"title": "Dual CFG Guider"
}
},
"54": {
"class_type": "SamplerCustomAdvanced",
"inputs": {
"guider": [
"53",
0
],
"latent_image": [
"52",
2
],
"noise": [
"47",
0
],
"sampler": [
"46",
0
],
"sigmas": [
"49",
0
]
},
"_meta": {
"title": "SamplerCustomAdvanced"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)