Seedance 2.0 Python Requests Example for Async Jobs

From Wiki Planet
Jump to navigationJump to search

In the fast-evolving world of creative media, easy-to-use, API-first tools that support asynchronous video generation have become crucial for developers building video applications. Seedance 2.0, powered by Apiframe, is an exciting step forward that unifies multiple modes of video generation—text-to-video, image-to-video, and reference-to-video—into a single streamlined API. It also supports synchronized audio generation and dynamic, director-style camera movements via natural language prompts.

Brands like ByteDance and CapCut already use Seedance-generated workflows to enhance their media creation pipeline, thanks to its powerful multimodal references for style, motion, and sound. In this article, I'll walk you through how to use the Seedance 2.0 Python requests library example to start async jobs, poll for results, and understand the billing model, which is based on video output length billed per second.

Why Seedance 2.0? One Endpoint, Multiple Video Modalities

Many video generators today require separate endpoints or APIs to handle different input types like images, text, or video references. Seedance 2.0 changes this by providing a single POST endpoint to generate videos from any combination of inputs:

  • Text prompts describing scene and action
  • Images as style or background references
  • Reference videos for motion or pacing

This multimodal fusion is powered by specifying each input with a role, allowing you to express complex creative directions naturally:

Role Description Example style Defines the artistic look, color grading or theme URL to a painting or photo, e.g. Van Gogh style image motion Reference video or animation that guides movement Short clip of a dancer or an object moving sound Audio track providing soundtrack or beat Background music or voice-over guidance

This flexibility builds on Seedance’s unique capability to generate native synchronized audio in the same generation pass, meaning your final video and sound are perfectly timed without post-processing.

API Endpoints and Workflow

Seedance 2.0 offers two main API endpoints:

  • POST https://api.apiframe.ai/v2/videos/generate — to submit a new video generation job with your inputs and parameters
  • GET https://api.apiframe.ai/v2/jobs/id — to poll and retrieve job status and final results asynchronously

This pattern decouples submission and retrieval, enabling you to integrate non-blocking workflows and long-running video rendering in your app or backend.

Pricing Model: Billed Per Second of Video Output

It’s important to plan usage and cost effectively. Seedance charges based on how many seconds of video you generate, not just the number of requests or complexity. This means you have granular control over billing based on final video duration, which is ideal for keeping costs predictable and aligned with actual content length.

Seedance 2.0 Python Requests Tutorial

Let’s jump into a practical example using Python’s popular requests library that will:

  1. Submit an asynchronous video generation job
  2. Extract the jobId from the response
  3. Use a poll loop to track job status until completion
  4. Retrieve the final video URL once the job is done
  5. Apiframe video API

Step 1: Setup and Prepare Your Request

First, make sure you have requests installed:

pip install requests

Here’s a sample Python script demonstrating how to initiate the generation:

import requests import time API_KEY = 'your_api_key_here' # Replace with your Apiframe API key BASE_URL = 'https://api.apiframe.ai/v2' def create_job(): url = f"BASE_URL/videos/generate" headers = 'Authorization': f'Bearer API_KEY', 'Content-Type': 'application/json' payload = "inputs": [ "role": "style", "image_url": "https://example.com/van_gogh_style.jpg" , "role": "motion", "video_url": "https://example.com/dance_motion.mp4" , "role": "sound", "audio_url": "https://example.com/background_music.mp3" , "role": "text", "text": "A surreal dancer performing in a sunlit forest, dreamlike atmosphere" ], "parameters": "resolution": "1920x1080", "duration_sec": 15, "generate_audio": True, "camera_movement": "dramatic tracking shot from left to right" response = requests.post(url, json=payload, headers=headers) response.raise_for_status() data = response.json() job_id = data.get("jobId") if not job_id: raise ValueError("Missing jobId in response") print(f"Job created with jobId: job_id") return job_id

Notes:

  • We sanity-check that jobId is present to avoid silent errors.
  • The resolution default is set explicitly to 1920x1080 to ensure HD output.
  • generate_audio is enabled because audio synchronicity is a key feature.
  • The camera_movement parameter uses natural language to instruct dynamic, director-style shots.

Step 2: Polling the Job Status

The video generation happens asynchronously. After submission, you need to poll the job status using the returned jobId. Polling is done by sending GET requests to /jobs/id until the job completes or fails.

def poll_job(job_id, poll_interval=5): url = f"BASE_URL/jobs/job_id" headers = 'Authorization': f'Bearer API_KEY' while True: response = requests.get(url, headers=headers) response.raise_for_status() job_data = response.json() status = job_data.get("status") print(f"Job status: status") if status == "completed": video_url = job_data.get("result", ).get("video_url") if not video_url: raise ValueError("Missing video_url in completed job") print(f"Video available at: video_url") return video_url elif status == "failed": error = job_data.get("error", "Unknown error") raise RuntimeError(f"Job failed: error") time.sleep(poll_interval)

This pattern is standard for async media pipelines:

  • status: monitors job progression (e.g., "queued", "processing", "completed", "failed")
  • Gracefully handles failure and missing URLs
  • Waits poll_interval seconds between checks to avoid excessive API requests

Putting it All Together

Finally, combine these methods to submit and track an async video generation job:

if __name__ == "__main__": try: job_id = create_job() video_url = poll_job(job_id) print(f"Successfully generated video: video_url") except Exception as e: print(f"Error occurred: e")

Integrations and Real-World Applications

ByteDance and CapCut have embraced APIs like Seedance from Apiframe to power user-generated content and automated video editing, enhancing their products with dynamic video creation directly from prompts, references, and styles provided by users or machine learning models.

Seedance 2.0's flexibility with its endpoint allows teams to:

  • Quickly prototype creative ideas by mixing text, images, and videos
  • Generate native audio-video synchronized clips to avoid complex postproduction
  • Use prompt-driven camera movement for richer storytelling experiences
  • Keep costs predictable by paying per second of video output

Summary

Seedance 2.0 by Apiframe represents a breakthrough in how asynchronous video generation APIs are architected. By offering a single endpoint that accepts multimodal inputs with granular role definitions—for style, motion, sound, and text—and generating synchronized audio alongside video with director-style cinematic controls, Seedance empowers developers and creatives to build next-gen apps like ByteDance and CapCut.

Using Python requests with robust jobId handling and an efficient poll loop makes integrating this asynchronous video generation straightforward and scalable. Keep in mind the billing is based on video output duration, so designing your prompts and parameters carefully will optimize your investment.

Ready to try Seedance 2.0? Grab your API key from Apiframe’s portal and start creating stunning videos programmatically with just a few lines of Python.

References and Links

  • POST /videos/generate — Apiframe Seedance 2.0 API
  • GET /jobs/id — Retrieve asynchronous job status
  • ByteDance Company
  • CapCut Video Editor
  • Apiframe Platform