Skip to main content

Path Parameters

id
string
required
The task ID returned from the create video request. Treat id and task_id as the same async identity.
If a create response returns poll_url, call that exact URL. When it points to /v1/tasks/{id}, treat that as the canonical fixed status endpoint.If the task no longer exists or is no longer available in the public task record, TokenLab returns async_task_not_found with the message Task not found or no longer available.

Response

id
string
Canonical async task identifier.
task_id
string
Async task identifier alias.
poll_url
string
Preferred polling URL when the create response supplies one.
billing_transaction_id
string
TokenLab billing transaction ID when settlement already completed. This is the dashboard/accounting transaction identifier and is separate from the async id / task_id.
status
string
Task status: pending, processing, completed, failed.
progress
number
Optional progress value. Returned only when a real progress value is available; use status to determine completion.
video_url
string
URL of the generated video (when completed).
video
object
Single video payload with url, duration, width, and height when available.
videos
array
Multiple video payloads when the generation task returns more than one output.
error
string
Error message (if failed).
created
integer
Creation timestamp.
updated
integer
Last update timestamp.
model
string
Model used for the task.
curl "https://api.tokenlab.sh/v1/tasks/ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
  -H "Authorization: Bearer sk-your-api-key"
import requests
import time

task_id = "ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

while True:
    response = requests.get(
        f"https://api.tokenlab.sh/v1/tasks/{task_id}",
        headers={"Authorization": "Bearer sk-your-api-key"}
    )

    data = response.json()
    print(f"Status: {data['status']}")

    if data["status"] == "completed":
        print(f"Video URL: {data['video_url']}")
        break
    elif data["status"] == "failed":
        print(f"Error: {data['error']}")
        break

    time.sleep(5)  # Poll every 5 seconds
const taskId = 'ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';

async function pollForVideo() {
  while (true) {
    const response = await fetch(
      `https://api.tokenlab.sh/v1/tasks/${taskId}`,
      { headers: { 'Authorization': 'Bearer sk-your-api-key' } }
    );

    const data = await response.json();
    console.log(`Status: ${data.status}`);

    if (data.status === 'completed') {
      console.log(`Video URL: ${data.video_url}`);
      return data.video_url;
    } else if (data.status === 'failed') {
      throw new Error(data.error);
    }

    await new Promise(r => setTimeout(r, 5000));
  }
}
package main

import (
    "encoding/json"
    "fmt"
    "net/http"
    "time"
)

func main() {
    taskID := "ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    for {
        req, _ := http.NewRequest("GET",
            fmt.Sprintf("https://api.tokenlab.sh/v1/tasks/%s", taskID), nil)
        req.Header.Set("Authorization", "Bearer sk-your-api-key")

        client := &http.Client{}
        resp, _ := client.Do(req)

        var result map[string]interface{}
        json.NewDecoder(resp.Body).Decode(&result)
        resp.Body.Close()

        fmt.Printf("Status: %s\n", result["status"])

        if result["status"] == "completed" {
            fmt.Printf("Video URL: %s\n", result["video_url"])
            break
        } else if result["status"] == "failed" {
            fmt.Printf("Error: %s\n", result["error"])
            break
        }

        time.Sleep(5 * time.Second)
    }
}
<?php
$taskId = 'ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';

while (true) {
    $ch = curl_init("https://api.tokenlab.sh/v1/tasks/{$taskId}");

    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [
            'Authorization: Bearer sk-your-api-key'
        ]
    ]);

    $response = curl_exec($ch);
    curl_close($ch);

    $data = json_decode($response, true);
    echo "Status: {$data['status']}\n";

    if ($data['status'] === 'completed') {
        echo "Video URL: {$data['video_url']}\n";
        break;
    } elseif ($data['status'] === 'failed') {
        echo "Error: {$data['error']}\n";
        break;
    }

    sleep(5);
}
{
  "id": "ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "task_id": "ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "poll_url": "/v1/tasks/ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "status": "pending",
  "model": "veo3.1",
  "created": 1706000000,
  "updated": 1706000000
}
{
  "id": "ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "task_id": "ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "poll_url": "/v1/tasks/ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "status": "processing",
  "model": "veo3.1",
  "created": 1706000000,
  "updated": 1706000030
}
{
  "id": "ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "task_id": "ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "poll_url": "/v1/tasks/ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "billing_transaction_id": "cmo164zyc0s48jpgegi80vqv4",
  "status": "completed",
  "video_url": "https://assets.tokenlab.sh/videos/abc123.mp4",
  "model": "veo3.1",
  "created": 1706000000,
  "updated": 1706000060
}
{
  "id": "ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "task_id": "ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "poll_url": "/v1/tasks/ldtask_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "status": "failed",
  "error": "Content policy violation",
  "model": "veo3.1",
  "created": 1706000000,
  "updated": 1706000060
}

Polling Best Practices

  • Poll every 5-10 seconds
  • Implement exponential backoff for long tasks
  • Set a maximum timeout (e.g., 10 minutes)
  • Handle failed status gracefully
import time

def wait_for_video(task_id, max_wait=600, interval=5):
    """Wait for video with timeout."""
    start = time.time()

    while time.time() - start < max_wait:
        response = requests.get(
            f"https://api.tokenlab.sh/v1/tasks/{task_id}",
            headers={"Authorization": "Bearer sk-your-api-key"}
        )
        data = response.json()

        if data["status"] == "completed":
            return data["video_url"]
        elif data["status"] == "failed":
            raise Exception(data.get("error", "Video generation failed"))

        time.sleep(interval)

    raise TimeoutError("Video generation timed out")