Overview
AI Studio uses environment variables to configure database connections, authentication, AI services, and third-party integrations. This guide documents all required and optional environment variables.Setup Process
Fill in your values
Update each variable with your actual credentials. See sections below for where to obtain each value.
Required Variables
These variables must be configured for AI Studio to function properly.Database (Supabase)
- Go to Supabase Dashboard
- Select your project → Settings → Database
- Copy the Transaction pooler connection string (port 6543)
- Use the Transaction mode connection string for serverless compatibility
AI Studio uses Supabase Transaction pooler (port 6543) with
prepare: false for compatibility with serverless functions. See lib/db/index.ts:5-6.Supabase Storage & Authentication
- Supabase Dashboard → Settings → API
- Project URL: Copy the URL from “Configuration”
- Secret Key: Copy the
service_rolekey under “Project API keys”
Authentication (Better Auth)
- Used for signing authentication tokens
- Must be at least 32 characters long
- Generate securely:
- Base URL where your application runs
- Local:
http://localhost:3000 - Production:
https://yourdomain.com(no trailing slash)
- Public URL of your application
- Used for redirects, emails, and OAuth callbacks
- Must match your actual domain
AI Services (Fal.ai)
- Sign up at fal.ai
- Go to Dashboard → API Keys
- Create a new API key
- AI-powered image generation and editing
- Real estate photo enhancement
- Style template applications
Email (Resend)
- Sign up at resend.com
- Go to API Keys
- Create a new API key
- Team member invitation emails
- Password reset emails
- Notification emails
- Transaction confirmations
Background Jobs (Trigger.dev)
- Sign up at cloud.trigger.dev
- Create a new project
- Go to Settings → API Keys
- Copy your DEV secret key (starts with
tr_dev_)
For local development, use the DEV key (
tr_dev_). For production deployments, use the PROD key (tr_prod_).- AI image generation tasks (background processing)
- Long-running workflows
- Scheduled jobs
- Webhook processing
pnpm trigger in a separate terminal for background jobs to process locally.
Optional Variables
These variables enable additional features but are not required for basic functionality.Accounting Integration (Fiken)
- Norwegian cloud-based accounting system integration
- Automated invoicing
- Financial reporting
- Sign up at fiken.no
- Go to Settings → API
- Generate an API key
- Find your company slug in your Fiken URL
Fiken integration is specifically designed for Norwegian businesses and is completely optional.
Environment-Specific Configuration
Local Development
.env.local
Production (Vercel)
Vercel Environment Variables
Variable Reference
Complete alphabetical reference of all environment variables:| Variable | Required | Description | Example |
|---|---|---|---|
BETTER_AUTH_SECRET | Yes | Secret key for signing auth tokens (32+ chars) | openssl rand -base64 32 |
BETTER_AUTH_URL | Yes | Base URL where app runs | http://localhost:3000 |
DATABASE_URL | Yes | PostgreSQL connection string (Transaction pooler) | postgresql://user:pass@host:6543/db |
FAL_API_KEY | Yes | Fal.ai API key for AI image processing | fal_xxxxxxxx |
FIKEN_API_KEY | No | Fiken accounting API key (Norwegian) | fik_xxxxxxxx |
FIKEN_COMPANY_SLUG | No | Company identifier in Fiken | my-company |
NEXT_PUBLIC_APP_URL | Yes | Public URL (for redirects, emails) | https://yourdomain.com |
NEXT_PUBLIC_SUPABASE_URL | Yes | Supabase project URL | https://xxx.supabase.co |
RESEND_API_KEY | Yes | Resend API key for email delivery | re_xxxxxxxx |
SUPABASE_SECRET_KEY | Yes | Supabase service role key (server-only) | sb_secret_xxxxx |
TRIGGER_SECRET_KEY | Yes | Trigger.dev secret key (dev or prod) | tr_dev_xxxxxxxx |
Security Best Practices
Never commit secrets to Git
Never commit secrets to Git
.env.localis already in.gitignore- Use
.env.exampleas a template (without real values) - Review commits before pushing to ensure no secrets leaked
Use different keys per environment
Use different keys per environment
- Separate API keys for development and production
- Rotate keys regularly (every 90 days recommended)
- Revoke old keys after rotation
Restrict API key permissions
Restrict API key permissions
- Use read-only keys where possible
- Limit IP addresses (when supported)
- Set spending limits on paid APIs
Public vs Private variables
Public vs Private variables
NEXT_PUBLIC_*variables are exposed to the browser- Never prefix secrets with
NEXT_PUBLIC_ - Server-only variables (like
SUPABASE_SECRET_KEY) are safe
Troubleshooting
Variables Not Loading
- Next.js Development
- Vercel Deployment
- Trigger.dev
- Restart the dev server:
pnpm dev - Verify file name is exactly
.env.local - Check variables are in the root directory
- Ensure no syntax errors (no quotes needed)
Common Errors
Error: “DATABASE_URL is not defined”- Verify
.env.localexists in root directory - Check spelling:
DATABASE_URL(notDATABASE_URI) - Restart dev server after adding variable
- Use Transaction pooler URL (port 6543, not 5432)
- Verify password doesn’t contain special characters that need URL encoding
- Check project isn’t paused in Supabase dashboard
- Generate a new secret:
openssl rand -base64 32 - Ensure no extra spaces or line breaks in
.env.local
- Use
tr_dev_key for local development - Use
tr_prod_key for production deployments - Verify key is active in Trigger.dev dashboard
Next Steps
Database Setup
Configure PostgreSQL and run migrations with Drizzle ORM
Deployment
Deploy AI Studio to Vercel with proper environment configuration