# 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": {
"filename_prefix": "video/Kling",
"format": "auto",
"format.codec": "h264",
"video": [
"8",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"8": {
"class_type": "KlingOmniProEditVideoNode",
"inputs": {
"keep_original_sound": True,
"model_name": "kling-video-o1",
"prompt": "Change the human skateboarder in [@Video] to the anthropomorphic dog (wearing a brown jacket and straw hat) from [@Image], and keep the dog’s movements consistent with the original skateboarder’s actions (pushing off, balancing on the skateboard) in the skatepark scene. Preserve the original video’s lighting and background details.",
"reference_images": [
"24",
0
],
"resolution": "1080p",
"seed": 0,
"video": [
"22",
0
]
},
"_meta": {
"title": "Kling 3.0 Omni Edit Video"
}
},
"21": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"23",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"22": {
"class_type": "CreateVideo",
"inputs": {
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": 24,
"images": [
"21",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"23": {
"class_type": "LoadVideo",
"inputs": {
"file": "UPLOADED_video_FILENAME"
},
"_meta": {
"title": "Load Video"
}
},
"24": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("24", "image", client.assets.from_url("https://example.com/replace-with-a-url/image"))
workflow.set_input("23", "file", client.assets.from_url("https://example.com/replace-with-a-url/video"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)