Models Hub
API ReferenceSeedance 2.x

Python Polling & Download

Create a Seedance 2.0 task, poll its status, and download the result video with Python.

Edit this page

Seedance 2.0 is an asynchronous task API. Poll the task status at a fixed interval; generation commonly takes a few minutes. The example below uses a 10-second polling interval.

pip install requests
import os
import time
import requests

BASE_URL = "https://modelsok.com"
API_KEY = os.environ["MODELSOK_API_KEY"]
MODEL = "doubao-seedance-2-0-260128"


def create_task(prompt: str) -> str:
    response = requests.post(
        f"{BASE_URL}/api/v3/contents/generations/tasks",
        headers={
            "Authorization": f"Bearer {API_KEY}",
            "Content-Type": "application/json",
        },
        json={
            "model": MODEL,
            "content": [
                {
                    "type": "text",
                    "text": prompt,
                }
            ],
            "resolution": "480p",
            "ratio": "16:9",
            "duration": 5,
            "generate_audio": True,
            "watermark": False,
        },
        timeout=180,
    )
    response.raise_for_status()
    return response.json()["id"]


def wait_for_result(task_id: str, max_wait: int = 600, interval: int = 10) -> str:
    elapsed = 0
    while elapsed < max_wait:
        time.sleep(interval)
        elapsed += interval
        response = requests.get(
            f"{BASE_URL}/api/v3/contents/generations/tasks/{task_id}",
            headers={"Authorization": f"Bearer {API_KEY}"},
            timeout=60,
        )
        response.raise_for_status()
        data = response.json()
        status = data.get("status")
        print(f"[{elapsed}s] status={status}")
        if status == "succeeded":
            return data["content"]["video_url"]
        if status == "failed":
            error = data.get("error") or {}
            raise RuntimeError(error.get("message", "video generation failed"))
    raise TimeoutError(f"task timed out: {task_id}")


def download_video(video_url: str, save_path: str) -> None:
    response = requests.get(video_url, stream=True, timeout=120)
    response.raise_for_status()
    with open(save_path, "wb") as file:
        for chunk in response.iter_content(chunk_size=8192):
            if chunk:
                file.write(chunk)


if __name__ == "__main__":
    task_id = create_task("A golden Shiba Inu running under cherry blossoms, camera slowly rising")
    video_url = wait_for_result(task_id)
    download_video(video_url, "seedance-output.mp4")

The content.video_url in the result is usually time-limited; in production, re-store it to your own object storage right after fetching.