# 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": "masked_woman_desert_golden_hour.mp4"
},
"_meta": {
"title": "Load Video"
}
},
"3": {
"class_type": "LtxApiVideoShotEdit",
"inputs": {
"stills.frame_1": [
"109:108",
1
],
"stills.image_1": [
"106",
0
],
"video": [
"1",
0
]
},
"_meta": {
"title": "LtxApiVideoShotEdit"
}
},
"4": {
"class_type": "SaveVideo",
"inputs": {
"codec": "auto",
"filename_prefix": "video/LTX_VFX_shot_edit",
"format": "mp4",
"format.codec": "h264",
"format.codec.encoding": "auto",
"video": [
"3",
0
]
},
"_meta": {
"title": "Save Video"
}
},
"103": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"109:102",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"106": {
"class_type": "SaveImageAdvanced",
"inputs": {
"filename_prefix": "video/LTX_VFX_shot_edit_frame",
"format": "png",
"format.bit_depth": "8-bit",
"format.channels": "auto",
"format.input_color_space": "sRGB",
"images": [
"125",
0
]
},
"_meta": {
"title": "Save Image (Advanced)"
}
},
"125": {
"class_type": "GeminiImage2Node",
"inputs": {
"aspect_ratio": "auto",
"images": [
"103",
0
],
"model": "gemini-3-pro-image-preview",
"prompt": "Remove the silver spiked mask completely and reveal the bare face underneath:\nnatural skin with visible nose, lips, cheeks and jaw, the same eyes, same expression,\nno makeup change, no marks on the skin.\n\nKeep the hair, the sheer veil, the beaded collar, the pose, framing and lighting unchanged.\n\nReplace only the background: a dim stone corridor lit by warm candle sconces, deep\nshadow with soft warm falloff. Keep the woman, her bare face, hair, veil, beads,\npose, framing and the warm light on her skin unchanged.",
"resolution": "1K",
"response_modalities": "IMAGE+TEXT",
"seed": 42,
"system_prompt": "You are an expert image-generation engine. You must ALWAYS produce an image.\nInterpret all user input—regardless of format, intent, or abstraction—as literal visual directives for image composition.\nIf a prompt is conversational or lacks specific visual details, you must creatively invent a concrete visual scenario that depicts the concept.\nPrioritize generating the visual representation above any text, formatting, or conversational requests."
},
"_meta": {
"title": "Nano Banana Pro (Google Gemini Image)"
}
},
"109:100": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"1",
0
]
},
"_meta": {
"title": "Get Video Components"
}
},
"109:102": {
"class_type": "ImageFromBatch",
"inputs": {
"batch_index": [
"109:108",
1
],
"image": [
"109:100",
0
],
"length": 1
},
"_meta": {
"title": "Get Image from Batch"
}
},
"109:107": {
"class_type": "PrimitiveFloat",
"inputs": {
"value": 0.1
},
"_meta": {
"title": "Float"
}
},
"109:108": {
"class_type": "ComfyMathExpression",
"inputs": {
"expression": "a * b",
"values.a": [
"109:100",
2
],
"values.b": [
"109:107",
0
]
},
"_meta": {
"title": "Math Expression"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)