# 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": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"12": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_2_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"30": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"35",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"35": {
"class_type": "GeminiImage2Node",
"inputs": {
"aspect_ratio": "16:9",
"images": [
"36",
0
],
"model": "gemini-3-pro-image-preview",
"prompt": "Dress the woman from the first image in the suit from the second image. She now wears the oatmeal-and-charcoal check two-piece suit with its peak lapels, horn buttons and sharply creased straight trousers, plus the walnut-brown brogue oxfords, all fitted naturally to her body with realistic folds at the elbows and knees. Keep her face, hair, skin tone and build exactly as they are. Change her pose to a relaxed, confident fashion stance: weight on one leg, one hand slipped into a trouser pocket, the other lightly touching the jacket lapel, head turned slightly toward the camera with a faint smile. Place her in a bright, minimal studio with a warm ivory backdrop and a soft shadow on the floor, lit like a menswear campaign photograph, full body visible from head to shoes.",
"resolution": "2K",
"response_modalities": "IMAGE",
"seed": 39494503692700,
"system_prompt": "You are an expert image-generation engine. You must ALWAYS produce an image.\nInterpret all user input—regardless of format, intent, or abstraction—as literal visual directives for image composition.\nIf a prompt is conversational or lacks specific visual details, you must creatively invent a concrete visual scenario that depicts the concept.\nPrioritize generating the visual representation above any text, formatting, or conversational requests."
},
"_meta": {
"title": "Nano Banana Pro (Google Gemini Image)"
}
},
"36": {
"class_type": "BatchImagesNode",
"inputs": {
"images.image0": [
"11",
0
],
"images.image1": [
"12",
0
]
},
"_meta": {
"title": "Batch Images"
}
}
})
workflow.set_input("11", "image", client.assets.from_url("https://comfy.org/catalog-media/2c3a1c82-2b03-41d6-8eaf-1b498e5e85d6/d5e9e3ae-d491-4a2b-928b-e9a0a78f7eeb"))
workflow.set_input("12", "image", client.assets.from_url("https://comfy.org/catalog-media/84378120-4c58-4aca-a0d0-9ff9eb41c226/cfc59f7b-0d5c-476c-ada5-d151755f7c7f"))
# 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("30"):
output.to_file(output.name)