Overview
Supabase provides two critical services for AI Studio:- PostgreSQL Database - Stores all application data (users, workspaces, projects, etc.)
- Storage - Hosts original images, processed results, and generated videos
Configuration
Environment Variables
Add the following to your.env.local file:
Setup Steps
Create Supabase Project
- Sign up at supabase.com
- Create a new project
- Wait for the database to provision (usually 2-3 minutes)
Get Database URL
- Go to Settings → Database
- Under “Connection string”, select Transaction mode
- Copy the connection string (use the pooler for serverless)
- Replace
[YOUR-PASSWORD]with your database password - Set as
DATABASE_URLin your.env.local
Get API Keys
- Go to Settings → API
- Copy the Project URL →
NEXT_PUBLIC_SUPABASE_URL - Copy the service_role secret key →
SUPABASE_SECRET_KEY
Create Storage Bucket
- Go to Storage in your Supabase dashboard
- Create a new bucket named
aistudio-bucket - Set it to Public (for serving images/videos)
- Configure CORS if needed for client uploads
Database Client
The database is accessed via Drizzle ORM. Supabase is only used for storage operations.Server-Side Client
For storage operations, use the admin client inlib/supabase.ts:
lib/supabase.ts
Storage Functions
Upload Image
Upload images to organized paths:Upload Video
Upload generated videos:Delete Images
Delete individual or project images:Get Public URL
Get public URL for a stored file:Create Signed Upload URL
For client-side direct uploads:Storage Organization
Files are organized with the following structure:Helper Functions
Path Generators
Content Type Helpers
Usage in Workflows
Image Processing Task
Fromtrigger/process-image.ts:
Video Generation Task
Fromtrigger/generate-video-clip.ts:
Error Handling
All storage functions throw errors on failure:Storage Limits
Supabase free tier includes:- 500 MB storage
- 2 GB bandwidth per month
- 50 MB max file upload size
- 100 GB storage
- 200 GB bandwidth
- 5 GB max file upload size