# 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({
"83": {
"class_type": "FluxKontextProImageNode",
"inputs": {
"aspect_ratio": "16:9",
"guidance": 3,
"input_image": [
"98",
0
],
"prompt": "The man with the mustache from the first image sits relaxed on the cognac leather sofa from the third image, leaning back with one arm along the backrest and his legs crossed, still wearing his mustard corduroy jacket and burnt-orange turtleneck. The long-haired silver Maine Coon cat from the second image is curled up asleep on the cushion beside him, its fluffy tail draped over his knee. Keep the twilight living room exactly as it is: the arc floor lamp casting a warm amber pool of light, the tall steel-framed windows with rain on the glass, the concrete walls and the charcoal rug. Cinematic interior photograph, natural proportions, soft warm and cool contrast.",
"prompt_upsampling": False,
"seed": 323708991831609,
"steps": 50
},
"_meta": {
"title": "Flux.1 Kontext [pro] Image"
}
},
"84": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_1_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"85": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"83",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"90": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"98",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"91": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_3_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"96": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_2_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"97": {
"class_type": "ImageStitch",
"inputs": {
"direction": "up",
"image1": [
"84",
0
],
"image2": [
"96",
0
],
"match_image_size": True,
"spacing_color": "white",
"spacing_width": 8
},
"_meta": {
"title": "Stitch Images"
}
},
"98": {
"class_type": "ImageStitch",
"inputs": {
"direction": "right",
"image1": [
"97",
0
],
"image2": [
"91",
0
],
"match_image_size": True,
"spacing_color": "white",
"spacing_width": 20
},
"_meta": {
"title": "Stitch Images"
}
}
})
workflow.set_input("84", "image", client.assets.from_url("https://comfy.org/catalog-media/18bce541-baf6-4132-82aa-3cfa614f81d2/1e81b9f7-e2b3-44d8-903e-1a153aee1e9a"))
workflow.set_input("96", "image", client.assets.from_url("https://comfy.org/catalog-media/129dc51d-f36c-4561-9e53-535bb3f6552b/e708da58-5617-40ea-a109-a849389dfc80"))
workflow.set_input("91", "image", client.assets.from_url("https://comfy.org/catalog-media/76a44330-564a-4b90-8a92-20748a616b1e/5d5cfa81-0ba4-4f4a-ba0a-4e8894b2464d"))
# 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("85"):
output.to_file(output.name)