# 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({
"343": {
"class_type": "ByteDance2TextToVideoNode",
"inputs": {
"model": "Seedance 2.0",
"model.duration": 10,
"model.generate_audio": True,
"model.prompt": "A single sleek sports car (colored red) being chased by a heavy SUV (colored green), drifting aggressively around a tight corner and kicking up particle debris. Low-angle handheld tracking shot, moving backward at high speed to keep both vehicles centered in the frame. A busy city intersection (colored blue). Untextured grey 3D playblast render style, Maya viewport look, flat Lambert shading, ambient occlusion only. No color, no textures, no realistic lighting, maintain solid geometry, no vehicle morphing, no camera cuts.",
"model.ratio": "16:9",
"model.resolution": "720p",
"seed": 675586000,
"watermark": False
},
"_meta": {
"title": "ByteDance Seedance 2.5 Text to Video"
}
},
"344": {
"class_type": "SaveVideo",
"inputs": {
"codec": "auto",
"filename_prefix": "video/Seedance2.0_t2v",
"format": "auto",
"format.codec": "auto",
"video": [
"343",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"347": {
"class_type": "ImageFromBatch+",
"inputs": {
"image": [
"428",
0
],
"length": 1,
"start": [
"430",
0
]
},
"_meta": {
"title": "🔧 Image From Batch"
}
},
"348": {
"class_type": "GeminiNanoBanana2",
"inputs": {
"aspect_ratio": "auto",
"images": [
"431",
0
],
"model": "Nano Banana 2 (Gemini 3.1 Flash Image)",
"prompt": "make a 2x2 grid of this image showing different angles of the object on a white background. no text.",
"resolution": "1K",
"response_modalities": "IMAGE",
"seed": 43,
"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"
}
},
"352": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"347",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"356": {
"class_type": "ByteDance2ReferenceNode",
"inputs": {
"model": "Seedance 2.0",
"model.auto_downscale": True,
"model.auto_upscale": False,
"model.duration": [
"447",
0
],
"model.generate_audio": True,
"model.prompt": "Use the motion from video_1 with the vehicles from image_1 and image_2 chasing each other in the city streets based on image_4. The other cars look like image_3. Tire smoke and road debris being kicked up behind the cars. Headlight coming from the cars cause anamorphic lens flares. As the red car spins out, sparks fly out of it's rear tires. Cinematic. 4k.",
"model.ratio": "16:9",
"model.reference_images.image_1": [
"453",
0
],
"model.reference_images.image_2": [
"380",
0
],
"model.reference_images.image_3": [
"404",
0
],
"model.reference_images.image_4": [
"384",
0
],
"model.reference_videos.video_1": [
"451",
0
],
"model.resolution": "720p",
"seed": 1077699877,
"watermark": False
},
"_meta": {
"title": "ByteDance Seedance 2.5 Reference to Video (Legacy)"
}
},
"359": {
"class_type": "SaveVideo",
"inputs": {
"codec": "auto",
"filename_prefix": "video/Seedance2.0_r2v",
"format": "auto",
"format.codec": "auto",
"video": [
"356",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"361": {
"class_type": "GeminiNode",
"inputs": {
"model": "gemini-3-1-pro",
"prompt": "I have a shot that I want to match the motion of, this is video_1. I want it to have the vehilces from image_1, 2, and 3 and the enviroment should look like image_4.",
"seed": 42,
"system_prompt": "# 🧠 Seedance 2.0 Prompt Assistant\n\n## System Instructions\n\nYou are an expert AI video director and prompt engineer specializing in Seedance 2.0. Your role is to help the user design high-quality prompts for multimodal video generation, including text-to-video, image-to-video, reference-to-video, video-to-video, and audio-to-video workflows.\n\nYou must think like a film director, not a casual prompt writer.\n\n---\n\n## 🎯 Core Objective\n\nAlways generate prompts that:\n\n* Are structured using cinematic language\n* Describe filmable shots, not abstract ideas\n* Maintain subject consistency and motion clarity\n* Use constraints to reduce model drift\n* Are optimized for Seedance’s multimodal behavior\n\n---\n\n## 🧱 Universal Prompt Structure\n\nAlways follow this structure when generating prompts:\n\nSubject → Action → Camera → Scene → Style → Constraints → Timing\n\nDefinitions:\n\n* Subject: who or what is in the scene\n* Action: what is happening (single continuous action)\n* Camera: shot type, framing, and movement\n* Scene: environment and spatial context\n* Style: a single clear visual style reference\n* Constraints: rules to prevent artifacts or drift\n* Timing: optional shot sequencing or time-based structure\n\nDo not change this order.\n\n---\n\n## 🎬 Mode-Specific Behavior\n\n### 1. Text-to-Video (T2V)\n\n* Generate everything from scratch\n* Use a single subject and a single action\n* Avoid multiple ideas or branching events\n* Treat the prompt as one continuous shot unless explicitly told otherwise\n\n---\n\n### 2. Image-to-Video (I2V)\n\n* Assume the image defines identity\n* Do not redefine appearance in detail\n* Focus on motion, camera, and environment\n* Include constraints to preserve facial and structural consistency\n\nExample constraints:\n\n* maintain exact facial structure\n* preserve clothing and proportions\n\n---\n\n### 3. Reference-to-Video (Multi-input)\n\n* Assign clear roles to each input\n\nUse this pattern:\n\n* Image = identity\n* Video = motion reference\n* Audio = timing and emotion\n\nExplicitly describe how each input is used:\n\n* perform motion from reference video\n* maintain identity from reference image\n\n---\n\n### 4. Video-to-Video (V2V)\n\n* Preserve motion and timing from the source video\n* Only modify:\n\n * subject\n * environment\n * style\n* Avoid redefining motion unless necessary\n\n---\n\n### 5. Audio-to-Video (A2V)\n\n* Use audio to drive:\n\n * pacing\n * rhythm\n * emotional tone\n* Sync actions and camera movement to audio cues\n\n---\n\n## 🎥 Shot Design Rules\n\n* Default to a single shot unless multi-shot is requested\n* If multi-shot is used, structure clearly:\n\nShot 1:\nShot 2:\nShot 3:\n\nEach shot must follow the full prompt structure.\n\n---\n\n## 🎯 Constraints (Critical Requirement)\n\nAlways include constraints when generating prompts.\n\nTypes of constraints:\n\n* identity: no face distortion, consistent character\n* motion: no jitter, no morphing\n* camera: no cuts unless specified\n* environment: consistent lighting and geometry\n\nConstraints must be short, direct, and explicit.\n\n---\n\n## ⚖️ Prompt Quality Rules\n\n* Keep prompts between 30 and 120 words unless user asks otherwise\n* Use clear, literal language\n* Avoid vague descriptors like:\n\n * cool\n * cinematic (unless supported with specifics)\n * dynamic\n\nReplace vague language with:\n\n* specific camera moves\n* lighting descriptions\n* physical actions\n\n---\n\n## 🎨 Style Rules\n\n* Use only ONE strong style anchor\n* Prefer:\n\n * film references\n * lighting styles\n * real-world cinematography\n\nAvoid stacking multiple styles.\n\n---\n\n## 🎥 Camera Rules\n\nAlways define camera behavior when possible:\n\n* shot type: wide, medium, close-up\n* movement: dolly, pan, tilt, handheld\n* perspective: eye-level, low angle, overhead\n\nCamera language is more important than visual adjectives.\n\n---\n\n## 🧠 Iteration Strategy\n\nWhen refining prompts:\n\n* Change only one major variable at a time\n* Preserve working elements\n* Improve clarity, not complexity\n\n---\n\n## 🚫 What NOT to Do\n\nDo not:\n\n* write long narrative paragraphs\n* include multiple competing subjects\n* mix conflicting styles\n* omit camera direction\n* rely on abstract or emotional-only descriptions\n\n---\n\n## ✅ Output Format\n\nWhen the user asks for a prompt, return:\n\n1. Final Prompt (clean, ready to paste)\n2. Optional: Short explanation (if helpful)\n\nDo not over-explain unless asked.\n\n---\n\n## 🔥 Guiding Principle\n\nEvery prompt should describe something that could realistically be filmed on a set.\n\nIf it would not make sense to a cinematographer, rewrite it."
},
"_meta": {
"title": "Google Gemini"
}
},
"364": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"361",
0
]
},
"_meta": {
"title": "Preview as Text"
}
},
"380": {
"class_type": "LoadImage",
"inputs": {
"image": "bc1a1a3b41888b23907817f550a86cd1d4d332574a66307ef5e7e4407f1d6684.png"
},
"_meta": {
"title": "Load Image"
}
},
"384": {
"class_type": "LoadImage",
"inputs": {
"image": "efaf62dab3fc7e992bb6b628df69b781112830794beb98facb695ca810922772.png"
},
"_meta": {
"title": "Load Image"
}
},
"404": {
"class_type": "LoadImage",
"inputs": {
"image": "c62d4ddf874ebc4e076d63f1f3de34b0355052470bd3acd2dced26262449f3b2.png"
},
"_meta": {
"title": "Load Image"
}
},
"428": {
"class_type": "VHS_LoadVideo",
"inputs": {
"custom_height": 0,
"custom_width": 0,
"force_rate": 0,
"format": "AnimateDiff",
"frame_load_cap": 0,
"select_every_nth": 1,
"skip_first_frames": 0,
"video": "69e04c97120a65e3f3739e9b68cdfa58e06addc39cfe1417ac56b4798828e2fe.mp4"
},
"_meta": {
"title": "Load Video (Upload) 🎥🅥🅗🅢"
}
},
"430": {
"class_type": "Int",
"inputs": {
"value": 1
},
"_meta": {
"title": "CHOOSE FRAME"
}
},
"431": {
"class_type": "GeminiNanoBanana2",
"inputs": {
"aspect_ratio": "auto",
"model": "Nano Banana 2 (Gemini 3.1 Flash Image)",
"prompt": "A stylized synthwave race car. Red.",
"resolution": "1K",
"response_modalities": "IMAGE",
"seed": 43,
"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"
}
},
"432": {
"class_type": "GeminiNanoBanana2",
"inputs": {
"aspect_ratio": "auto",
"images": [
"436",
0
],
"model": "Nano Banana 2 (Gemini 3.1 Flash Image)",
"prompt": "Change this 3D render into a photorealistic, high quality, still frame of a sythnwave style environment.",
"resolution": "1K",
"response_modalities": "IMAGE",
"seed": 43,
"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"
}
},
"433": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"432",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"436": {
"class_type": "ImageBatchMulti",
"inputs": {
"image_1": [
"347",
0
],
"inputcount": 2
},
"_meta": {
"title": "Image Batch Multi"
}
},
"443": {
"class_type": "VHS_VideoInfo",
"inputs": {
"video_info": [
"428",
3
]
},
"_meta": {
"title": "Video Info 🎥🅥🅗🅢"
}
},
"447": {
"class_type": "CM_FloatToInt",
"inputs": {
"a": [
"443",
7
]
},
"_meta": {
"title": "FloatToInt"
}
},
"451": {
"class_type": "LoadVideo",
"inputs": {
"file": "video/69e04c97120a65e3f3739e9b68cdfa58e06addc39cfe1417ac56b4798828e2fe.mp4 [output]"
},
"_meta": {
"title": "Load Video"
}
},
"452": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"348",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"453": {
"class_type": "LoadImage",
"inputs": {
"image": "56598a0bbd51a7ff5dc6f7557906032006c8e4b7c5d0c6e14cf8e019dc018761.png [output]"
},
"_meta": {
"title": "Load Image"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)