# 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({
"4": {
"class_type": "CheckpointLoaderSimple",
"inputs": {
"ckpt_name": "sd3.5_large_fp8_scaled.safetensors"
},
"_meta": {
"title": "Load Checkpoint"
}
},
"8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"56",
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"
}
},
"45": {
"class_type": "LoadImage",
"inputs": {
"image": "sd3.5_large_depth_input_image.png"
},
"_meta": {
"title": "Load Image"
}
},
"46": {
"class_type": "ControlNetLoader",
"inputs": {
"control_net_name": "sd3.5_large_controlnet_depth.safetensors"
},
"_meta": {
"title": "Load ControlNet Model"
}
},
"56": {
"class_type": "KSampler",
"inputs": {
"cfg": 8,
"denoise": 1,
"latent_image": [
"77",
0
],
"model": [
"4",
0
],
"negative": [
"61",
1
],
"positive": [
"61",
0
],
"sampler_name": "euler",
"scheduler": "normal",
"seed": 1020711502084247,
"steps": 20
},
"_meta": {
"title": "KSampler"
}
},
"57": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"4",
1
],
"text": "A cute, plush - like light green baby dragon with large, shiny eyes. It has light yellow horns and wing membranes. Its belly and parts of its wings have a soft, fuzzy texture. The dragon stands against a plain light green background, giving a warm and whimsical feel."
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"58": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"57",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"61": {
"class_type": "ControlNetApplyAdvanced",
"inputs": {
"control_net": [
"46",
0
],
"end_percent": 1,
"image": [
"68:99",
0
],
"negative": [
"58",
0
],
"positive": [
"57",
0
],
"start_percent": 0,
"strength": 0.7000000000000002,
"vae": [
"4",
2
]
},
"_meta": {
"title": "Apply ControlNet"
}
},
"70": {
"class_type": "ImageScaleToTotalPixels",
"inputs": {
"image": [
"45",
0
],
"megapixels": 1,
"resolution_steps": 1,
"upscale_method": "lanczos"
},
"_meta": {
"title": "Scale Image to Total Pixels"
}
},
"73": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"68:99",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"77": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"68:99",
0
],
"vae": [
"4",
2
]
},
"_meta": {
"title": "VAE Encode"
}
},
"68:100": {
"class_type": "KSamplerSelect",
"inputs": {
"sampler_name": "euler"
},
"_meta": {
"title": "KSamplerSelect"
}
},
"68:101": {
"class_type": "SetFirstSigma",
"inputs": {
"sigma": 10000,
"sigmas": [
"68:95",
0
]
},
"_meta": {
"title": "SetFirstSigma"
}
},
"68:87": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "lotus-depth-d-v1-1.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"68:89": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "vae-ft-mse-840000-ema-pruned.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"68:92": {
"class_type": "SamplerCustomAdvanced",
"inputs": {
"guider": [
"68:94",
0
],
"latent_image": [
"68:97",
0
],
"noise": [
"68:93",
0
],
"sampler": [
"68:100",
0
],
"sigmas": [
"68:101",
0
]
},
"_meta": {
"title": "SamplerCustomAdvanced"
}
},
"68:93": {
"class_type": "DisableNoise",
"inputs": {},
"_meta": {
"title": "DisableNoise"
}
},
"68:94": {
"class_type": "BasicGuider",
"inputs": {
"conditioning": [
"68:96",
0
],
"model": [
"68:87",
0
]
},
"_meta": {
"title": "Basic Guider"
}
},
"68:95": {
"class_type": "BasicScheduler",
"inputs": {
"denoise": 1,
"model": [
"68:87",
0
],
"scheduler": "normal",
"steps": 1
},
"_meta": {
"title": "BasicScheduler"
}
},
"68:96": {
"class_type": "LotusConditioning",
"inputs": {},
"_meta": {
"title": "LotusConditioning"
}
},
"68:97": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"70",
0
],
"vae": [
"68:89",
0
]
},
"_meta": {
"title": "VAE Encode"
}
},
"68:98": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"68:92",
0
],
"vae": [
"68:89",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"68:99": {
"class_type": "ImageInvert",
"inputs": {
"image": [
"68:98",
0
]
},
"_meta": {
"title": "Invert Image Colors"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)