# 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({
"1": {
"class_type": "KlingMotionControl",
"inputs": {
"character_orientation": "video",
"keep_original_sound": True,
"mode": "pro",
"model": "kling-v3",
"prompt": "The figure in the slate-grey canvas suit dances on the cracked pale lakebed at twilight, copying every step, spin and arm movement of the dancer: arms sweeping wide, a quick turn on one foot, a low lunge and a rise back up. The suit folds and creases with each move and fine chalky dust puffs up from the dry earth under the boots on every step. The cool silver overcast light stays soft and even, the flat horizon stays level behind the figure and faint haze hangs in the distance. The camera holds steady at full-body distance so the whole figure stays in frame from head to feet throughout. Muted, quiet atmosphere, 1970s film grain.",
"reference_image": [
"2",
0
],
"reference_video": [
"3",
0
]
},
"_meta": {
"title": "Kling Motion Control"
}
},
"2": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"3": {
"class_type": "LoadVideo",
"inputs": {
"file": "UPLOADED_video_FILENAME"
},
"_meta": {
"title": "Load Video"
}
},
"4": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/kling_motion_control3.0",
"format": "auto",
"format.codec": "auto",
"video": [
"1",
0
]
},
"_meta": {
"title": "Save Video"
}
}
})
workflow.set_input("2", "image", client.assets.from_url("https://comfy.org/catalog-media/c0bd820f-1316-40df-8c28-4b0690950a01/221832a6-68de-406e-b545-14ab6df9fa4e"))
workflow.set_input("3", "file", client.assets.from_url("https://comfy.org/catalog-media/cafe6c47-9c6b-4a21-9a28-e8efab77d38c/3f3fa51c-4e55-44da-9fef-7e245c5bc3aa"))
# 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("4"):
output.to_file(output.name)