# 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": "16:9",
"model.resolution": "1K",
"model.thinking_level": "MINIMAL",
"prompt": "A surreal studio still life unfolds across an expansive plane of fractured charcoal basalt. On the left, an antique tarnished brass pocket watch hovers weightlessly in mid-air, its cracked glass crystal exposing delicate, frozen clockwork gears and oxidized copper cogs. Across the vast expanse on the right, resting directly upon the coarse, porous volcanic stone, sits a dark caramelized canelé with a glossy beeswax crust, precisely bisected to reveal a moist, aerated vanilla-bean custard interior with glistening amber syrup droplets. In the background, a towering slab of brutalist, damp-stained poured concrete anchors the cold, austere environment. Piercing, low-angled sidelighting cuts sharply from the side, carving long, hard-edged shadows across the textured terrain and highlighting micro-scratches in the patinated metal. A brooding, somber palette of gunmetal slate, oxidized verdigris, and burnt umber establishes an unsettling, timeless stillness.",
"response_modalities": "IMAGE",
"seed": 129222452393446,
"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)"
}
}
})
# 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)