# 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({
"14": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/kling_o3_video_edit",
"format": "auto",
"format.codec": "auto",
"video": [
"23",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"17": {
"class_type": "LoadImage",
"inputs": {
"image": "giant_trees_sky_pyramid.png"
},
"_meta": {
"title": "Load Image"
}
},
"23": {
"class_type": "KlingOmniProEditVideoNode",
"inputs": {
"keep_original_sound": True,
"model_name": "kling-v3-omni",
"prompt": "Keep the character (the man) and the ornate bird character (covered in jewelry and exquisite details) in the reference video completely unchanged—including their actions, postures, and all decorative details. Replace the original desert background in the video with the background environment from the reference image (the scene with giant trees, castles, and a blue sky). Adjust the lighting and color tone of the man and the ornate bird to match the new background for a natural, cohesive visual effect. ",
"reference_images": [
"17",
0
],
"resolution": "720p",
"seed": 0,
"video": [
"25",
0
]
},
"_meta": {
"title": "Kling 3.0 Omni Edit Video"
}
},
"25": {
"class_type": "LoadVideo",
"inputs": {
"file": "kling_o3_video_input.mp4"
},
"_meta": {
"title": "Load Video"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)