# 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({
"60": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "Qwen-Image-2512",
"images": [
"86:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"121": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"122": {
"class_type": "Canny",
"inputs": {
"high_threshold": 0.35,
"image": [
"123",
0
],
"low_threshold": 0.33
},
"_meta": {
"title": "Detect Edges (Canny)"
}
},
"123": {
"class_type": "ResizeImageMaskNode",
"inputs": {
"input": [
"121",
0
],
"resize_type": "scale total pixels",
"resize_type.megapixels": 1.6,
"scale_method": "area"
},
"_meta": {
"title": "Resize Image/Mask"
}
},
"125": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"123",
0
]
},
"_meta": {
"title": "Get Image Size"
}
},
"126": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"122",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"86:111": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "Qwen-Image-Lightning-4steps-V1.0.safetensors",
"model": [
"86:37",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"86:112": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"86:37",
0
],
"on_true": [
"86:111",
0
],
"switch": [
"86:118",
0
]
},
"_meta": {
"title": "If/Else Switch"
}
},
"86:113": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 50
},
"_meta": {
"title": "Steps"
}
},
"86:115": {
"class_type": "PrimitiveFloat",
"inputs": {
"value": 4
},
"_meta": {
"title": "CFG"
}
},
"86:116": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 4
},
"_meta": {
"title": "Steps"
}
},
"86:117": {
"class_type": "PrimitiveFloat",
"inputs": {
"value": 1
},
"_meta": {
"title": "CFG"
}
},
"86:118": {
"class_type": "PrimitiveBoolean",
"inputs": {
"value": False
},
"_meta": {
"title": "Enable 4 Steps LoRA?"
}
},
"86:119": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"86:113",
0
],
"on_true": [
"86:116",
0
],
"switch": [
"86:118",
0
]
},
"_meta": {
"title": "If/Else Switch"
}
},
"86:120": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"86:115",
0
],
"on_true": [
"86:117",
0
],
"switch": [
"86:118",
0
]
},
"_meta": {
"title": "If/Else Switch"
}
},
"86:121": {
"class_type": "ControlNetApplyAdvanced",
"inputs": {
"control_net": [
"86:122",
0
],
"end_percent": 1,
"image": [
"122",
0
],
"negative": [
"86:7",
0
],
"positive": [
"86:81",
0
],
"start_percent": 0,
"strength": 1,
"vae": [
"86:39",
0
]
},
"_meta": {
"title": "Apply ControlNet"
}
},
"86:122": {
"class_type": "ControlNetLoader",
"inputs": {
"control_net_name": "Qwen-Image-2512-Fun-Controlnet-Union-2602.safetensors"
},
"_meta": {
"title": "Load ControlNet Model"
}
},
"86:3": {
"class_type": "KSampler",
"inputs": {
"cfg": [
"86:120",
0
],
"denoise": 1,
"latent_image": [
"86:58",
0
],
"model": [
"86:66",
0
],
"negative": [
"86:121",
1
],
"positive": [
"86:121",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 985578626029454,
"steps": [
"86:119",
0
]
},
"_meta": {
"title": "KSampler"
}
},
"86:37": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "qwen_image_2512_fp8_e4m3fn.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"86:38": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_2.5_vl_7b_fp8_scaled.safetensors",
"device": "default",
"type": "qwen_image"
},
"_meta": {
"title": "Load CLIP"
}
},
"86:39": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "qwen_image_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"86:58": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": [
"125",
1
],
"width": [
"125",
0
]
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"86:66": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"86:112",
0
],
"sampling": "flow",
"shift": 3.1000000000000005
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"86:7": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"86:38",
0
],
"text": "低分辨率,低画质,肢体畸形,手指畸形,画面过饱和,蜡像感,人脸无细节,过度光滑,画面具有AI感。构图混乱。文字模糊,扭曲"
},
"_meta": {
"title": "CLIP Text Encode (Negative Prompt)"
}
},
"86:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"86:3",
0
],
"vae": [
"86:39",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"86:81": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"86:38",
0
],
"text": "A vast underwater cathedral grown from living coral, its arches formed by the curved white ribs of an ancient whale skeleton encrusted with pink and violet coral, sea fans and barnacles. The arches recede in a long perspective tunnel toward a bright opening where sunlight floods down through blue water in shimmering god rays. The floor is pale rippled sand dotted with clusters of anemones, starfish and small sea urchins, with a giant open clam shell resting near the centre catching the light. Schools of tiny silver fish drift between the ribs, and soft caustic light patterns dance across every surface. Photorealistic underwater photography, deep turquoise and teal water, warm coral pinks and sandy golds, crisp detail, calm and dreamlike atmosphere, no divers or people."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
}
})
workflow.set_input("121", "image", client.assets.from_url("https://comfy.org/catalog-media/6116c337-3883-4a70-a93d-5d1dc06c0ec4/1d4b583e-cc57-4e12-a00d-bc9598e92091"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)
for output in job.get_outputs("60"):
output.to_file(output.name)