# 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": "ComfyUI",
"images": [
"111:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"71": {
"class_type": "LoadImage",
"inputs": {
"image": "image_qwen_image_instantx_controlnet_input_image.jpg"
},
"_meta": {
"title": "Load Image"
}
},
"73": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"112:22",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"113": {
"class_type": "FluxKontextImageScale",
"inputs": {
"image": [
"71",
0
]
},
"_meta": {
"title": "FluxKontextImageScale"
}
},
"111:3": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"111:76",
0
],
"model": [
"111:66",
0
],
"negative": [
"111:85",
1
],
"positive": [
"111:85",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 498544006715206,
"steps": 4
},
"_meta": {
"title": "KSampler"
}
},
"111:37": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "qwen_image_fp8_e4m3fn.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"111:38": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_2.5_vl_7b_fp8_scaled.safetensors",
"device": "default",
"type": "qwen_image"
},
"_meta": {
"title": "Load CLIP"
}
},
"111:39": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "qwen_image_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"111:6": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"111:38",
0
],
"text": "Post-apocalyptic style clothing, long wavy hair, rough texture, exotic woman, tattered coarse-woven linen fabric, wearing a hood, mechanical aesthetics, mainly in dark gray tones, low-saturation earthy yellow, sense of impact and rebellion, doomsday aesthetics, grotesque aesthetics, works of art, backlighting, film photography, professional photography works, clear visible face, emotional and atmospheric dynamic photography, Fujichrome color positive film, shot with a 17mm Hasselblad ultra-wide-angle lens, f/1.2 large aperture, side backlighting, artistic light, hair light, Rembrandt light, 8K high-definition image quality, delicate real human skin texture."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"111:66": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"111:80",
0
],
"sampling": "flow",
"shift": 3.1000000000000005
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"111:7": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"111:38",
0
],
"text": ""
},
"_meta": {
"title": "CLIP Text Encode (Negative Prompt)"
}
},
"111:76": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"112:22",
0
],
"vae": [
"111:39",
0
]
},
"_meta": {
"title": "VAE Encode"
}
},
"111:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"111:3",
0
],
"vae": [
"111:39",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"111:80": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "Qwen-Image-Lightning-4steps-V1.0.safetensors",
"model": [
"111:37",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"111:84": {
"class_type": "ControlNetLoader",
"inputs": {
"control_net_name": "Qwen-Image-InstantX-ControlNet-Union.safetensors"
},
"_meta": {
"title": "Load ControlNet Model"
}
},
"111:85": {
"class_type": "ControlNetApplyAdvanced",
"inputs": {
"control_net": [
"111:84",
0
],
"end_percent": 1,
"image": [
"112:22",
0
],
"negative": [
"111:7",
0
],
"positive": [
"111:6",
0
],
"start_percent": 0,
"strength": 1,
"vae": [
"111:39",
0
]
},
"_meta": {
"title": "Apply ControlNet"
}
},
"112:10": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "lotus-depth-d-v1-1.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"112:14": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "vae-ft-mse-840000-ema-pruned.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"112:16": {
"class_type": "SamplerCustomAdvanced",
"inputs": {
"guider": [
"112:19",
0
],
"latent_image": [
"112:23",
0
],
"noise": [
"112:18",
0
],
"sampler": [
"112:21",
0
],
"sigmas": [
"112:28",
0
]
},
"_meta": {
"title": "SamplerCustomAdvanced"
}
},
"112:18": {
"class_type": "DisableNoise",
"inputs": {},
"_meta": {
"title": "DisableNoise"
}
},
"112:19": {
"class_type": "BasicGuider",
"inputs": {
"conditioning": [
"112:68",
0
],
"model": [
"112:10",
0
]
},
"_meta": {
"title": "Basic Guider"
}
},
"112:20": {
"class_type": "BasicScheduler",
"inputs": {
"denoise": 1,
"model": [
"112:10",
0
],
"scheduler": "normal",
"steps": 1
},
"_meta": {
"title": "BasicScheduler"
}
},
"112:21": {
"class_type": "KSamplerSelect",
"inputs": {
"sampler_name": "euler"
},
"_meta": {
"title": "KSamplerSelect"
}
},
"112:22": {
"class_type": "ImageInvert",
"inputs": {
"image": [
"112:8",
0
]
},
"_meta": {
"title": "Invert Image Colors"
}
},
"112:23": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"113",
0
],
"vae": [
"112:14",
0
]
},
"_meta": {
"title": "VAE Encode"
}
},
"112:28": {
"class_type": "SetFirstSigma",
"inputs": {
"sigma": 999.0000000000002,
"sigmas": [
"112:20",
0
]
},
"_meta": {
"title": "SetFirstSigma"
}
},
"112:68": {
"class_type": "LotusConditioning",
"inputs": {},
"_meta": {
"title": "LotusConditioning"
}
},
"112:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"112:16",
0
],
"vae": [
"112:14",
0
]
},
"_meta": {
"title": "VAE Decode"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)