# 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": "ComfyUI",
"images": [
"112:8",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"47": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"112:109": {
"class_type": "ImageScaleToMaxDimension",
"inputs": {
"image": [
"47",
0
],
"largest_size": 512,
"upscale_method": "area"
},
"_meta": {
"title": "Scale Image to Max Dimension"
}
},
"112:110": {
"class_type": "EmptySD3LatentImage",
"inputs": {
"batch_size": 1,
"height": 768,
"width": 1344
},
"_meta": {
"title": "EmptySD3LatentImage"
}
},
"112:30": {
"class_type": "CheckpointLoaderSimple",
"inputs": {
"ckpt_name": "flux1-dev-fp8.safetensors"
},
"_meta": {
"title": "Load Checkpoint"
}
},
"112:31": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"112:110",
0
],
"model": [
"112:43",
0
],
"negative": [
"112:48",
0
],
"positive": [
"112:57:35",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 1058487910949722,
"steps": 20
},
"_meta": {
"title": "KSampler"
}
},
"112:39": {
"class_type": "ModelPatchLoader",
"inputs": {
"name": "uso-flux1-projector-v1.safetensors"
},
"_meta": {
"title": "Load Model Patch"
}
},
"112:40": {
"class_type": "CLIPVisionLoader",
"inputs": {
"clip_name": "sigclip_vision_patch14_384.safetensors"
},
"_meta": {
"title": "Load CLIP Vision"
}
},
"112:43": {
"class_type": "LoraLoaderModelOnly",
"inputs": {
"lora_name": "uso-flux1-dit-lora-v1.safetensors",
"model": [
"112:30",
0
],
"strength_model": 1
},
"_meta": {
"title": "Load LoRA"
}
},
"112:48": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"112:6",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"112:51": {
"class_type": "VAEEncode",
"inputs": {
"pixels": [
"112:109",
0
],
"vae": [
"112:30",
2
]
},
"_meta": {
"title": "VAE Encode"
}
},
"112:57:35": {
"class_type": "FluxGuidance",
"inputs": {
"conditioning": [
"112:57:41",
0
],
"guidance": 3.5
},
"_meta": {
"title": "FluxGuidance"
}
},
"112:57:41": {
"class_type": "FluxKontextMultiReferenceLatentMethod",
"inputs": {
"conditioning": [
"112:57:44",
0
],
"reference_latents_method": "uxo/uno"
},
"_meta": {
"title": "Edit Model Reference Method"
}
},
"112:57:44": {
"class_type": "ReferenceLatent",
"inputs": {
"conditioning": [
"112:6",
0
],
"latent": [
"112:51",
0
]
},
"_meta": {
"title": "Set Reference Latent"
}
},
"112:6": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"112:30",
1
],
"text": "The same man from the reference photo, with the same face, eyes, stubble and wavy dark hair, now standing at the stern of a small wooden fishing boat at first light. He wears a heavy cream cable-knit sweater and an oilskin apron, sleeves pushed up, coiling a wet rope over one forearm and looking straight towards the camera with a calm, tired expression. Behind him a grey-green sea rolls under low clouds, gulls hang above the wake, and a rocky headland with a white lighthouse sits on the horizon. Cold dawn light comes from the left, catching salt spray on his face and the wet planks of the deck. Live-action documentary photograph, 35mm lens, natural colour, crisp detail on the knit and the rope, shallow depth of field on the far coastline."
},
"_meta": {
"title": "CLIP Text Encode (Positive Prompt)"
}
},
"112:8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"112:31",
0
],
"vae": [
"112:30",
2
]
},
"_meta": {
"title": "VAE Decode"
}
}
})
workflow.set_input("47", "image", client.assets.from_url("https://comfy.org/catalog-media/c94b548e-618e-481c-8ed2-fdf58b7b3f68/48639183-6716-4e49-9464-3f0958da2c31"))
# 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)