# 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": "RunwayAleph2VideoToVideoNode",
"inputs": {
"prompt": "Change the scene to a surfing scene and replace the characters with surfers",
"public_figure_threshold": "low",
"seed": 2374599215,
"video": [
"4",
0
]
},
"_meta": {
"title": "Runway Aleph2 Video to Video"
}
},
"2": {
"class_type": "RunwayAleph2PromptImageNode",
"inputs": {
"image": [
"3",
0
],
"position": "Absolute time (seconds)",
"position.seconds": 0
},
"_meta": {
"title": "Runway Aleph2 Prompt Image"
}
},
"3": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"4": {
"class_type": "LoadVideo",
"inputs": {
"file": "UPLOADED_video_FILENAME"
},
"_meta": {
"title": "Load Video"
}
},
"5": {
"class_type": "RunwayAleph2KeyframeNode",
"inputs": {
"image": [
"6",
0
],
"timing": "Absolute time (seconds)",
"timing.seconds": 0
},
"_meta": {
"title": "Runway Aleph2 Keyframe"
}
},
"6": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_keyframe_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"7": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/Runway_Aleph2",
"format": "auto",
"format.codec": "auto",
"video": [
"1",
0
]
},
"_meta": {
"title": "Save Video"
}
}
})
workflow.set_input("3", "image", client.assets.from_url("https://comfy.org/catalog-media/10c64ace-8530-4ccd-b1a9-95f50601c1ed/3fbe9b0b-4e07-4c60-b63a-919270e09a07"))
workflow.set_input("6", "image", client.assets.from_url("https://comfy.org/catalog-media/10c64ace-8530-4ccd-b1a9-95f50601c1ed/3fbe9b0b-4e07-4c60-b63a-919270e09a07"))
workflow.set_input("4", "file", client.assets.from_url("https://comfy.org/catalog-media/88b990ea-736c-4a68-9eb3-61084e2f0988/590bb695-f840-4bcb-82b9-c56ec385f44c"))
# 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("7"):
output.to_file(output.name)