# 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({
"14": {
"class_type": "TextEncodeAceStepAudio",
"inputs": {
"clip": [
"40",
1
],
"lyrics": "[verse]\nMidnight train is rolling in,\nneon rain on silver skin,\nI left my coat beside the door\nand chased the lights I knew before.\n\n[chorus]\nOh, the city lights are low,\ncarry me where the rivers go,\nhome is a song I used to know.",
"lyrics_strength": 0.99,
"tags": "synthwave, retro 1980s analog synthesizers, warm polysynth pads, gated reverb snare, airy breathy female vocals, pulsing octave bass, shimmering arpeggios, glossy chorus guitar, dreamy, nostalgic, night drive through a neon city, 92 bpm"
},
"_meta": {
"title": "TextEncodeAceStepAudio"
}
},
"18": {
"class_type": "VAEDecodeAudio",
"inputs": {
"samples": [
"52",
0
],
"vae": [
"40",
2
]
},
"_meta": {
"title": "VAE Decode Audio"
}
},
"40": {
"class_type": "CheckpointLoaderSimple",
"inputs": {
"ckpt_name": "ace_step_v1_3.5b.safetensors"
},
"_meta": {
"title": "Load Checkpoint"
}
},
"44": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"14",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"49": {
"class_type": "LatentApplyOperationCFG",
"inputs": {
"end_percent": 1,
"model": [
"51",
0
],
"operation": [
"50",
0
],
"start_percent": 0
},
"_meta": {
"title": "LatentApplyOperationCFG"
}
},
"50": {
"class_type": "LatentOperationTonemapReinhard",
"inputs": {
"multiplier": 1.0000000000000002
},
"_meta": {
"title": "LatentOperationTonemapReinhard"
}
},
"51": {
"class_type": "ModelSamplingSD3",
"inputs": {
"model": [
"40",
0
],
"shift": 5.000000000000001
},
"_meta": {
"title": "ModelSamplingSD3"
}
},
"52": {
"class_type": "KSampler",
"inputs": {
"cfg": 5,
"denoise": 0.3,
"latent_image": [
"68",
0
],
"model": [
"49",
0
],
"negative": [
"44",
0
],
"positive": [
"14",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": 378808614834773,
"steps": 50
},
"_meta": {
"title": "KSampler"
}
},
"59": {
"class_type": "SaveAudioMP3",
"inputs": {
"audio": [
"18",
0
],
"filename_prefix": "audio/ComfyUI",
"quality": "V0"
},
"_meta": {
"title": "Save Audio (MP3) (DEPRECATED)"
}
},
"64": {
"class_type": "LoadAudio",
"inputs": {
"audio": "UPLOADED_audio_FILENAME"
},
"_meta": {
"title": "Load Audio"
}
},
"68": {
"class_type": "VAEEncodeAudio",
"inputs": {
"audio": [
"64",
0
],
"vae": [
"40",
2
]
},
"_meta": {
"title": "VAE Encode Audio"
}
}
})
workflow.set_input("64", "audio", client.assets.from_url("https://comfy.org/catalog-media/bb5e13c6-2773-45e0-9ef6-b6a51695eb0c/4f126f4f-af39-4403-bbca-4746aac168f0"))
# 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("59"):
output.to_file(output.name)