# 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({
"3": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"53",
0
],
"model": [
"70",
0
],
"negative": [
"40",
0
],
"positive": [
"16",
0
],
"sampler_name": "lcm",
"scheduler": "normal",
"seed": 426270906276990,
"steps": 28
},
"_meta": {
"title": "KSampler"
}
},
"8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"3",
0
],
"vae": [
"55",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"16": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"54",
0
],
"text": "A photograph of an albino woman with white skin and dark hair wearing black in the style of old baroque oil paintings, with soft focus, wearing a pearl necklace around her neck, with a dark background, with rosy cheeks, with a long veil covering her face, looking straight ahead"
},
"_meta": {
"title": "Positive Prompt"
}
},
"40": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"54",
0
],
"text": "bad ugly jpeg artifacts"
},
"_meta": {
"title": "Negative Prompt"
}
},
"53": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 1024,
"width": 1024
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"54": {
"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)"
}
},
"55": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"70": {
"class_type": "ModelSamplingSD3",
"inputs": {
"model": [
"76",
0
],
"shift": 6.000000000000001
},
"_meta": {
"title": "ModelSamplingSD3"
}
},
"76": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "hidream_i1_dev_fp8.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)