# 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({
"3": {
"class_type": "GeminiNanoBanana2V2",
"inputs": {
"model": "Nano Banana 2 Lite",
"model.aspect_ratio": "auto",
"model.images.image_1": [
"8",
0
],
"model.resolution": "1K",
"model.thinking_level": "MINIMAL",
"prompt": "Keep the roadster's exact shape, proportions, chrome bumpers, wire wheels and position in the frame, and keep the mountain overlook and camera angle. Change the moment from a misty, rainy twilight to a bright, crisp autumn afternoon: clear blue sky with a few high clouds, the pine ridges now mixed with golden larches, the road dry and sunlit with long soft shadows. Repaint the car in a glossy cream with a single thin racing-green stripe along its side, the convertible top folded down, a tartan blanket and a wicker picnic basket on the passenger seat. Warm sunlight glints on the chrome and the paint. Photorealistic, sharp detail on the car, no badges, logos, lettering or number plates anywhere.",
"response_modalities": "IMAGE",
"seed": 557242843672064,
"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.",
"temperature": 1,
"top_p": 0.95
},
"_meta": {
"title": "Nano Banana 2"
}
},
"4": {
"class_type": "SaveImageAdvanced",
"inputs": {
"filename_prefix": "Nano_banana_2_lite",
"format": "png",
"format.bit_depth": "8-bit",
"format.input_color_space": "sRGB",
"images": [
"3",
0
]
},
"_meta": {
"title": "Save Image (Advanced)"
}
},
"8": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"9": {
"class_type": "ImageCompare",
"inputs": {
"compare_view": None,
"image_a": [
"8",
0
],
"image_b": [
"4",
0
]
},
"_meta": {
"title": "Compare Images"
}
}
})
workflow.set_input("8", "image", client.assets.from_url("https://comfy.org/catalog-media/5d061cdd-dc86-418a-a446-423201f9f466/1139253c-dfc6-45e6-94e3-4633f97fbfce"))
# 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("4"):
output.to_file(output.name)