Environment Variables
Complete reference for configuring Earna AI Console through environment variables.
Required Variables
These variables must be set for the application to function:
Variable | Description | Example |
---|---|---|
NEXT_PUBLIC_SUPABASE_URL | Supabase project URL | https://xxx.supabase.co |
NEXT_PUBLIC_SUPABASE_ANON_KEY | Supabase anonymous key | eyJ... (long JWT) |
SUPABASE_SERVICE_ROLE | Supabase service role key | eyJ... (long JWT) |
OPENAI_API_KEY | OpenAI API key for GPT-4o | sk-... |
CSRF_SECRET | CSRF protection secret (32 chars) | Random 32 character string |
Security Note: Never commit environment variables to Git. Use .env.local
for development and configure production values in your deployment platform.
AI Provider Variables
OpenAI (Primary)
# Required for GPT-4o (primary model)
OPENAI_API_KEY=sk-...
# Optional: Custom endpoint
OPENAI_BASE_URL=https://api.openai.com/v1
# Optional: Organization ID
OPENAI_ORG_ID=org-...
Anthropic (Claude)
# Optional: For Claude 3 Opus/Sonnet
ANTHROPIC_API_KEY=sk-ant-api03-...
# Optional: Custom endpoint
ANTHROPIC_BASE_URL=https://api.anthropic.com
Google AI (Gemini)
# Optional: For Gemini Pro/Flash
GOOGLE_GENERATIVE_AI_API_KEY=AIzaSy...
Additional Providers
Provider | Variable | Models |
---|---|---|
Mistral | MISTRAL_API_KEY | Mistral Large, Medium, Small |
xAI | XAI_API_KEY | Grok-1, Grok-2 |
Perplexity | PERPLEXITY_API_KEY | pplx-7b-online, pplx-70b-online |
Local Models
# Ollama (local models)
OLLAMA_BASE_URL=http://localhost:11434
# OpenRouter (proxy for multiple models)
OPENROUTER_API_KEY=sk-or-...
Feature-Specific Variables
HeyGen Avatars
# Required for interactive avatars
HEYGEN_API_KEY=...
# Optional: API URL
NEXT_PUBLIC_HEYGEN_API_URL=https://api.heygen.com
Voice Features
# Required for voice features (uses OpenAI)
NEXT_PUBLIC_OPENAI_API_KEY=sk-proj-...
# Optional: Voice settings
OPENAI_TTS_MODEL=tts-1-hd
OPENAI_TTS_VOICE=alloy
OPENAI_REALTIME_MODEL=gpt-4o-realtime-preview
File Upload
# Optional: Maximum file size (default: 10MB)
MAX_FILE_SIZE=10485760
# Optional: Allowed file types
ALLOWED_FILE_TYPES=.pdf,.txt,.docx,.png,.jpg,.jpeg
Monitoring & Analytics
Error Tracking
# Optional: Sentry for error tracking
SENTRY_DSN=https://...@sentry.io/...
SENTRY_ORG=your-org
SENTRY_PROJECT=earna-ai-console
# Optional: Environment name
SENTRY_ENVIRONMENT=production
Product Analytics
# Optional: PostHog for analytics
NEXT_PUBLIC_POSTHOG_KEY=phc_...
NEXT_PUBLIC_POSTHOG_HOST=https://app.posthog.com
# Optional: Mixpanel
NEXT_PUBLIC_MIXPANEL_TOKEN=...
# Optional: Google Analytics
NEXT_PUBLIC_GA_MEASUREMENT_ID=G-...
Security Variables
Encryption
# Required: For encrypting sensitive data
ENCRYPTION_KEY=... # 32-byte hex string
# Generate with: openssl rand -hex 32
Authentication
# Required for NextAuth.js
NEXTAUTH_SECRET=... # Random string
NEXTAUTH_URL=https://your-domain.com
# Optional: JWT settings
JWT_SECRET=... # Custom JWT secret
JWT_EXPIRATION=7d
Rate Limiting
# Optional: Redis for rate limiting
UPSTASH_REDIS_REST_URL=https://...
UPSTASH_REDIS_REST_TOKEN=...
# Optional: Rate limit settings
RATE_LIMIT_REQUESTS=100
RATE_LIMIT_WINDOW=900 # 15 minutes in seconds
Database Variables
Supabase (Primary)
# Public (client-side)
NEXT_PUBLIC_SUPABASE_URL=https://xxx.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJ...
# Private (server-side)
SUPABASE_SERVICE_ROLE=eyJ...
SUPABASE_JWT_SECRET=...
# Optional: Custom schema
SUPABASE_SCHEMA=public
Direct PostgreSQL (Alternative)
# If using direct PostgreSQL connection
DATABASE_URL=postgresql://user:pass@host:5432/dbname
DATABASE_POOL_SIZE=20
DATABASE_SSL=true
Deployment Variables
Vercel
# Set automatically by Vercel
VERCEL=1
VERCEL_URL=your-app.vercel.app
VERCEL_GIT_COMMIT_SHA=...
# Optional: Custom domain
NEXT_PUBLIC_APP_URL=https://console.earna.ai
Custom Deployment
# Node.js settings
NODE_ENV=production
PORT=3000
# Health check endpoint
HEALTH_CHECK_PATH=/api/health
# Logging level
LOG_LEVEL=info
Development Variables
Local Development
# Development settings
NODE_ENV=development
NEXT_PUBLIC_APP_ENV=development
# Debug modes
DEBUG=true
VERBOSE_LOGGING=true
# Hot reload settings
FAST_REFRESH=true
Testing
# Test database
TEST_DATABASE_URL=postgresql://...
TEST_SUPABASE_URL=...
# Mock API keys for testing
MOCK_OPENAI_RESPONSES=true
TEST_API_KEY=test-key-123
Variable Validation
The application validates required environment variables on startup:
// lib/env.ts
const requiredEnvVars = [
'NEXT_PUBLIC_SUPABASE_URL',
'NEXT_PUBLIC_SUPABASE_ANON_KEY',
'SUPABASE_SERVICE_ROLE',
'CSRF_SECRET'
];
export function validateEnv() {
const missing = requiredEnvVars.filter(
name => !process.env[name]
);
if (missing.length > 0) {
throw new Error(`Missing required environment variables: ${missing.join(', ')}`);
}
}
Environment File Examples
.env.example
(Template)
# ================================
# REQUIRED VARIABLES
# ================================
# Supabase Configuration
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
# OpenAI (Required for GPT-4o)
OPENAI_API_KEY=sk-proj-your-key
# ================================
# OPTIONAL AI PROVIDERS
# ================================
# Anthropic (for Claude models)
ANTHROPIC_API_KEY=sk-ant-api03-your-key
# Google AI (for Gemini models)
GOOGLE_AI_API_KEY=AIzaSy-your-key
# Other providers
MISTRAL_API_KEY=your-key
XAI_API_KEY=your-key
PERPLEXITY_API_KEY=pplx-your-key
# ================================
# OPTIONAL FEATURES
# ================================
# HeyGen Avatars
HEYGEN_API_KEY=your-key
# Monitoring
SENTRY_DSN=https://your-dsn@sentry.io/project
NEXT_PUBLIC_POSTHOG_KEY=phc_your-key
# Security
ENCRYPTION_KEY=your-32-byte-hex-key
NEXTAUTH_SECRET=your-secret
.env.local
(Development)
# Copy from .env.example and fill in real values
NEXT_PUBLIC_SUPABASE_URL=https://abcdefgh.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
OPENAI_API_KEY=sk-proj-real-key-here
# Development-specific
NODE_ENV=development
DEBUG=true
Best Practices
Security
- Never commit secrets to version control
- Use different keys for development/production
- Rotate keys regularly (quarterly recommended)
- Use service-specific keys where possible
- Monitor key usage for anomalies
Organization
- Group related variables with comments
- Use consistent naming (SCREAMING_SNAKE_CASE)
- Document each variable in .env.example
- Validate on startup to catch missing vars early
- Use defaults where appropriate
Performance
- Minimize client-side vars (
NEXT_PUBLIC_*
) - Cache expensive lookups
- Use connection pooling for databases
- Set appropriate timeouts
Need Help? Check the Setup Guide for step-by-step configuration, or see Troubleshooting for common issues.
Last updated on