Poll a Task until all targets complete and download results
Tasks process asynchronously. After creating a Task, poll Get Task by ID until each target’s status is completed or error. Add a delay between requests to avoid hitting rate limits.
For production, use webhooks instead of polling — you’ll receive a request each time a target completes.
import requestsimport timeAPI_KEY = "your_api_key"TASK_ID = "your_task_id"while True: task = requests.get( f"https://api.audioshake.ai/tasks/{TASK_ID}", headers={"x-api-key": API_KEY} ).json() statuses = [t["status"] for t in task["targets"]] print(f"Statuses: {statuses}") if all(s in ("completed", "error") for s in statuses): break time.sleep(5)# Download resultsfor target in task["targets"]: if target["status"] == "completed": for output in target["output"]: print(f"{target['model']}: {output['link']}") elif target["status"] == "error": print(f"{target['model']}: error - {target['error']}")
const API_KEY = "your_api_key";const TASK_ID = "your_task_id";let task;while (true) { const res = await fetch(`https://api.audioshake.ai/tasks/${TASK_ID}`, { headers: { "x-api-key": API_KEY } }); task = await res.json(); const statuses = task.targets.map(t => t.status); console.log("Statuses:", statuses); if (statuses.every(s => s === "completed" || s === "error")) break; await new Promise(r => setTimeout(r, 5000));}// Download resultsfor (const target of task.targets) { if (target.status === "completed") { for (const output of target.output) { console.log(`${target.model}: ${output.link}`); } } else if (target.status === "error") { console.log(`${target.model}: error -`, target.error); }}
Output download links expire after one hour. Re-fetch the Task to get fresh links, or download and store files in your own storage.