Video Generation
Enables backend AI video generation from text or images using an asynchronous polling model.
Install
mkdir -p .claude/skills/video-generation && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/11369" && unzip -o skill.zip -d .claude/skills/video-generation && rm skill.zipInstalls to .claude/skills/video-generation
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Implement AI-powered video generation capabilities using the z-ai-web-dev-sdk. Use this skill when the user needs to generate videos from text prompts or images, create video content programmatically, or build applications that produce video outputs. Supports asynchronous task management with status polling and result retrieval.Key capabilities
- →Generate video from text
- →Create video from images
- →Poll asynchronous task status
- →Configure resolution and frame rate
How it works
The skill uses an asynchronous task model where the user creates a generation task and polls the API for the final video result.
Inputs & outputs
When to use Video Generation
- →Building AI-driven video content engines
- →Integrating video generation into web platforms
- →Automating video creation pipelines
About this skill
Video Generation Skill
This skill guides the implementation of video generation functionality using the z-ai-web-dev-sdk package, enabling AI models to create videos from text descriptions or images through asynchronous task processing.
Skills Path
Skill Location: {project_path}/skills/video-generation
This skill is located at the above path in your project.
Reference Scripts: Example test scripts are available in the {Skill Location}/scripts/ directory for quick testing and reference. See {Skill Location}/scripts/video.ts for a working example.
Overview
Video Generation allows you to build applications that can create video content from text prompts or images, with customizable parameters like resolution, frame rate, duration, and quality settings. The API uses an asynchronous task model where you create a task and poll for results.
IMPORTANT: z-ai-web-dev-sdk MUST be used in backend code only. Never use it in client-side code.
Prerequisites
The z-ai-web-dev-sdk package is already installed. Import it as shown in the examples below.
CLI Usage (For Simple Tasks)
For simple video generation tasks, you can use the z-ai CLI instead of writing code. The CLI handles task creation and polling automatically, making it ideal for quick tests and simple automation.
Basic Text-to-Video
# Generate video with automatic polling
z-ai video --prompt "A cat playing with a ball" --poll
# Using short options
z-ai video -p "Beautiful landscape with mountains" --poll
Custom Quality and Settings
# Quality mode (speed or quality)
z-ai video -p "Ocean waves at sunset" --quality quality --poll
# Custom resolution and FPS
z-ai video \
-p "City timelapse" \
--size "1920x1080" \
--fps 60 \
--poll
# Custom duration (5 or 10 seconds)
z-ai video -p "Fireworks display" --duration 10 --poll
Image-to-Video
IMPORTANT: For image_url parameter, it is strongly recommended to use base64-encoded image data instead of URLs. This approach is more reliable and avoids potential network issues or access restrictions.
Note: Match the MIME type in the data URI to your actual image format (image/jpeg, image/png, image/webp, etc.) to avoid decoding issues.
# Generate video from single image using base64 (RECOMMENDED)
# Convert your image to base64 with correct MIME type
# For PNG images
IMAGE_BASE64=$(base64 -i image.png)
z-ai video \
--image-url "data:image/png;base64,${IMAGE_BASE64}" \
--prompt "Make the scene come alive" \
--poll
# For JPEG images
IMAGE_BASE64=$(base64 -i photo.jpg)
z-ai video \
--image-url "data:image/jpeg;base64,${IMAGE_BASE64}" \
--prompt "Make the scene come alive" \
--poll
# For WebP images
IMAGE_BASE64=$(base64 -i image.webp)
z-ai video \
--image-url "data:image/webp;base64,${IMAGE_BASE64}" \
--prompt "Make the scene come alive" \
--poll
# Using URL (less recommended, may have reliability issues)
z-ai video \
-i "https://example.com/photo.jpg" \
-p "Add motion to this scene" \
--poll
First-Last Frame Mode
IMPORTANT: For best reliability, use base64-encoded images instead of URLs. Ensure the MIME type matches your actual image format.
# Generate video between two frames using base64 (RECOMMENDED)
# Make sure to use the correct MIME type for each image
# Example with PNG images
START_BASE64=$(base64 -i start.png)
END_BASE64=$(base64 -i end.png)
z-ai video \
--image-url "data:image/png;base64,${START_BASE64},data:image/png;base64,${END_BASE64}" \
--prompt "Smooth transition between frames" \
--poll
# Example with JPEG images
START_BASE64=$(base64 -i start.jpg)
END_BASE64=$(base64 -i end.jpg)
z-ai video \
--image-url "data:image/jpeg;base64,${START_BASE64},data:image/jpeg;base64,${END_BASE64}" \
--prompt "Smooth transition between frames" \
--poll
# Using URLs (less recommended)
z-ai video \
--image-url "https://example.com/start.png,https://example.com/end.png" \
--prompt "Smooth transition between frames" \
--poll
With Audio Generation
# Generate video with AI-generated audio effects
z-ai video \
-p "Thunder storm approaching" \
--with-audio \
--poll
Save Output
# Save task result to JSON file
z-ai video \
-p "Sunrise over mountains" \
--poll \
-o video_result.json
Custom Polling Parameters
# Customize polling behavior
z-ai video \
-p "Dancing robot" \
--poll \
--poll-interval 10 \
--max-polls 30
# Create task without polling (get task ID)
z-ai video -p "Abstract art animation" -o task.json
CLI Parameters
--prompt, -p <text>: Optional - Text description of the video--image-url, -i <data>: Optional - Preferably base64-encoded image data (e.g., "data:image/png;base64,iVBORw..."). URLs are also supported but less recommended. For two images, use comma-separated values.--quality, -q <mode>: Optional - Output mode:speedorquality(default: speed)--with-audio: Optional - Generate AI audio effects (default: false)--size, -s <resolution>: Optional - Video resolution (e.g., "1920x1080")--fps <rate>: Optional - Frame rate: 30 or 60 (default: 30)--duration, -d <seconds>: Optional - Duration: 5 or 10 seconds (default: 5)--model, -m <model>: Optional - Model name to use--poll: Optional - Auto-poll until task completes--poll-interval <seconds>: Optional - Polling interval (default: 5)--max-polls <count>: Optional - Maximum poll attempts (default: 60)--output, -o <path>: Optional - Output file path (JSON format)
Supported Resolutions
1024x1024768x1344864x11521344x7681152x8641440x720720x14401920x1080(and other standard resolutions)
Checking Task Status Later
If you create a task without --poll, you can check its status later:
# Get the task ID from the initial response
z-ai async-result --id "task-id-here" --poll
When to Use CLI vs SDK
Use CLI for:
- Quick video generation tests
- Simple one-off video creation
- Command-line automation scripts
- Testing different prompts and settings
Use SDK for:
- Batch video generation with custom logic
- Integration with web applications
- Custom task queue management
- Production applications with complex workflows
Video Generation Workflow
Video generation follows a two-step asynchronous pattern:
- Create Task: Submit video generation request and receive a task ID
- Poll Results: Query the task status until completion and retrieve the video URL
Basic Video Generation Implementation
Simple Text-to-Video Generation
import ZAI from 'z-ai-web-dev-sdk';
async function generateVideo(prompt) {
try {
const zai = await ZAI.create();
// Create video generation task
const task = await zai.video.generations.create({
prompt: prompt,
quality: 'speed', // 'speed' or 'quality'
with_audio: false,
size: '1920x1080',
fps: 30,
duration: 5
});
console.log('Task ID:', task.id);
console.log('Task Status:', task.task_status);
// Poll for results
let result = await zai.async.result.query(task.id);
let pollCount = 0;
const maxPolls = 60;
const pollInterval = 5000; // 5 seconds
while (result.task_status === 'PROCESSING' && pollCount < maxPolls) {
pollCount++;
console.log(`Polling ${pollCount}/${maxPolls}: Status is ${result.task_status}`);
await new Promise(resolve => setTimeout(resolve, pollInterval));
result = await zai.async.result.query(task.id);
}
if (result.task_status === 'SUCCESS') {
// Get video URL from multiple possible fields
const videoUrl = result.video_result?.[0]?.url ||
result.video_url ||
result.url ||
result.video;
console.log('Video URL:', videoUrl);
return videoUrl;
} else {
console.log('Task failed or still processing');
return null;
}
} catch (error) {
console.error('Video generation failed:', error.message);
throw error;
}
}
// Usage
const videoUrl = await generateVideo('A cat is playing with a ball.');
console.log('Generated video:', videoUrl);
Image-to-Video Generation
IMPORTANT: The image_url parameter accepts both base64-encoded image data and URLs, but base64 encoding is strongly recommended for better reliability and to avoid network-related issues.
Critical: Always match the MIME type in your base64 data URI to the actual image format to prevent decoding errors.
import ZAI from 'z-ai-web-dev-sdk';
import fs from 'fs';
import path from 'path';
// Helper function to detect MIME type from file extension
function getMimeType(filePath) {
const ext = path.extname(filePath).toLowerCase();
const mimeTypes = {
'.jpg': 'image/jpeg',
'.jpeg': 'image/jpeg',
'.png': 'image/png',
'.gif': 'image/gif',
'.webp': 'image/webp',
'.bmp': 'image/bmp'
};
return mimeTypes[ext] || 'image/jpeg'; // Default to JPEG if unknown
}
async function generateVideoFromImage(imagePath, prompt) {
const zai = await ZAI.create();
// Method 1: Using base64-encoded image (RECOMMENDED)
// Automatically detect MIME type from file extension
const imageBuffer = fs.readFileSync(imagePath);
const mimeType = getMimeType(imagePath);
const base64Image = `data:${mimeType};base64,${imageBuffer.toString('base64')}`;
const task = await zai.video.generations.create({
image_url: base64Image, // Base64 data string with correct MIME type
prompt: prompt,
quality: 'quality',
duration: 5,
fps: 30
});
return task;
}
// Method 2: Using URL (less recommended)
async function generateVideoFromImageUrl(imageUrl, prompt) {
const zai = await ZAI.create();
const task = await zai.video.generations.create({
image_url: imageUrl, // URL string
prompt
---
*Content truncated.*
When not to use it
- →When using client-side code
- →When the task complexity exceeds timeout limits
Prerequisites
Limitations
- →Must be used in backend code only
- →Requires polling for task completion
How it compares
It provides a programmatic backend interface for video generation rather than relying on manual creation tools.
Compared to similar skills
Video Generation side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| Video Generation (this skill) | 0 | 3mo | Review | Intermediate |
| ai-model-nodejs | 5 | 2mo | Review | Intermediate |
| add-ai-endpoint | 0 | 4mo | Review | Intermediate |
| telegram-bot-builder | 106 | 6mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
ai-model-nodejs
TencentCloudBase
Use this skill when developing Node.js backend services or CloudBase cloud functions (Express/Koa/NestJS, serverless, backend APIs) that need AI capabilities. Features text generation (generateText), streaming (streamText), AND image generation (generateImage) via @cloudbase/node-sdk ≥3.16.0. Built-in models include Hunyuan (hunyuan-2.0-instruct-20251111 recommended), DeepSeek (deepseek-v3.2 recommended), and hunyuan-image for images. This is the ONLY SDK that supports image generation. NOT for browser/Web apps (use ai-model-web) or WeChat Mini Program (use ai-model-wechat).
add-ai-endpoint
malhajri07
Scaffold a Claude API powered endpoint with system prompt, structured output, token tracking, and rate limiting. Use when adding AI features like chatbot, matching, or text generation.
telegram-bot-builder
davila7
Expert in building Telegram bots that solve real problems - from simple automation to complex AI-powered bots. Covers bot architecture, the Telegram Bot API, user experience, monetization strategies, and scaling bots to thousands of users. Use when: telegram bot, bot api, telegram automation, chat bot telegram, tg bot.
telegram-mini-app
davila7
Expert in building Telegram Mini Apps (TWA) - web apps that run inside Telegram with native-like experience. Covers the TON ecosystem, Telegram Web App API, payments, user authentication, and building viral mini apps that monetize. Use when: telegram mini app, TWA, telegram web app, TON app, mini app.
stripe-integration
wshobson
Implement Stripe payment processing for robust, PCI-compliant payment flows including checkout, subscriptions, and webhooks. Use when integrating Stripe payments, building subscription systems, or implementing secure checkout flows.
langchain-architecture
wshobson
Design LLM applications using the LangChain framework with agents, memory, and tool integration patterns. Use when building LangChain applications, implementing AI agents, or creating complex LLM workflows.