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']}")
Output download links expire after one hour. Re-fetch the Task to get fresh links, or download and store files in your own storage.