# 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({
"9": {
"class_type": "RunwayFirstLastFrameNode",
"inputs": {
"duration": 5,
"end_frame": [
"11",
0
],
"prompt": "wide horizontal pan shot of a girl running across a reflective water surface, behind her vast starry sky with pastel-colored nebula waves swirling, stardust drifting and twinkling stars, cool-to-warm dreamy pastel gradient, soft backlighting by starlight, watercolor and oil painting blend texture, smooth frame-to-frame transitions maintaining continuous nebula motion",
"ratio": "1280:768",
"seed": 379330984,
"start_frame": [
"10",
0
]
},
"_meta": {
"title": "Runway First-Last-Frame to Video"
}
},
"10": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_2_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"11": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"12": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/ComfyUI",
"format": "auto",
"format.codec": "auto",
"video": [
"9",
0
]
},
"_meta": {
"title": "Save Video"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("11", "image", client.assets.from_url("https://example.com/replace-with-a-url/image"))
workflow.set_input("10", "image", client.assets.from_url("https://example.com/replace-with-a-url/image_2"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)