# 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": [
"35",
2
],
"model": [
"31",
0
],
"negative": [
"35",
1
],
"positive": [
"35",
0
],
"sampler_name": "euler",
"scheduler": "normal",
"seed": 1125476660951871,
"steps": 20
},
"_meta": {
"title": "KSampler"
}
},
"8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"3",
0
],
"vae": [
"32",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"17": {
"class_type": "LoadImage",
"inputs": {
"image": "flux_canny_model_example_input_image.png"
},
"_meta": {
"title": "Load Image"
}
},
"18": {
"class_type": "Canny",
"inputs": {
"high_threshold": 0.3,
"image": [
"17",
0
],
"low_threshold": 0.15
},
"_meta": {
"title": "Detect Edges (Canny)"
}
},
"19": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"18",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"23": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"34",
0
],
"text": "A vibrant red ladybug rests on a blooming deep purple rose with lush, velvety petals. The background is a soft pink, filled with subtly blurred roses of the same pink shade, creating a dreamy and romantic atmosphere."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"26": {
"class_type": "FluxGuidance",
"inputs": {
"conditioning": [
"23",
0
],
"guidance": 30
},
"_meta": {
"title": "FluxGuidance"
}
},
"31": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "flux1-canny-dev.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"32": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"34": {
"class_type": "DualCLIPLoader",
"inputs": {
"clip_name1": "clip_l.safetensors",
"clip_name2": "t5xxl_fp16.safetensors",
"device": "default",
"type": "flux"
},
"_meta": {
"title": "Load CLIP (Dual)"
}
},
"35": {
"class_type": "InstructPixToPixConditioning",
"inputs": {
"negative": [
"37",
0
],
"pixels": [
"18",
0
],
"positive": [
"26",
0
],
"vae": [
"32",
0
]
},
"_meta": {
"title": "InstructPixToPixConditioning"
}
},
"37": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"23",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)