# 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({
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "flux_krea",
"images": [
"53:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"53:27": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 768,
"width": 1360
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"53:31": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"53:27",
0
],
"model": [
"53:38",
0
],
"negative": [
"53:42",
0
],
"positive": [
"53:45",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 277251746703202,
"steps": 20
},
"_meta": {
"title": "KSampler"
}
},
"53:38": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "flux1-krea-dev_fp8_scaled.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"53:39": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"53:40": {
"class_type": "DualCLIPLoader",
"inputs": {
"clip_name1": "clip_l.safetensors",
"clip_name2": "t5xxl_fp16.safetensors",
"device": "default",
"type": "flux"
},
"_meta": {
"title": "Load CLIP (Dual)"
}
},
"53:42": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"53:45",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"53:45": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"53:40",
0
],
"text": "A young Mexican-American farm laborer in the 1930s pauses with a rusted steel hoe in a parched orchard. He has a lean, sinewy build, sharp cheekbones, and cropped dark hair beneath a sweat-stained wool felt hat, wearing a sun-bleached chambray work shirt dusted with dry alkaline earth. Close documentary portrait with real skin texture, showing open pores, coarse stubble, and rivulets of perspiration cutting through windblown grit across his brow. High-contrast, searing midday sunlight casts deep, sharp shadows under his hat brim, catching shimmering heat and suspended dust motes around his shoulders. The shallow depth of field softly blurs the scorched, cracked soil and rows of wilted fruit trees stretching endlessly across the background behind his focused, weary expression."
},
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"53:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"53:31",
0
],
"vae": [
"53:39",
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)
for output in job.get_outputs("9"):
output.to_file(output.name)