# 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({
"33": {
"class_type": "WanReferenceVideoApi",
"inputs": {
"duration": 5,
"model": "wan2.6-r2v",
"negative_prompt": "",
"prompt": "Shot 1: Extreme close-up of Character 1’s determined face, hands tightly gripping a spear, rain cascading down polished armor. Character 1 speaks in fluent English with a gravelly voice: \"I will not yield!\" Heavy, labored breathing; raindrops striking metal with sharp, clinking sounds. Hyper-detailed, gritty texture.\n\nShot 2: Close-up of Character 2’s piercing, intense gaze, streaks of blood smudged across the face, weapon held in a battle-ready stance. Character 2 responds in clear English with a cold tone: \"Then this ends now.\" Thunder rumbles in the background, raindrops splashing violently against the ground. High contrast, dramatic lighting.\n\nShot 3: Epic wide shot: Two characters stand 20 meters apart, weapons raised, thick smoke swirling between them under roiling storm clouds. Eyes locked in a death stare, tension palpable. Wind howls fiercely, distant battle cries echo. All environmental sounds and dialogue must be in English. Cinematic, epic confrontation scene, film-grade composition.",
"reference_videos.character1": [
"34",
0
],
"reference_videos.character2": [
"35",
0
],
"seed": 1354927741,
"shot_type": "multi",
"size": "720p: 16:9 (1280x720)",
"watermark": False
},
"_meta": {
"title": "Wan Reference to Video"
}
},
"34": {
"class_type": "LoadVideo",
"inputs": {
"file": "armored_warrior.mp4"
},
"_meta": {
"title": "Load Video"
}
},
"35": {
"class_type": "LoadVideo",
"inputs": {
"file": "spear_warrior.mp4"
},
"_meta": {
"title": "Load Video"
}
},
"37": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/wan2_6_r2v",
"format": "auto",
"format.codec": "auto",
"video": [
"33",
0
]
},
"_meta": {
"title": "Save Video"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)