# 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": "SaveVideo",
"inputs": {
"codec": "auto",
"filename_prefix": "video/HeyGen_video_1.0_i2v",
"format": "auto",
"format.codec": "auto",
"video": [
"9",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"5": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"9": {
"class_type": "HeyGenImageToVideoNode",
"inputs": {
"model": "heygen-video-1",
"model.auto_duration": "disabled",
"model.duration": 5,
"model.image": [
"5",
0
],
"model.prompt": "The woman from the first frame raises her hand in one slow, steady move from her jaw until the ring is held right in front of the lens, the ring's face turned straight to the camera and filling the middle of the frame. For the first three seconds nothing else moves and she says nothing: the ring is the brightest, sharpest thing in the shot, closer to the lens than her face. Then she settles her eyes on the lens and speaks straight to camera in an easy, conversational selling tone, unhurried, about two words per second: \"One ring, every outfit. This is the only one I pack.\" Her arm stays steady while she talks. At the end of the line she tips her wrist a few degrees so the highlight travels across the ring, then blinks once and holds. Shot on an ARRI Alexa Mini LF, 85mm T1.8, locked off on a tripod at eye level, the same soft key light as the first frame, shallow depth of field, fine film grain, true-to-life muted colour, no teal-orange grade, natural skin texture with visible pores and fine lines, no retouching, no beauty filter, no glamour lighting. No readable text, logos, brand names, printed words or badges anywhere in frame, hands have exactly five fingers, nothing CG-looking, no plastic skin. Quiet studio room tone, a faint fabric rustle as she raises her arm, her voice close to the mic and dry. No music.",
"model.resolution": "768p",
"model.seed": 3006221932
},
"_meta": {
"title": "HeyGen Video 1.0 Image to Video"
}
}
})
workflow.set_input("5", "image", client.assets.from_url("https://comfy.org/catalog-media/d4cee80d-1f3a-4e69-8cde-333669e88300/a6f1d5a4-c958-4ccb-af6a-99219ec59f1a"))
# 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("3"):
output.to_file(output.name)