# 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": "TextGenerate",
"inputs": {
"audio": [
"5",
0
],
"clip": [
"3",
0
],
"image": [
"2",
0
],
"max_length": 2048,
"mtp": "auto",
"prompt": "Describe the image, and transcribe the audio",
"sampling_mode": "on",
"sampling_mode.min_p": 0.05,
"sampling_mode.presence_penalty": 0,
"sampling_mode.repetition_penalty": 1.05,
"sampling_mode.seed": 0,
"sampling_mode.temperature": 0.7,
"sampling_mode.top_k": 64,
"sampling_mode.top_p": 0.95,
"thinking": False,
"use_default_template": True
},
"_meta": {
"title": "Generate Text (DEPRECATED)"
}
},
"2": {
"class_type": "LoadImage",
"inputs": {
"image": "UPLOADED_image_FILENAME"
},
"_meta": {
"title": "Load Image"
}
},
"3": {
"class_type": "CLIPLoader",
"inputs": {
"clip_name": "gemma4_e4b_it_fp8_scaled.safetensors",
"device": "default",
"type": "stable_diffusion"
},
"_meta": {
"title": "Load CLIP"
}
},
"4": {
"class_type": "PreviewAny",
"inputs": {
"source": [
"1",
0
]
},
"_meta": {
"title": "Preview as Text"
}
},
"5": {
"class_type": "LoadAudio",
"inputs": {
"audio": "UPLOADED_audio_FILENAME"
},
"_meta": {
"title": "Load Audio"
}
},
"6": {
"class_type": "LoadVideo",
"inputs": {
"file": "video_wan_vace_inpainting_input_video.mp4"
},
"_meta": {
"title": "Load Video"
}
},
"7": {
"class_type": "GetVideoComponents",
"inputs": {
"video": [
"6",
0
]
},
"_meta": {
"title": "Get Video Components"
}
}
})
workflow.set_input("5", "audio", client.assets.from_url("https://comfy.org/catalog-media/73af9ea5-08d7-4a9f-a5a4-f5e4917febf1/2a8c71e0-16e9-4366-9849-b1ef38137337"))
workflow.set_input("2", "image", client.assets.from_url("https://comfy.org/catalog-media/dcac9855-5748-4d30-bec0-0394963faa51/45b7ae5b-8ab2-4eae-a622-57d86e51460f"))
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)