# 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": "LoadVideo",
"inputs": {
"file": "utility_relayvsr_video_x2_upscale_input.mp4"
},
"_meta": {
"title": "Load Video"
}
},
"106": {
"class_type": "SaveVideo",
"inputs": {
"codec": "auto",
"filename_prefix": "video/RelayVSR",
"format": "auto",
"format.codec": "auto",
"video": [
"108:105",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"202": {
"class_type": "Video Slice",
"inputs": {
"duration": 5,
"start_time": 0,
"strict_duration": False
},
"_meta": {
"title": "Trim Video"
}
},
"108:104": {
"class_type": "VSRDecode",
"inputs": {
"detail": 1,
"images": [
"108:2",
0
],
"samples": [
"108:6",
0
],
"vae": [
"108:7",
0
]
},
"_meta": {
"title": "VSR Decode"
}
},
"108:105": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"108:2",
1
],
"bit_depth": "auto",
"chroma_subsampling": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": [
"108:2",
2
],
"images": [
"108:104",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"108:2": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"1",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"108:4": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "relayvsr_x2_lightx2v_int8_convrot.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"108:5": {
"class_type": "RelayVSRConditioning",
"inputs": {
"images": [
"108:2",
0
],
"model": [
"108:4",
0
]
},
"_meta": {
"title": "RelayVSRConditioning"
}
},
"108:6": {
"class_type": "KSampler",
"inputs": {
"cfg": 1,
"denoise": 1,
"latent_image": [
"108:5",
1
],
"model": [
"108:4",
0
],
"negative": [
"108:5",
0
],
"positive": [
"108:5",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 42,
"steps": 1
},
"_meta": {
"title": "KSampler"
}
},
"108:7": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "relayvsr_flash_vae_x2_fp32.safetensors"
},
"_meta": {
"title": "Load VAE"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)