# 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": 8,
"denoise": 1,
"latent_image": [
"5",
0
],
"model": [
"40",
0
],
"negative": [
"7",
0
],
"positive": [
"37",
0
],
"sampler_name": "dpmpp_3m_sde_gpu",
"scheduler": "exponential",
"seed": 900749379955168,
"steps": 26
},
"_meta": {
"title": "KSampler"
}
},
"5": {
"class_type": "EmptyLatentImage",
"inputs": {
"batch_size": 1,
"height": 1024,
"width": 1024
},
"_meta": {
"title": "Empty Latent Image"
}
},
"6": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"40",
1
],
"text": "car, city, anime style"
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"7": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"40",
1
],
"text": "text, watermark"
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"3",
0
],
"vae": [
"40",
2
]
},
"_meta": {
"title": "VAE Decode"
}
},
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"13": {
"class_type": "CLIPVisionEncode",
"inputs": {
"clip_vision": [
"39",
0
],
"crop": "center",
"image": [
"34",
0
]
},
"_meta": {
"title": "CLIP Vision Encode"
}
},
"19": {
"class_type": "unCLIPConditioning",
"inputs": {
"clip_vision_output": [
"13",
0
],
"conditioning": [
"6",
0
],
"noise_augmentation": 0,
"strength": 0.75
},
"_meta": {
"title": "unCLIPConditioning"
}
},
"34": {
"class_type": "LoadImage",
"inputs": {
"image": "sdxl_revision_text_prompts_ref_image1.png"
},
"_meta": {
"title": "Load Image"
}
},
"36": {
"class_type": "CLIPVisionEncode",
"inputs": {
"clip_vision": [
"39",
0
],
"crop": "center",
"image": [
"38",
0
]
},
"_meta": {
"title": "CLIP Vision Encode"
}
},
"37": {
"class_type": "unCLIPConditioning",
"inputs": {
"clip_vision_output": [
"36",
0
],
"conditioning": [
"19",
0
],
"noise_augmentation": 0,
"strength": 0.75
},
"_meta": {
"title": "unCLIPConditioning"
}
},
"38": {
"class_type": "LoadImage",
"inputs": {
"image": "sdxl_revision_text_prompts_ref_image2.png"
},
"_meta": {
"title": "Load Image"
}
},
"39": {
"class_type": "CLIPVisionLoader",
"inputs": {
"clip_name": "clip_vision_g.safetensors"
},
"_meta": {
"title": "Load CLIP Vision"
}
},
"40": {
"class_type": "CheckpointLoaderSimple",
"inputs": {
"ckpt_name": "sd_xl_base_1.0.safetensors"
},
"_meta": {
"title": "Load Checkpoint"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)