What You’ll Build
A video generation workflow that:- Submits text-to-video generation jobs
- Polls for job completion
- Retrieves the generated video
- Handles job status and errors
Prerequisites
- Node.js 18 or higher
- A Decart API key
Quick Start
Automatic Polling (Recommended)
ThesubmitAndPoll method handles job submission and polling automatically:
Manual Polling
For more control, you can manually poll job status:Job Status Lifecycle
Jobs progress through these states:- pending - Job is queued and waiting to start
- processing - Job is actively being processed
- completed - Job finished successfully
- failed - Job encountered an error
Available Video Models
You can use different video generation models:Advanced Options
Custom Polling Interval
Error Handling
Express API Example
Here’s how to integrate video generation into an Express API:Best Practices
- Use
submitAndPollfor simplicity - It handles polling automatically - Implement timeout logic - Set maximum wait times for long-running jobs
- Store job IDs - Save job IDs in a database for later retrieval
- Handle failures gracefully - Check for failed status and provide feedback
- Rate limiting - Be mindful of API rate limits when submitting many jobs