# 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({
"2": {
"class_type": "SaveVideo",
"inputs": {
"codec": "auto",
"filename_prefix": "video/Minimax_h3_max",
"format": "auto",
"format.codec": "auto",
"video": [
"4",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"4": {
"class_type": "MinimaxHailuo03ReferenceNode",
"inputs": {
"model": "MiniMax H3 Max",
"model.duration": 5,
"model.prompt": [
"12",
0
],
"model.prompt_expansion_mode": "balanced",
"model.ratio": "adaptive",
"model.reference_detail": "high",
"model.reference_images.image_1": [
"6",
0
],
"model.resolution": "768P",
"seed": 3353295271,
"watermark": False
},
"_meta": {
"title": "MiniMax H3 Reference to Video"
}
},
"6": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"7": {
"class_type": "MinimaxHailuo03ContextIRNode",
"inputs": {
"model": "MiniMax H3",
"model.duration": 5,
"model.prompt": [
"14",
0
],
"model.ratio": "adaptive",
"model.reference_images.image_1": [
"6",
0
]
},
"_meta": {
"title": "MiniMax H3 Context IR (Prompt Enhancer)"
}
},
"8": {
"class_type": "SaveText",
"inputs": {
"filename_prefix": "H3_prompt",
"format": "txt",
"text": [
"12",
0
]
},
"_meta": {
"title": "Save Text"
}
},
"10": {
"class_type": "MinimaxHailuo03RegenerateNode",
"inputs": {
"model": "MiniMax H3",
"model.prompt": [
"8",
0
],
"model.reference_images.image_1": [
"6",
0
],
"model.resolution": "2K",
"video": [
"2",
0
],
"watermark": False
},
"_meta": {
"title": "MiniMax H3 Regenerate to 2K"
}
},
"11": {
"class_type": "SaveVideo",
"inputs": {
"codec": "auto",
"filename_prefix": "video/Minimax_h3_max",
"format": "auto",
"format.codec": "auto",
"video": [
"13",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"12": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"14",
0
],
"on_true": [
"7",
0
],
"switch": [
"18",
0
]
},
"_meta": {
"title": "If/Else Switch"
}
},
"13": {
"class_type": "ComfySwitchNode",
"inputs": {
"on_false": [
"4",
0
],
"on_true": [
"10",
0
],
"switch": [
"19",
0
]
},
"_meta": {
"title": "If/Else Switch"
}
},
"14": {
"class_type": "PrimitiveStringMultiline",
"inputs": {
"value": "subject_definitions:\n<Subject 1> is the otherworldly samurai in <Picture 1>, featuring light blue skin with yellow markings, a tall blue curved hat, and a black face mask with gold studs. He wears a thick brown fur collar over a teal kimono-style top with orange and red patches, dark blue armor panels on his waist, and red and purple sashes. Two katana swords with dark scabbards and gold hilts are tucked into his waist, and he carries a massive backpack bound with thick brown ropes, loaded with blue and green bedrolls, a wooden container, and yellow gourds.\n<Subject 2> is the alien night environment and intricate, colorful 2D comic illustration style in <Picture 1>, characterized by a starry purple and blue sky, a massive dark circular celestial sphere, wispy cyan smoke, and stylized light blue leafy foliage in the foreground.\n<Picture 1> is the first frame of [Shot 1], showing <Subject 1> standing in profile within <Subject 2>.\n\nsummary:\n[keyframe completion + reference generation] The target video begins with <Picture 1> as the first frame, showing <Subject 1> standing in the alien night landscape of <Subject 2>. The tranquil scene is interrupted when a monster attacks, prompting <Subject 1> to draw his sword and perform a powerful, dynamic slash to fight the creature, bringing the still illustration into intense animated combat.\n\nretention_analysis:\n<Picture 1> ([Shot 1] first frame): fully_preserved - the target video starts exactly from this image, preserving the initial composition, the side-profile view of <Subject 1>, and the background elements of <Subject 2>.\n<Subject 1> (appears in [Shot 1]): fully_preserved - the samurai's light blue skin, studded mask, tall hat, fur collar, patched teal clothing, massive loaded backpack, and katana swords remain intact and clearly visible during his rapid combat movements.\n<Subject 2> (appears in [Shot 1]): fully_preserved - the deep purple and blue starry sky, the dark celestial sphere, the curling cyan smoke, the light blue foliage, and the intricate flat-shaded 2D illustration style are maintained throughout the action.\n\ndetailed_description:\nThe target video is in an intricate, colorful, flat-shaded 2D comic illustration style.\n\n[Shot 1] The shot begins with <Picture 1> as the first frame. In the center of the frame, <Subject 1> stands in profile, facing left within the alien night environment of <Subject 2>. The otherworldly samurai is fully realized, featuring light blue skin speckled with yellow markings, a tall, curved blue hat, and a black face mask dotted with gold studs covering his lower face. He wears a heavy, textured brown fur collar over a teal, kimono-style top adorned with bright orange and red patches. Dark blue armor panels hang at his waist, secured by red and purple sashes, where two katana swords with dark scabbards and gold hilts are tucked. On his back, he carries a massive, towering backpack bound tightly with thick brown ropes, loaded with green and blue bedrolls, a wooden bucket, and round yellow gourds. The background of <Subject 2> features a deep purple and blue night sky filled with four-pointed stars, dominated by the massive silhouette of a dark circular celestial sphere. Wispy, stylized cyan smoke curls upward behind him, while light blue, leafy plants fill the foreground.\n\nSuddenly, the tranquil atmosphere is broken as a menacing, shadowy monster with glowing red eyes and jagged claws bursts into the frame from the left edge, lunging toward the samurai. Reacting with lightning speed, <Subject 1> pivots his upper body, his purple-gloved right hand snapping down to grip the gold hilt of his primary katana. With a fluid, explosive motion, he draws the blade from its dark scabbard, the polished steel catching the starlight. The sudden movement causes his heavy, rope-bound backpack to shift heavily, the gourds and bedrolls swaying with realistic secondary motion, while his brown fur collar rustles wildly. The camera dynamically pushes in and arcs slightly to capture the action, heightening the intensity of the confrontation.\n\n<Subject 1> steps forward, planting his foot firmly among the light blue foliage, and unleashes a devastating, sweeping slash toward the lunging monster. The blade cuts through the air with a stylized, trailing arc of light blue energy, striking the beast's claws. The monster recoils from the heavy impact, its dark form twisting backward. The samurai follows through with his swing, his posture low and grounded, the intricate details of his patched teal clothing and studded dark armor fully visible in the dramatic combat stance. The curling cyan smoke of <Subject 2> swirls violently around them, disturbed by the shockwave of the sword strike, as the shot ends on this tense, action-packed battle tableau.\n\noverall_soundscape:\nA tense, atmospheric soundscape featuring the crisp, metallic ring of a sword being quickly drawn from its scabbard, followed by the heavy whoosh of a blade slicing through the air and a deep, resonant impact as the weapon connects with the monster's claws, all set against a backdrop of eerie, howling nocturnal wind.\n\nnon_diegetic_music:\nA fast-paced, dramatic orchestral track with driving taiko drums, sharp shamisen plucks, and tense strings, matching the sudden burst of combat action."
},
"_meta": {
"title": "Text (Prompt)"
}
},
"18": {
"class_type": "PrimitiveBoolean",
"inputs": {
"value": False
},
"_meta": {
"title": "Boolean (Prompt Enhance)"
}
},
"19": {
"class_type": "PrimitiveBoolean",
"inputs": {
"value": False
},
"_meta": {
"title": "Boolean (Upscale to 2K)"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("6", "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)