# 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({
"245": {
"class_type": "KlingOmniProEditVideoNode",
"inputs": {
"keep_original_sound": True,
"model_name": "kling-v3-omni",
"prompt": "remove and outpaint the white borders of the video",
"resolution": "1080p",
"seed": 1652002455,
"video": [
"249",
0
]
},
"_meta": {
"title": "Kling 3.0 Omni Edit Video"
}
},
"247": {
"class_type": "LoadVideo",
"inputs": {
"file": "UPLOADED_video_FILENAME"
},
"_meta": {
"title": "Load Video"
}
},
"248": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"254",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"249": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"248",
1
],
"bit_depth": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": [
"248",
2
],
"images": [
"252:162",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"254": {
"class_type": "Video Slice",
"inputs": {
"duration": 0,
"start_time": 0,
"strict_duration": False,
"video": [
"247",
0
]
},
"_meta": {
"title": "Trim Video"
}
},
"270": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/9x16",
"format": "auto",
"format.codec": "auto",
"video": [
"245",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"302": {
"class_type": "JWImageResizeByShorterSide",
"inputs": {
"image": [
"248",
0
],
"interpolation_mode": "bicubic",
"size": 1080
},
"_meta": {
"title": "Image Resize by Shorter Side"
}
},
"252:152": {
"class_type": "Paste By Mask",
"inputs": {
"image_base": [
"252:230",
0
],
"image_to_paste": [
"252:229",
0
],
"mask": [
"252:229",
0
],
"resize_behavior": "keep_ratio_fit"
},
"_meta": {
"title": "Paste By Mask"
}
},
"252:153": {
"class_type": "ImageToMask",
"inputs": {
"channel": "red",
"image": [
"252:152",
0
]
},
"_meta": {
"title": "Convert Image to Mask"
}
},
"252:162": {
"class_type": "ImageRemoveAlpha+",
"inputs": {
"image": [
"252:165",
0
]
},
"_meta": {
"title": "🔧 Image Remove Alpha"
}
},
"252:163": {
"class_type": "Get Image Size",
"inputs": {
"image": [
"302",
0
]
},
"_meta": {
"title": "Get Image Size"
}
},
"252:165": {
"class_type": "Paste By Mask",
"inputs": {
"image_base": [
"252:231",
0
],
"image_to_paste": [
"302",
0
],
"mask": [
"252:152",
0
],
"resize_behavior": "keep_ratio_fit"
},
"_meta": {
"title": "Paste By Mask"
}
},
"252:229": {
"class_type": "LayerUtility: ColorImage V2",
"inputs": {
"color": "#ffffff",
"custom_height": [
"252:163",
1
],
"custom_width": [
"252:163",
0
],
"size": "custom"
},
"_meta": {
"title": "LayerUtility: ColorImage V2"
}
},
"252:230": {
"class_type": "LayerUtility: ColorImage V2",
"inputs": {
"color": "#000000",
"custom_height": [
"252:285",
1
],
"custom_width": [
"252:285",
0
],
"size": "custom"
},
"_meta": {
"title": "LayerUtility: ColorImage V2"
}
},
"252:231": {
"class_type": "LayerUtility: ColorImage V2",
"inputs": {
"color": "#ffffff",
"custom_height": [
"252:285",
1
],
"custom_width": [
"252:285",
0
],
"size": "custom"
},
"_meta": {
"title": "LayerUtility: ColorImage V2"
}
},
"252:285": {
"class_type": "ResolutionSelector",
"inputs": {
"aspect_ratio": "9:16 (Portrait Widescreen)",
"megapixels": 2,
"multiple": 8
},
"_meta": {
"title": "Resolution Selector"
}
}
})
# Replace each example.com URL with a public URL of your file.
workflow.set_input("247", "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)