Poll Video Results
Endpoint
Section titled “Endpoint”GET https://api.apimart.cc/v1/videos/{task_id}Response Format
Section titled “Response Format”While Processing
Section titled “While Processing”{ "id": "vt-abc123def", "object": "video", "model": "tk-wan3.0-video-prime", "status": "in_progress", "progress": 45, "created_at": 1760000000}When Completed
Section titled “When Completed”{ "id": "vt-abc123def", "object": "video", "model": "tk-wan3.0-video-prime", "status": "completed", "created_at": 1760000000, "completed_at": 1760000142, "url": "https://cdn.example.com/output/video.mp4"}When Failed
Section titled “When Failed”{ "id": "vt-abc123def", "object": "video", "model": "tk-wan3.0-video-prime", "status": "failed", "created_at": 1760000000, "error": { "code": "task_failed", "message": "Content policy violation detected in prompt" }}Status Values
Section titled “Status Values”| Status | Description | Action |
|---|---|---|
queued | Task waiting in queue | Continue polling |
in_progress | Model generating video | Continue polling |
completed | Video ready | Download from url |
failed | Generation failed | Check error field |
unknown | Execution outcome needs reconciliation | Retain the ID and contact support; do not resubmit automatically |
Polling Strategy
Section titled “Polling Strategy”import timeimport requests
def wait_for_video(task_id, api_key, max_wait=600, interval=5): """Poll until the video task reaches a terminal state.""" deadline = time.monotonic() + max_wait while time.monotonic() < deadline: response = requests.get( f"https://api.apimart.cc/v1/videos/{task_id}", headers={"Authorization": f"Bearer {api_key}"}, timeout=30, ) response.raise_for_status() resp = response.json()
if resp["status"] == "completed": return resp if resp["status"] == "failed": raise RuntimeError(f"Video failed: {resp.get('error', 'unknown')}") if resp["status"] not in ("queued", "in_progress"): raise RuntimeError(f"Task {task_id} needs review: {resp['status']}")
time.sleep(interval)
raise TimeoutError(f"Video did not complete within {max_wait}s")Handling Timeouts
Section titled “Handling Timeouts”If your polling loop times out:
- The task may still be running — check again later with the same task ID
- Don’t resubmit immediately — you’d be charged for a duplicate
- Keep the task ID — no fixed retention window is promised by this guide
Video URL
Section titled “Video URL”The url field in a completed response points to the generated video file.
URLs may expire
We recommend downloading the video file to your own storage as soon as it’s completed. Don’t rely on the URL being permanently available.
# Download the videodownload = requests.get(resp["url"], timeout=60)download.raise_for_status()video_data = download.contentwith open("output.mp4", "wb") as f: f.write(video_data)Billing
Section titled “Billing”Accepted submission reserves balance; completion settles the final charge. Confirmed failure triggers failure settlement. A polling timeout or unknown state is not a confirmed failure. Inspect usage logs and balance for settlement information. See Pricing & Billing.