AI music generator API key: a Python script that polls and downloads
Use your SUME_API_KEY to generate a track with the Music Router, poll the job and read the audio URL. A 28-line Python script with the $0.125 price.

"AI music generator API key" is on Google's autocomplete today (read 2026-10-07). On Sume there is one key for every product. Create it in the workspace settings, export it as SUME_API_KEY, and send it as a Bearer token. The music call is asynchronous: it returns a job, and you poll until result_ready is true.
The script below uses requests, an Idempotency-Key so a retry cannot bill twice, and a main() function. It makes one real call at $0.125 (read 2026-10-07), so it needs a funded key to run.
The script
import os, time, uuid, requests
BASE = "https://api.sume.com"
H = {"Authorization": "Bearer " + os.environ["SUME_API_KEY"]}
def main():
r = requests.post(
BASE + "/v1/music-router/generate",
headers={**H, "Idempotency-Key": str(uuid.uuid4())},
json={"prompt": "Warm lo-fi, 80 BPM, A minor. Soft piano, vinyl crackle, "
"brushed drums. A calm 60-second loop. Instrumental, no vocals."},
timeout=60,
)
r.raise_for_status()
job_id = r.json()["job_id"]
while True:
s = requests.get(f"{BASE}/v1/jobs/{job_id}/status", headers=H, timeout=30).json()
if s.get("result_ready"):
break
time.sleep(5)
res = requests.get(f"{BASE}/v1/jobs/{job_id}/result", headers=H, timeout=30).json()
for a in res["result"]["artifacts"]:
if a["type"] == "audio":
print(a["url"])
if __name__ == "__main__":
main()What to know before you run it
- A missing
SUME_API_KEYraisesKeyErroron the first line ofmain(), before any request is sent. - Reuse the same
Idempotency-Keyto retry one logical request; a fresh key is a new job and a new charge. - The only request controls are
prompt, optionalimage_urland optionalengine. There is nodurationfield. - Sume media inputs must be public HTTPS URLs on
media.sume.com; import other files first withPOST /v1/media-imports. - Stop looping on a failed job: check the status field and print the error instead of waiting forever.
Cost per run
Every generation is $0.125, so ten test prompts cost $1.25. The status and result calls are free. Add max_spend_usd while you iterate so a loop bug cannot spend more than you planned.
Sources
Related posts
More in Developers
- AI song generator API: section markers in, lyrics out, $0.125
Sume Music Router writes songs from a 5,000-character prompt: put [0:00-0:30] section markers and a BPM in, read result.lyrics out. $0.125 each.
- aiohttp web server: verify a Sume webhook with await request.read()
An aiohttp 3.14 web handler that verifies the Sume HMAC on await request.read(), then calls request.json(). Exits on an empty secret and handles webhook.test.
- Alt text for a 30-image gallery in one Sume Agent Completion
One Agent Completion call can take up to 30 images and return an alts array under an object schema. Python stdlib script with the cap, poll and limits.
- API key scopes for Sume: which key can call which endpoint family?
Sume API keys carry fixed scopes: formats:write, actions:read, agent_completions:write, account:read. Which scope each route needs, and why old keys get a 403.
Written by Sume