ai-video-gen
AI video generation with Replicate and fal.ai — text-to-video, image-to-video with multiple model support. Use this skill when the user says "add video generation", "setup ai video", "text to video", "image to video", or "ai video gen".
What this skill does
# AI Video Generation
Multi-provider AI video generation using [Replicate](https://replicate.com) and [fal.ai](https://fal.ai). Supports text-to-video and image-to-video with models like Minimax, Kling, and Luma. Videos are stored permanently via the `storage` skill.
## Prerequisites
- Next.js app with App Router (with `src/` directory)
- `db` skill applied (Drizzle + Postgres)
- `env-config` skill applied
- `auth` skill applied
- `storage` skill applied (for permanent video storage)
- `replicate` and `@fal-ai/client` packages installed (from `ai-image-gen` or install separately)
## Installation
```bash
bun add replicate @fal-ai/client
```
## Environment Variables
Same as `ai-image-gen` — add to `.env.local` if not already present:
```env
REPLICATE_API_TOKEN=r8_...
FAL_KEY=fal_...
```
> **Note:** `REPLICATE_API_TOKEN` and `FAL_KEY` are owned by the `ai-image-gen` skill (applied first in Layer 2). If `ai-image-gen` is already applied, these are already set — no need to configure them again.
If keys are missing, use the `/env-from-1password` skill to load them from 1Password.
## What Gets Created
```
app/
└── api/
└── ai/
└── videos/
├── route.ts # POST generate, GET list generations
└── [id]/
└── route.ts # GET status/result, DELETE
lib/
└── ai/
└── video-gen/
├── types.ts # VideoGenRequest, VideoGenResult, VideoModelConfig
├── models.ts # Video model registry
├── providers/
│ ├── replicate.ts # Replicate video prediction
│ └── fal.ts # fal.ai video queue
└── generate.ts # Unified video generation
db/
└── schema/
└── video-generations.ts # Drizzle schema: video_generations table
```
## Setup Steps
### Step 1: Create `db/schema/video-generations.ts`
```typescript
import { pgTable, text, integer, timestamp, jsonb, uuid } from "drizzle-orm/pg-core";
export const videoGenerations = pgTable("video_generations", {
id: uuid("id").primaryKey().defaultRandom(),
userId: text("user_id").notNull(),
type: text("type", {
enum: ["text-to-video", "image-to-video"],
}).notNull(),
status: text("status", {
enum: ["pending", "processing", "completed", "failed"],
}).notNull().default("pending"),
provider: text("provider").notNull(),
model: text("model").notNull(),
prompt: text("prompt").notNull(),
inputImageUrl: text("input_image_url"),
duration: integer("duration"),
width: integer("width").default(1280),
height: integer("height").default(720),
resultUrl: text("result_url"),
thumbnailUrl: text("thumbnail_url"),
providerJobId: text("provider_job_id"),
metadata: jsonb("metadata"),
error: text("error"),
createdAt: timestamp("created_at").defaultNow().notNull(),
completedAt: timestamp("completed_at"),
});
export type VideoGeneration = typeof videoGenerations.$inferSelect;
export type NewVideoGeneration = typeof videoGenerations.$inferInsert;
```
### Step 2: Add export to `db/schema/index.ts`
```typescript
export * from "./video-generations";
```
### Step 3: Create `lib/ai/video-gen/types.ts`
```typescript
export type VideoProvider = "replicate" | "fal";
export type VideoGenRequest = {
prompt: string;
model?: string;
inputImageUrl?: string;
duration?: number;
width?: number;
height?: number;
seed?: number;
};
export type VideoGenResult = {
url: string;
duration: number;
width: number;
height: number;
provider: VideoProvider;
model: string;
providerJobId: string;
};
export type VideoModelConfig = {
provider: VideoProvider;
modelId: string;
name: string;
description: string;
maxDuration: number;
defaults: {
width: number;
height: number;
duration: number;
};
capabilities: ("text-to-video" | "image-to-video")[];
};
```
### Step 4: Create `lib/ai/video-gen/models.ts`
```typescript
import type { VideoModelConfig } from "./types";
export const VIDEO_MODELS: Record<string, VideoModelConfig> = {
"minimax-video": {
provider: "replicate",
modelId: "minimax/video-01",
name: "Minimax Video-01",
description: "Fast, high quality video generation",
maxDuration: 6,
defaults: { width: 1280, height: 720, duration: 5 },
capabilities: ["text-to-video", "image-to-video"],
},
"luma-dream-machine": {
provider: "fal",
modelId: "fal-ai/luma-dream-machine",
name: "Luma Dream Machine",
description: "Cinematic quality, longer videos",
maxDuration: 10,
defaults: { width: 1280, height: 720, duration: 5 },
capabilities: ["text-to-video", "image-to-video"],
},
"kling-video": {
provider: "fal",
modelId: "fal-ai/kling-video/v1.5/pro",
name: "Kling Video v1.5",
description: "Professional quality, good motion",
maxDuration: 10,
defaults: { width: 1280, height: 720, duration: 5 },
capabilities: ["text-to-video", "image-to-video"],
},
};
export const DEFAULT_VIDEO_MODEL = "minimax-video";
export function getVideoModelConfig(modelName?: string): VideoModelConfig {
const name = modelName ?? DEFAULT_VIDEO_MODEL;
const config = VIDEO_MODELS[name];
if (!config) {
throw new Error(
`Unknown video model: ${name}. Available: ${Object.keys(VIDEO_MODELS).join(", ")}`
);
}
return config;
}
```
### Step 5: Create `lib/ai/video-gen/providers/replicate.ts`
```typescript
import Replicate from "replicate";
const replicate = new Replicate();
export async function generateVideoWithReplicate(params: {
modelId: string;
prompt: string;
inputImageUrl?: string;
duration?: number;
width?: number;
height?: number;
}): Promise<{ url: string; predictionId: string }> {
const input: Record<string, unknown> = {
prompt: params.prompt,
};
if (params.inputImageUrl) input.first_frame_image = params.inputImageUrl;
if (params.duration) input.duration = params.duration;
const prediction = await replicate.predictions.create({
model: params.modelId as `${string}/${string}`,
input,
});
// Poll for completion — video generation can take 30s-5min
let result = prediction;
const maxWait = 5 * 60 * 1000; // 5 minutes
const start = Date.now();
while (result.status !== "succeeded" && result.status !== "failed") {
if (Date.now() - start > maxWait) {
throw new Error("Video generation timed out after 5 minutes");
}
await new Promise((resolve) => setTimeout(resolve, 3000));
result = await replicate.predictions.get(prediction.id);
}
if (result.status === "failed") {
throw new Error(`Replicate prediction failed: ${result.error}`);
}
const output = result.output;
const url = typeof output === "string" ? output : Array.isArray(output) ? String(output[0]) : String(output);
return { url, predictionId: prediction.id };
}
```
### Step 6: Create `lib/ai/video-gen/providers/fal.ts`
```typescript
import { fal } from "@fal-ai/client";
export async function generateVideoWithFal(params: {
modelId: string;
prompt: string;
inputImageUrl?: string;
duration?: number;
width?: number;
height?: number;
}): Promise<{ url: string; requestId: string }> {
const input: Record<string, unknown> = {
prompt: params.prompt,
};
if (params.inputImageUrl) input.image_url = params.inputImageUrl;
if (params.duration) input.duration = params.duration;
const result = await fal.subscribe(params.modelId, {
input,
pollInterval: 3000,
});
type FalVideo = { url: string };
const data = result.data as { video?: FalVideo };
const url = data.video?.url;
if (!url) {
throw new Error("No video URL in fal.ai response");
}
return { url, requestId: result.requestId };
}
```
### Step 7: Create `lib/ai/video-gen/generate.ts`
```typescript
import { getVideoModelConfig } from "./models";
import { generateVideoWithReplicate } from "./providers/replicate";
import { generateVideoWithFal } fromRelated in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.