Basic Render Examples
Get started with these simple examples showing how to generate different types of content using GigaReels.Educational Brainrot Video
Generate an educational video with character dialogues:import { GigaReels } from "@gigareels/sdk";
const client = new GigaReels("your-api-key");
async function generateEducationalVideo() {
try {
const task = await client.templates.brainrot.educational({
prompt: "Explain how photosynthesis works in plants and why it's important for life on Earth",
characterPack: "rick-and-morty",
backgroundVideoPack: "minecraft-parkour",
enableGifs: true,
webhookUrl: "https://your-app.com/webhook", // Optional
});
console.log("✅ Video generation started!");
console.log("Task ID:", task.taskId);
console.log("Status:", task.status);
if (task.outputUrl) {
console.log("🎬 Video URL:", task.outputUrl);
}
return task;
} catch (error) {
console.error("❌ Error generating video:", error.message);
throw error;
}
}
generateEducationalVideo();
Breaking News Video
Create a viral news-style video:async function generateBreakingNews() {
const task = await client.templates.brainrot.newsFish({
searchTerm: "Scientists discover plants can actually hear music and prefer jazz!",
webhookUrl: "https://your-app.com/webhook",
});
console.log("📺 Breaking news video started:", task.taskId);
return task;
}
Text Message Conversation
Generate an iPhone-style conversation video:async function generateTextConversation() {
const task = await client.templates.brainrot.iMessage({
prompt:
"Create a funny conversation between two roommates where one discovers the other has been using their Netflix account to watch nothing but cooking shows",
characterPack: "family-guy",
backgroundVideoPack: "subway-surfers",
enableImages: true,
});
console.log("💬 Text conversation video started:", task.taskId);
return task;
}
Transform Existing Video
Modify an existing video to bypass duplicate detection:async function transformVideo() {
const task = await client.templates.utilities.transform({
videoUrl: "https://your-bucket.com/original-video.mp4",
enableDistortionBar: true,
audioPitchDistortion: 0.15,
framesToKill: 25,
});
console.log("🎭 Video transformation started:", task.taskId);
return task;
}
Complete Workflow with Error Handling
Here’s a more complete example with proper error handling:import { GigaReels, ValidationError } from "@gigareels/sdk";
class VideoGenerator {
constructor(apiKey) {
this.client = new GigaReels(apiKey);
}
async generateWithRetry(renderFunction, maxRetries = 3) {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
return await renderFunction();
} catch (error) {
console.log(`Attempt ${attempt} failed:`, error.message);
if (error instanceof ValidationError) {
// Don't retry validation errors
throw error;
}
if (attempt === maxRetries) {
throw error;
}
// Wait before retrying
await new Promise(resolve => setTimeout(resolve, 2000 * attempt));
}
}
}
async generateEducationalContent(topic) {
return this.generateWithRetry(async () => {
return await this.client.templates.brainrot.educational({
prompt: `Explain ${topic} in an engaging way for a young audience. Make it educational but fun.`,
characterPack: "rick-and-morty",
backgroundVideoPack: "minecraft-parkour",
enableGifs: true,
});
});
}
async generateNews(headline) {
return this.generateWithRetry(async () => {
return await this.client.templates.brainrot.newsFish({
searchTerm: headline,
});
});
}
async checkTaskStatus(taskId) {
try {
const status = await this.client.getTaskStatus(taskId);
return status;
} catch (error) {
console.error("Error checking task status:", error.message);
throw error;
}
}
}
// Usage example
async function main() {
const generator = new VideoGenerator(process.env.GIGAREELS_API_KEY);
try {
// Generate educational content
console.log("🎬 Generating educational video...");
const educationalTask = await generator.generateEducationalContent("quantum physics");
console.log("✅ Educational video:", educationalTask.taskId);
// Generate breaking news
console.log("📺 Generating news video...");
const newsTask = await generator.generateNews("AI robots learn to make perfect pizza!");
console.log("✅ News video:", newsTask.taskId);
// Check status after some time
setTimeout(async () => {
const educationalStatus = await generator.checkTaskStatus(educationalTask.taskId);
console.log("📊 Educational video status:", educationalStatus.status);
if (educationalStatus.outputUrl) {
console.log("🎉 Educational video completed:", educationalStatus.outputUrl);
}
}, 60000); // Check after 1 minute
} catch (error) {
if (error instanceof ValidationError) {
console.error("❌ Validation Error:");
error.issues.forEach(issue => {
console.error(` - ${issue.path.join(".")}: ${issue.message}`);
});
} else {
console.error("❌ Unexpected Error:", error.message);
}
}
}
main();
Batch Generation
Generate multiple videos in parallel:async function generateBatch() {
const client = new GigaReels(process.env.GIGAREELS_API_KEY);
const topics = [
"How do black holes work?",
"Why do we dream when we sleep?",
"What makes music sound good?",
"How do vaccines protect us?",
];
try {
// Start all generations in parallel
const tasks = await Promise.all(
topics.map(topic =>
client.templates.brainrot.educational({
prompt: topic,
characterPack: "rick-and-morty",
backgroundVideoPack: "minecraft-parkour",
enableGifs: true,
webhookUrl: "https://your-app.com/webhook",
})
)
);
console.log("🚀 Started", tasks.length, "video generations:");
tasks.forEach((task, index) => {
console.log(` ${index + 1}. ${topics[index]} -> ${task.taskId}`);
});
return tasks;
} catch (error) {
console.error("❌ Batch generation failed:", error.message);
throw error;
}
}
generateBatch();
Environment-Specific Configuration
Set up different configurations for different environments:class EnvironmentConfig {
static getConfig() {
const env = process.env.NODE_ENV || "development";
const configs = {
development: {
apiKey: process.env.GIGAREELS_DEV_API_KEY,
baseUrl: "http://localhost:3000",
webhookUrl: "http://localhost:3001/webhook",
},
staging: {
apiKey: process.env.GIGAREELS_STAGING_API_KEY,
baseUrl: "https://staging-api.gigareels.com",
webhookUrl: "https://staging.yourapp.com/webhook",
},
production: {
apiKey: process.env.GIGAREELS_API_KEY,
baseUrl: "https://gigareels.com",
webhookUrl: "https://yourapp.com/webhook",
},
};
return configs[env] || configs.development;
}
static createClient() {
const config = this.getConfig();
return new GigaReels({
apiKey: config.apiKey,
baseUrl: config.baseUrl,
});
}
}
// Usage
const client = EnvironmentConfig.createClient();
const config = EnvironmentConfig.getConfig();
const task = await client.templates.brainrot.educational({
prompt: "Explain renewable energy",
characterPack: "rick-and-morty",
backgroundVideoPack: "minecraft-parkour",
webhookUrl: config.webhookUrl,
});
Next Steps
Batch Rendering
Learn how to generate multiple videos efficiently
Social Media Integration
Automatically upload generated content to social platforms
Webhook Handling
Set up webhooks for async video processing
Advanced Templates
Explore all available render types and customization options
Pro Tip: Always use webhooks in production to avoid blocking your application while videos are
being generated. Video generation typically takes 2-5 minutes.