# 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({
"11": {
"class_type": "Flux2ProImageNode",
"inputs": {
"height": 1088,
"images": [
"22",
0
],
"prompt": "A photoshoot-style group portrait of exactly four people, one from each of the four reference images, all four fully visible from head to shoes: the person in the cobalt-blue velvet suit with flared trousers, the man in the moss-green brocade tunic and wide grey trousers, the older man in the blue double-breasted suit with a yellow scarf, and the woman in the sculpted cream jacket and layered skirt. Keep each face, hair, skin tone, build and outfit exactly as in their reference. Shot from high above on a tall platform, looking down at a steep angle, the four stand evenly spaced in a loose row on a pale concrete rooftop at golden hour and look up toward the lens. Long clean shadows stretch across the roof, a hazy city far below. Crisp editorial magazine look, no text or logos.",
"prompt_upsampling": True,
"seed": 96048955606126,
"width": 1920
},
"_meta": {
"title": "Flux.2 [pro] Image"
}
},
"12": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "Flux.2[pro]",
"images": [
"11",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"15": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_1_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"16": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_3_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"18": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_4_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"19": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_2_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"22": {
"class_type": "BatchImagesNode",
"inputs": {
"images.image0": [
"15",
0
],
"images.image1": [
"19",
0
],
"images.image2": [
"16",
0
],
"images.image3": [
"18",
0
]
},
"_meta": {
"title": "Batch Images"
}
}
})
workflow.set_input("15", "image", client.assets.from_url("https://comfy.org/catalog-media/1a3f777f-b1c4-40af-a67a-0fba141e99f2/6a589022-bb3e-4d88-a8bf-7a4fb0cd6dac"))
workflow.set_input("19", "image", client.assets.from_url("https://comfy.org/catalog-media/ed79d568-928a-4f40-8f29-5fe6adb98cef/d9993afb-7bfe-4afe-8242-a39c19decf09"))
workflow.set_input("16", "image", client.assets.from_url("https://comfy.org/catalog-media/888155e0-e8a3-4bfb-b32b-1279d85ef1cb/4e128683-0078-4c59-abc3-70964364f268"))
workflow.set_input("18", "image", client.assets.from_url("https://comfy.org/catalog-media/256dde63-7af3-412f-b438-b3f8ab287c06/70643f22-81e1-49f3-9d24-d3062cfd3e77"))
# 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("12"):
output.to_file(output.name)