# 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": [
"11",
0
],
"text": "A weathered fishing bothy constructed from rusted corrugated iron and charred larch timber clings to a jagged basalt shoreline beside a churning North Atlantic fjord at desolate twilight. Deep indigo dusk blankets the expansive seascape, contrasted by a single bare incandescent bulb casting a harsh amber glow through salt-crusted glass. Outside on the damp treated-wood jetty, a solitary figure draped in a heavy, drenched oilskin coat pauses, gazing across the cold, crashing surf toward the distant horizon. Slick black stones, glistening wet kelp, and foaming tide pools sprawl along the water's edge, while biting ocean spray and low-hanging storm clouds complete the bleak, isolated atmosphere."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"13",
0
],
"vae": [
"10",
0
]
},
"_meta": {
"title": "VAE Decode"
}
},
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"10": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"11": {
"class_type": "DualCLIPLoader",
"inputs": {
"clip_name1": "t5xxl_fp16.safetensors",
"clip_name2": "clip_l.safetensors",
"device": "default",
"type": "flux"
},
"_meta": {
"title": "Load CLIP (Dual)"
}
},
"12": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "flux1-dev.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"13": {
"class_type": "SamplerCustomAdvanced",
"inputs": {
"guider": [
"22",
0
],
"latent_image": [
"27",
0
],
"noise": [
"25",
0
],
"sampler": [
"16",
0
],
"sigmas": [
"17",
0
]
},
"_meta": {
"title": "SamplerCustomAdvanced"
}
},
"16": {
"class_type": "KSamplerSelect",
"inputs": {
"sampler_name": "euler"
},
"_meta": {
"title": "KSamplerSelect"
}
},
"17": {
"class_type": "BasicScheduler",
"inputs": {
"denoise": 1,
"model": [
"30",
0
],
"scheduler": "simple",
"steps": 20
},
"_meta": {
"title": "BasicScheduler"
}
},
"22": {
"class_type": "BasicGuider",
"inputs": {
"conditioning": [
"45",
0
],
"model": [
"30",
0
]
},
"_meta": {
"title": "Basic Guider"
}
},
"25": {
"class_type": "RandomNoise",
"inputs": {
"noise_seed": 1006963725794704
},
"_meta": {
"title": "RandomNoise"
}
},
"26": {
"class_type": "FluxGuidance",
"inputs": {
"conditioning": [
"6",
0
],
"guidance": 3.5
},
"_meta": {
"title": "FluxGuidance"
}
},
"27": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 768,
"width": 1344
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"30": {
"class_type": "ModelSamplingFlux",
"inputs": {
"base_shift": 0.5,
"height": 768,
"max_shift": 1.15,
"model": [
"12",
0
],
"width": 1344
},
"_meta": {
"title": "ModelSamplingFlux"
}
},
"38": {
"class_type": "CLIPVisionLoader",
"inputs": {
"clip_name": "sigclip_vision_patch14_384.safetensors"
},
"_meta": {
"title": "Load CLIP Vision"
}
},
"39": {
"class_type": "CLIPVisionEncode",
"inputs": {
"clip_vision": [
"38",
0
],
"crop": "center",
"image": [
"40",
0
]
},
"_meta": {
"title": "CLIP Vision Encode"
}
},
"40": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_1_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"41": {
"class_type": "StyleModelApply",
"inputs": {
"clip_vision_output": [
"39",
0
],
"conditioning": [
"26",
0
],
"strength": 1,
"strength_type": "multiply",
"style_model": [
"42",
0
]
},
"_meta": {
"title": "Apply Style Model"
}
},
"42": {
"class_type": "StyleModelLoader",
"inputs": {
"style_model_name": "flux1-redux-dev.safetensors"
},
"_meta": {
"title": "Load Style Model"
}
},
"45": {
"class_type": "StyleModelApply",
"inputs": {
"clip_vision_output": [
"46",
0
],
"conditioning": [
"41",
0
],
"strength": 1,
"strength_type": "multiply",
"style_model": [
"42",
0
]
},
"_meta": {
"title": "Apply Style Model"
}
},
"46": {
"class_type": "CLIPVisionEncode",
"inputs": {
"clip_vision": [
"38",
0
],
"crop": "center",
"image": [
"47",
0
]
},
"_meta": {
"title": "CLIP Vision Encode"
}
},
"47": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_2_FILENAME"
},
"_meta": {
"title": "Load Image"
}
}
})
workflow.set_input("40", "image", client.assets.from_url("https://comfy.org/catalog-media/0b4e1c7c-ccd1-43cc-8dfa-193ebe6422a9/ddcf0f0a-9ebd-4117-a70c-2b1c2484c05a"))
workflow.set_input("47", "image", client.assets.from_url("https://comfy.org/catalog-media/5c62caa3-0de5-434e-87ac-ac1716e85da6/034c0874-fe1b-4a3b-b696-0226bbb71381"))
# 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)