-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmusic.py
More file actions
38 lines (33 loc) · 1.28 KB
/
Copy pathmusic.py
File metadata and controls
38 lines (33 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Suno V5 music generation with job polling. $0.09 per generation request;
# one request returns ~2 track variations for a single charge.
# Supports plain-prompt, custom lyrics + style, and instrumental modes.
# export KUNAVO_API_KEY=sk-kunavo-...
import os
import time
import requests
BASE = "https://api.kunavo.com/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['KUNAVO_API_KEY']}"}
# 1. Submit an async music job
job = requests.post(
f"{BASE}/audio/music/jobs",
headers=HEADERS,
json={
"model": "suno-v5",
"prompt": "dreamy synthwave about writing code at 2am, female vocals",
},
timeout=60,
).json()
job_id = job["id"] # "msc_abc..."
status = job["status"] # "queued"
print(f"job {job_id} submitted, polling...")
# 2. Poll until terminal (recommended cadence: 5s, backing off to 30s)
while status not in ("completed", "failed"):
time.sleep(10)
j = requests.get(f"{BASE}/audio/music/jobs/{job_id}", headers=HEADERS, timeout=60).json()
status = j["status"]
print(f" status: {status}")
if status == "failed":
raise SystemExit(f"generation failed: {j['error']['message']}")
# Suno returns ~2 tracks per request for a single charge.
for track in j["output"]["tracks"]:
print(track["url"]) # temporary URLs — download and re-host