# 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({
"87": {
"class_type": "LoadVideo",
"inputs": {
"file": "UPLOADED_video_FILENAME"
},
"_meta": {
"title": "Load Video"
}
},
"88": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/depth_anything3",
"format": "auto",
"format.codec": "auto",
"video": [
"89",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"89": {
"class_type": "CreateVideo",
"inputs": {
"audio": [
"14:86",
1
],
"bit_depth": "auto",
"chroma_subsampling": "auto",
"codec": "none",
"color_space": "sRGB",
"fps": [
"14:86",
2
],
"images": [
"14:7",
0
]
},
"_meta": {
"title": "Create Video"
}
},
"14:5": {
"class_type": "DA3Inference",
"inputs": {
"da3_model": [
"14:82",
0
],
"image": [
"14:86",
0
],
"mode": "mono",
"resize_method": "lower_bound_resize",
"resolution": 504
},
"_meta": {
"title": "Run Depth Anything 3"
}
},
"14:7": {
"class_type": "DA3Render",
"inputs": {
"da3_geometry": [
"14:5",
0
],
"output": "depth",
"output.apply_sky_clip": False,
"output.normalization": "v2_style"
},
"_meta": {
"title": "Render Depth Anything 3"
}
},
"14:82": {
"class_type": "LoadDA3Model",
"inputs": {
"model_name": "depth_anything_3_mono_large.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Depth Anything 3"
}
},
"14:86": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"14:90",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"14:90": {
"class_type": "Video Slice",
"inputs": {
"duration": 5,
"start_time": 0,
"strict_duration": False,
"video": [
"87",
0
]
},
"_meta": {
"title": "Trim Video"
}
}
})
workflow.set_input("87", "file", client.assets.from_url("https://comfy.org/catalog-media/0014dc47-df26-4ef7-950f-285dd9b4be04/4693f5a0-e74a-403b-8566-f553e0d5bfea"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)
for output in job.get_outputs("88"):
output.to_file(output.name)