Overview
Trigger.dev handles all long-running AI processing tasks in AI Studio. It provides:- Reliable background job execution
- Automatic retries with exponential backoff
- Real-time progress tracking
- Queue management for AI API calls
Configuration
Environment Variables
Add the following to your.env.local file:
Setup Steps
Create Trigger.dev Account
- Sign up at cloud.trigger.dev
- Create a new project
- Select the v3 version (latest)
Get Secret Key
- Go to your project in the Trigger.dev dashboard
- Navigate to Settings → API Keys
- Copy the Secret Key (starts with
tr_dev_for development) - Add to
.env.localasTRIGGER_SECRET_KEY
Configure Project
The configuration is in Update the
trigger.config.ts:trigger.config.ts
project ID with your own project ID from the dashboard.Available Tasks
AI Studio includes 6 background tasks in thetrigger/ directory:
Image Processing
Task:process-imageFile:
trigger/process-image.tsPurpose: Process images with Fal.ai Nano Banana Pro
Inpainting
Task:inpaint-imageFile:
trigger/inpaint-image.tsPurpose: Selective editing with Qwen Inpaint model
Video Generation
Task:generate-video-clipFile:
trigger/generate-video-clip.tsPurpose: Generate video clips from images with Kling Video Task:
generate-transition-clipFile:
trigger/generate-transition-clip.tsPurpose: Create transition clips between rooms Task:
compile-videoFile:
trigger/compile-video.tsPurpose: Compile clips into final video Task:
video-orchestratorFile:
trigger/video-orchestrator.tsPurpose: Orchestrate the complete video generation pipeline
Task Structure
All tasks follow a consistent pattern:Example: Image Processing Task
Fromtrigger/process-image.ts:
Triggering Tasks
From API Routes
Trigger tasks from Next.js API routes:app/api/process-image/route.ts
From Server Actions
Trigger tasks from server actions:lib/actions/process-image.ts
Progress Tracking
Setting Metadata
Update task progress for UI display:Reading Metadata
Poll for task status:Logging
Use structured logging:Retry Configuration
Task-Level Retries
Global Retries
Set intrigger.config.ts:
Deployment
Deploy to Trigger.dev Cloud
Environment Variables
Set production environment variables in the Trigger.dev dashboard:- Go to Settings → Environment Variables
- Add all required variables:
FAL_API_KEYDATABASE_URLSUPABASE_SECRET_KEYNEXT_PUBLIC_SUPABASE_URL
Monitoring
Dashboard
View task runs in the Trigger.dev dashboard:- Real-time run status
- Execution logs
- Error stack traces
- Performance metrics
Alerts
Configure alerts for:- Task failures
- Long execution times
- High retry rates