# 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({
"6": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"10",
0
],
"text": "Transform character into crystal material, transparent crystal texture, sparkling surface, prismatic light effects, magical appearance, elegant translucent look"
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"7": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"10",
0
],
"text": "deformed, blurry, over saturation, bad anatomy, disfigured, poorly drawn face, mutation, mutated, extra_limb, ugly, poorly drawn hands, fused fingers, messy drawing, broken legs censor, censored, censor_bar"
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"28",
0
],
"vae": [
"13",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"10": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "qwen_2.5_vl_fp16.safetensors",
"device": "default",
"type": "omnigen2"
},
"_meta": {
"title": "Load CLIP"
}
},
"11": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": [
"32",
1
],
"width": [
"32",
0
]
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"12": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "omnigen2_fp16.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"13": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"14": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"17",
0
],
"vae": [
"13",
0
]
},
"_meta": {
"title": "VAE Encode"
}
},
"15": {
"class_type": "ReferenceLatent",
"inputs": {
"conditioning": [
"6",
0
],
"latent": [
"14",
0
]
},
"_meta": {
"title": "Set Reference Latent"
}
},
"16": {
"class_type": "LoadImage",
"inputs": {
"image": "image_omnigen2_image_edit_input_image.png"
},
"_meta": {
"title": "Load Image"
}
},
"17": {
"class_type": "ImageScaleToTotalPixels",
"inputs": {
"image": [
"16",
0
],
"megapixels": 1,
"resolution_steps": 1,
"upscale_method": "area"
},
"_meta": {
"title": "Scale Image to Total Pixels"
}
},
"20": {
"class_type": "KSamplerSelect",
"inputs": {
"sampler_name": "euler"
},
"_meta": {
"title": "KSamplerSelect"
}
},
"21": {
"class_type": "RandomNoise",
"inputs": {
"noise_seed": 441693270797774
},
"_meta": {
"title": "RandomNoise"
}
},
"23": {
"class_type": "BasicScheduler",
"inputs": {
"denoise": 1,
"model": [
"12",
0
],
"scheduler": "simple",
"steps": 20
},
"_meta": {
"title": "BasicScheduler"
}
},
"27": {
"class_type": "DualCFGGuider",
"inputs": {
"cfg_cond2_negative": 2,
"cfg_conds": 5,
"cond1": [
"15",
0
],
"cond2": [
"29",
0
],
"model": [
"12",
0
],
"negative": [
"7",
0
],
"style": "regular"
},
"_meta": {
"title": "Dual CFG Guider"
}
},
"28": {
"class_type": "SamplerCustomAdvanced",
"inputs": {
"guider": [
"27",
0
],
"latent_image": [
"11",
0
],
"noise": [
"21",
0
],
"sampler": [
"20",
0
],
"sigmas": [
"23",
0
]
},
"_meta": {
"title": "SamplerCustomAdvanced"
}
},
"29": {
"class_type": "ReferenceLatent",
"inputs": {
"conditioning": [
"7",
0
],
"latent": [
"14",
0
]
},
"_meta": {
"title": "Set Reference Latent"
}
},
"32": {
"class_type": "GetImageSize",
"inputs": {
"image": [
"17",
0
]
},
"_meta": {
"title": "Get Image Size"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)