Learn how to create AI-generated videos from images using the Weights API. This guide walks you through the process of transforming static images into dynamic video content.
The Weights API provides video generation capabilities that can animate static images. You provide an input image and a prompt describing the desired motion, and the API creates a video that brings your image to life.
// Example: Upload to a cloud storage service// This is just an example - you'll need to implement your own upload logicasync function uploadImage(imageFile) { // Upload to your preferred service (AWS S3, Cloudinary, etc.) const imageUrl = await uploadToCloudStorage(imageFile); return imageUrl;}const inputImageUrl = await uploadImage("path/to/your/image.jpg");console.log("Image uploaded to:", inputImageUrl);
Video generation is asynchronous and typically takes longer than image generation. Poll the status to track progress:
Copy
Ask AI
async function checkVideoStatus(jobId) { const job = await client.videos.retrieve(jobId); console.log(`Status: ${job.status}`); switch (job.status) { case "QUEUED": console.log("Your video job is waiting in the queue..."); break; case "PROCESSING": console.log("Your video is being generated..."); break; case "SUCCEEDED": console.log("Video generated successfully!"); console.log("Download URL:", job.outputUrl); break; case "ERRORED": console.log("Video generation failed. Please try again."); break; } return job;}// Check status every 30 seconds (videos take longer than images)const job = await checkVideoStatus(videoJob.id);
Once the status is SUCCEEDED, your video is ready for download:
Copy
Ask AI
if (job.status === "SUCCEEDED") { console.log("Your video is ready!"); console.log("Download URL:", job.outputUrl); // You can now download or stream the video // The URL will be available for a limited time}