# 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": "KlingAvatarNode",
"inputs": {
"image": [
"3",
0
],
"mode": "pro",
"prompt": "The weathered fisherman speaks to the camera in a slow, low, steady voice, like an old hand passing on a hard-earned lesson. His brow lifts slightly on the first line, his eyes narrow as he talks about reading the water, and he gives a small, knowing nod before the last words, ending with a faint, wry half-smile. His head moves only a little, his gaze stays on the lens. Wind tugs at the knit cap and the collar of the oilskin jacket, fine sea spray drifts past, and the storm light flickers warm on his face.",
"seed": 209062259,
"sound_file": [
"4",
0
]
},
"_meta": {
"title": "Kling Avatar 2.0"
}
},
"3": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"4": {
"class_type": "LoadAudio",
"inputs": {
"audio": "UPLOADED_audio_FILENAME"
},
"_meta": {
"title": "Load Audio"
}
},
"5": {
"class_type": "SaveVideo",
"inputs": {
"filename_prefix": "video/Kling_avatar2.0",
"format": "auto",
"format.codec": "auto",
"video": [
"1",
0
]
},
"_meta": {
"title": "Save Video"
}
}
})
workflow.set_input("4", "audio", client.assets.from_url("https://comfy.org/catalog-media/438dbca5-dffd-47fe-80a3-224a1fc5281c/c8ce685d-16dd-476d-8384-80eddc5dc837"))
workflow.set_input("3", "image", client.assets.from_url("https://comfy.org/catalog-media/73cdc42d-5d75-4dbd-9e53-8c124885f1fc/d95b5723-82b3-4e6b-8bf3-c3fe4d2d3cb7"))
# 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("5"):
output.to_file(output.name)