# 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({
"3": {
"class_type": "KSampler",
"inputs": {
"cfg": 7,
"denoise": 1,
"latent_image": [
"98",
0
],
"model": [
"78",
0
],
"negative": [
"47",
0
],
"positive": [
"94",
0
],
"sampler_name": "euler",
"scheduler": "simple",
"seed": [
"109",
0
],
"steps": 50
},
"_meta": {
"title": "KSampler"
}
},
"18": {
"class_type": "VAEDecodeAudio",
"inputs": {
"samples": [
"3",
0
],
"vae": [
"106",
0
]
},
"_meta": {
"title": "VAE Decode Audio"
}
},
"47": {
"class_type": "ConditioningZeroOut",
"inputs": {
"conditioning": [
"94",
0
]
},
"_meta": {
"title": "Conditioning Zero Out"
}
},
"78": {
"class_type": "ModelSamplingAuraFlow",
"inputs": {
"model": [
"104",
0
],
"sampling": "flow",
"shift": 3
},
"_meta": {
"title": "ModelSamplingAuraFlow"
}
},
"94": {
"class_type": "TextEncodeAceStepAudio1.5",
"inputs": {
"bpm": 85,
"cfg_scale": 2,
"clip": [
"105",
0
],
"duration": 120,
"generate_audio_codes": True,
"keyscale": "E minor",
"language": "en",
"lyrics": "[Intro]\n\n[Verse 1]\nDust on the dashboard, sun in the glass\nMile after mile of the same yellow grass\nYou left a cassette with a song you never sang\nI play it at dawn when the long shadows hang\n\n[Chorus]\nOh, the road keeps turning, turning gold\nEvery motel sign is a story told\nI'll keep driving till the evening's old\nFollowing the light you left me\n\n[Verse 2]\nCoffee gone cold at a two-pump town\nRadio static when the hills come down\nI wrote your name on a map in the rain\nFaded by morning, I wrote it again\n\n[Chorus]\nOh, the road keeps turning, turning gold\nEvery motel sign is a story told\nI'll keep driving till the evening's old\nFollowing the light you left me\n\n[Bridge]\n\n[Outro]\nFollowing the light you left me",
"min_p": 0,
"seed": [
"109",
0
],
"tags": "A sun-drenched, mid-tempo desert dream-pop ballad set at a relaxed eighty-five beats per minute, carried by a steady, dry drum groove with soft brush snares and an earthy upright bassline. Warm, chorus-drenched electric guitars interlock with dusty electric piano chords and shimmering Mellotron strings across an expansive stereo spread. The lead vocal is an intimate, breathy male falsetto, captured close-mic with gentle plate reverb and vintage tape flutter, delivering bittersweet nostalgia and open-road yearning. In the bridge, a mournful muted trumpet solo rises through lush analog synth swells, while the mix prioritizes analog saturation, crisp transient percussion, and an airy, golden-hour atmosphere with deep low-end warmth and wide spatial separation.",
"temperature": 0.85,
"timesignature": "4",
"top_k": 0,
"top_p": 1
},
"_meta": {
"title": "TextEncodeAceStepAudio1.5"
}
},
"98": {
"class_type": "EmptyAceStep1.5LatentAudio",
"inputs": {
"batch_size": 1,
"seconds": 120
},
"_meta": {
"title": "Empty Ace Step 1.5 Latent Audio"
}
},
"104": {
"class_type": "UNETLoader",
"inputs": {
"unet_name": "acestep_v1.5_xl_sft_bf16.safetensors",
"weight_dtype": "default"
},
"_meta": {
"title": "Load Diffusion Model"
}
},
"105": {
"class_type": "DualCLIPLoader",
"inputs": {
"clip_name1": "qwen_0.6b_ace15.safetensors",
"clip_name2": "qwen_4b_ace15.safetensors",
"device": "default",
"type": "ace"
},
"_meta": {
"title": "Load CLIP (Dual)"
}
},
"106": {
"class_type": "VAELoader",
"inputs": {
"vae_name": "ace_1.5_vae.safetensors"
},
"_meta": {
"title": "Load VAE"
}
},
"107": {
"class_type": "SaveAudioMP3",
"inputs": {
"audio": [
"18",
0
],
"filename_prefix": "audio/shift6",
"quality": "V0"
},
"_meta": {
"title": "Save Audio (MP3) (DEPRECATED)"
}
},
"109": {
"class_type": "PrimitiveInt",
"inputs": {
"value": 0
},
"_meta": {
"title": "Int"
}
}
})
# 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("107"):
output.to_file(output.name)