# 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({
"26": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "Nano Banana",
"images": [
"316",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"29": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"225": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/ComfyUI-vid_1",
"format": "auto",
"format.codec": "auto",
"video": [
"244",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"227": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/ComfyUI-vid_2",
"format": "auto",
"format.codec": "auto",
"video": [
"232",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"232": {
"class_type": "ByteDanceFirstLastFrameNode",
"inputs": {
"aspect_ratio": "adaptive",
"camera_fixed": False,
"duration": 4,
"first_frame": [
"316",
0
],
"generate_audio": True,
"last_frame": [
"317",
0
],
"model": "seedance-1-5-pro-251215",
"prompt": "All expanded components slide back into place in a precise, mechanical motion.\n\nNo dialogue, narration, or voiceover — only visual movement.",
"resolution": "720p",
"seed": 642612484,
"watermark": False
},
"_meta": {
"title": "ByteDance First-Last-Frame to Video"
}
},
"241": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "Nano Banana",
"images": [
"317",
0
]
},
"_meta": {
"title": "Save Image"
}
},
"244": {
"class_type": "ByteDanceFirstLastFrameNode",
"inputs": {
"aspect_ratio": "adaptive",
"camera_fixed": False,
"duration": 4,
"first_frame": [
"317",
0
],
"generate_audio": True,
"last_frame": [
"316",
0
],
"model": "seedance-1-5-pro-251215",
"prompt": "Slowly, its real physical components begin separating along natural assembly seams, transitioning into a clean, fully exploded view. Exterior casing, covers, buttons, ports, and internal structural parts separate in correct order and alignment, maintaining accurate scale and physical logic.\n\n No dialogue, no narration, no voiceover — only visual motion.",
"resolution": "720p",
"seed": 1561859130,
"watermark": False
},
"_meta": {
"title": "ByteDance First-Last-Frame to Video"
}
},
"259": {
"class_type": "BatchImagesNode",
"inputs": {
"images.image0": [
"392",
0
],
"images.image1": [
"393",
0
]
},
"_meta": {
"title": "Batch Images"
}
},
"316": {
"class_type": "GeminiNanoBanana2",
"inputs": {
"aspect_ratio": "auto",
"images": [
"317",
0
],
"model": "Nano Banana 2 (Gemini 3.1 Flash Image)",
"prompt": "a car",
"resolution": "2K",
"response_modalities": "IMAGE",
"seed": 343513052101185,
"system_prompt": "Analyze the reference image and recreate the exact same scene while transforming the main subject into a photorealistic exploded view.\n\n\nOnly the target object may change.\n\n\nOBJECT SEPARATION RULES\n\nThe object must be separated into its true physical components following realistic assembly structure.\n\nInternal components must be revealed and spaced apart along their correct assembly directions.\n\nAll parts must maintain accurate:\n\n- scale\n- thickness\n- orientation\n- alignment\n- relative position\n- physical hierarchy\n\nDo not invent components that would not physically exist.\n\nDo not duplicate identical components unless they exist multiple times in the real object.\n\n\nEXTERIOR COMPONENT PRESERVATION (CRITICAL)\n\n\nAll exterior parts must remain present and visible in the exploded view.\n\nThis includes:\n\n- front casing\n- back casing\n- side panels\n- outer shell\n- trim pieces\n- buttons\n- dials\n- knobs\n- ports\n- screens\n- external controls\n\nExterior casing must separate outward as real physical parts.\n\nThe shell must NOT disappear, dissolve, turn transparent, or be removed.\n\nThe result must NOT become an interior-only explosion.\n\n============================================================\nBACKGROUND AND CAMERA LOCK\n============================================================\n\nThe background must remain pixel-perfect identical to the original image.\n\nCamera angle, framing, and perspective must remain completely unchanged.\n\nDo NOT:\n\n- zoom out\n- zoom in\n- tilt\n- reframe\n- expand the canvas\n- change focal length\n\nObject scale within the frame must remain consistent with the original image.\n\n\nDo NOT include:\n\n- labels\n- callout graphics\n- diagrams\n- arrows\n- transparency\n- ghosted parts\n- stylization",
"thinking_level": "HIGH"
},
"_meta": {
"title": "Nano Banana 2"
}
},
"317": {
"class_type": "GeminiNanoBanana2",
"inputs": {
"aspect_ratio": "auto",
"images": [
"29",
0
],
"model": "Nano Banana 2 (Gemini 3.1 Flash Image)",
"prompt": "Analyze the input image and recreate it exactly as a single, static, photorealistic image.\n\nThis is an image recreation / image edit only.",
"resolution": "2K",
"response_modalities": "IMAGE",
"seed": 0,
"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.",
"thinking_level": "MINIMAL"
},
"_meta": {
"title": "Nano Banana 2"
}
},
"380": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"392",
1
],
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": [
"392",
2
],
"images": [
"259",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"381": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/ComfyUI",
"format": "auto",
"format.codec": "auto",
"video": [
"380",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"392": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"244",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"393": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"232",
0
]
},
"_meta": {
"title": "Get Video Components"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("29", "image", client.assets.from_url("https://example.com/replace-with-a-url/image"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)