# 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": 4,
"denoise": 1,
"latent_image": [
"33",
0
],
"model": [
"4",
0
],
"negative": [
"58",
1
],
"positive": [
"58",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 268264726798396,
"steps": 30
},
"_meta": {
"title": "KSampler"
}
},
"4": {
"class_type": "CheckpointLoaderSimple",
"inputs": {
"ckpt_name": "sd3.5_large_fp8_scaled.safetensors"
},
"_meta": {
"title": "Load Checkpoint"
}
},
"6": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"4",
1
],
"text": "crystal butterfly above the sea, white, hyper detailed, with diamonds"
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"3",
0
],
"vae": [
"4",
2
]
},
"_meta": {
"title": "VAE Decode"
}
},
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"33": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 1024,
"width": 1024
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"46": {
"class_type": "ControlNetLoader",
"inputs": {
"control_net_name": "sd3.5_large_controlnet_blur.safetensors"
},
"_meta": {
"title": "Load ControlNet Model"
}
},
"50": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"6",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"57": {
"class_type": "LoadImage",
"inputs": {
"image": "sd3.5_large_blur_input_image.png"
},
"_meta": {
"title": "Load Image"
}
},
"58": {
"class_type": "ControlNetApplyAdvanced",
"inputs": {
"control_net": [
"46",
0
],
"end_percent": 1,
"image": [
"57",
0
],
"negative": [
"50",
0
],
"positive": [
"6",
0
],
"start_percent": 0,
"strength": 1,
"vae": [
"4",
2
]
},
"_meta": {
"title": "Apply ControlNet"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)