# 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({
"12": {
"class_type": "HappyHorseImageToVideoApi",
"inputs": {
"first_frame": [
"14",
0
],
"model": "happyhorse-1.1-i2v",
"model.duration": 5,
"model.prompt": "The woodcarver leans into the burled walnut bowl and pushes the iron gouge through a long, steady stroke, a translucent ribbon of shaving curling off the edge and dropping onto the dark bench. He pauses, blows the dust from the cut, turns the bowl a quarter turn with both hands, runs his thumb along the rim to feel the curve, then sets the gouge for the next cut. Golden winter sunlight streams through the frosted windows and the hanging wood dust drifts and glitters in the beams. The camera starts close on his hands and the bowl and slowly cranes up and back to reveal his focused face and the log walls hung with tools, a calm, smooth documentary move with soft natural sound of the blade and the creak of the bench.",
"model.resolution": "720P",
"seed": 0,
"watermark": False
},
"_meta": {
"title": "HappyHorse Image to Video"
}
},
"13": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/HappyHorse1.1",
"format": "auto",
"format.codec": "auto",
"video": [
"12",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"14": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
}
})
workflow.set_input("14", "image", client.assets.from_url("https://comfy.org/catalog-media/ef857202-9e0c-4fa1-8068-22c0b7e2b310/94294296-7852-4bb9-8942-8b6083603a67"))
# 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("13"):
output.to_file(output.name)