Chameleon

Environment Variables

Complete reference for all environment variables in Chameleon

Environment Variables Guide

This guide covers all environment variables used in Chameleon AI SaaS.

Required Variables

These variables are required for the application to function properly.

Database

# PostgreSQL (Vercel Postgres, Railway, Supabase, etc.)
DATABASE_URL="postgresql://user:password@host:5432/database"

# MySQL (PlanetScale, Railway, AWS RDS, etc.)
DATABASE_URL="mysql://user:password@host:3306/database"

Authentication (NextAuth v5)

# Required: Random secret for session encryption
# Generate with: openssl rand -base64 32
NEXTAUTH_SECRET="your-random-secret-key-here"
AUTH_SECRET="your-random-secret-key-here"

# Required: Base URL of your application
NEXTAUTH_URL="http://localhost:3000"  # Development
NEXTAUTH_URL="https://your-domain.com"  # Production

Base URL

# Required: Used for Stripe redirects, email links, etc.
NEXT_PUBLIC_WEB_URL="http://localhost:3000"  # Development
NEXT_PUBLIC_WEB_URL="https://your-domain.com"  # Production

Admin Access

# Required: Comma-separated list of admin emails
ADMIN_EMAILS="admin@example.com,another-admin@example.com"

Optional Variables

OAuth Providers

Google OAuth

AUTH_GOOGLE_ID="your-google-client-id.apps.googleusercontent.com"
AUTH_GOOGLE_SECRET="GOCSPX-your-google-client-secret"

Setup:

  1. Go to Google Cloud Console
  2. Create a new project or select existing
  3. Enable Google+ API
  4. Create OAuth 2.0 credentials
  5. Add authorized redirect URI: https://your-domain.com/api/auth/callback/google

GitHub OAuth

AUTH_GITHUB_ID="your-github-client-id"
AUTH_GITHUB_SECRET="your-github-client-secret"

Setup:

  1. Go to GitHub Developer Settings
  2. Create new OAuth App
  3. Set callback URL: https://your-domain.com/api/auth/callback/github

Payment (Stripe)

# Stripe API Keys
STRIPE_PRIVATE_KEY="sk_test_..."  # Test mode
STRIPE_PRIVATE_KEY="sk_live_..."  # Production

STRIPE_PUBLISHABLE_KEY="pk_test_..."  # Test mode
STRIPE_PUBLISHABLE_KEY="pk_live_..."  # Production

# Webhook Secret (from Stripe Dashboard)
STRIPE_WEBHOOK_SECRET="whsec_..."

Setup:

  1. Create account at stripe.com
  2. Get API keys from Dashboard > Developers > API keys
  3. Create webhook endpoint: https://your-domain.com/api/pay/notify/stripe
  4. Configure Price IDs in pricing files (src/i18n/pages/pricing/)

See Payment Documentation for detailed setup.

AI Providers

Critical: You must configure at least one AI provider to use AI generation features. Without AI providers, the AI Generator will not work.

These can be configured in the Admin AI Config page (/admin/ai-config) or via environment variables. Database configuration takes priority over environment variables.

OpenAI

OPENAI_API_KEY="sk-proj-..."

Features: Text generation (GPT-4, GPT-3.5), Image generation (DALL-E 3, DALL-E 2)

Get API Key: platform.openai.com/api-keys

Kling AI

KLING_ACCESS_KEY="your-kling-access-key"

Features: Image generation, Video generation

Get API Key: Kling AI Platform

Seedance (Volcengine ARK)

SEEDANCE_API_KEY="your-ark-api-key"

Features: Video generation (Seedance model)

Get API Key: Volcengine ARK Console

DeepSeek

DEEPSEEK_API_KEY="sk-..."

Features: Text generation

Get API Key: DeepSeek Platform

Replicate

REPLICATE_API_TOKEN="r8_..."

Features: Image generation (Flux Schnell, etc.)

Get API Key: replicate.com/account/api-tokens

OpenRouter

OPENROUTER_API_KEY="sk-or-..."

Features: Text generation (access to multiple models)

Get API Key: openrouter.ai/keys

SiliconFlow

SILICONFLOW_API_KEY="sk-..."

Features: Text generation

Get API Key: SiliconFlow Platform

Email (Resend)

RESEND_API_KEY="re_..."

Setup: Get API key from resend.com

Used for: Contact form, notifications, password reset emails

Analytics (OpenPanel)

NEXT_PUBLIC_OPENPANEL_CLIENT_ID="your-openpanel-client-id"
NEXT_PUBLIC_OPENPANEL_CLIENT_SECRET="your-openpanel-secret"

Setup: Create account at openpanel.dev

Used for: User analytics, page views, event tracking

Example .env.development File

# ============================================
# REQUIRED VARIABLES
# ============================================

# Database
DATABASE_URL="postgresql://user:pass@localhost:5432/chameleon"

# Authentication
NEXTAUTH_SECRET="your-random-secret-generate-with-openssl"
AUTH_SECRET="your-random-secret-generate-with-openssl"
NEXTAUTH_URL="http://localhost:3000"

# Base URL
NEXT_PUBLIC_WEB_URL="http://localhost:3000"

# Admin
ADMIN_EMAILS="admin@example.com"

# ============================================
# OPTIONAL: OAuth Providers
# ============================================

AUTH_GOOGLE_ID="xxx.apps.googleusercontent.com"
AUTH_GOOGLE_SECRET="GOCSPX-xxx"

AUTH_GITHUB_ID="xxx"
AUTH_GITHUB_SECRET="xxx"

# ============================================
# OPTIONAL: Payment
# ============================================

STRIPE_PRIVATE_KEY="sk_test_xxx"
STRIPE_PUBLISHABLE_KEY="pk_test_xxx"
STRIPE_WEBHOOK_SECRET="whsec_xxx"

# ============================================
# OPTIONAL: AI Providers
# ============================================

OPENAI_API_KEY="sk-proj-xxx"
KLING_ACCESS_KEY="xxx"
SEEDANCE_API_KEY="xxx"
DEEPSEEK_API_KEY="sk-xxx"
REPLICATE_API_TOKEN="r8_xxx"
OPENROUTER_API_KEY="sk-or-xxx"
SILICONFLOW_API_KEY="sk-xxx"

# ============================================
# OPTIONAL: Email & Analytics
# ============================================

RESEND_API_KEY="re_xxx"
NEXT_PUBLIC_OPENPANEL_CLIENT_ID="xxx"
NEXT_PUBLIC_OPENPANEL_CLIENT_SECRET="xxx"

Vercel Deployment Variables

When deploying to Vercel, you'll need to add these in the Vercel dashboard:

  1. Go to your project settings
  2. Navigate to Environment Variables
  3. Add each variable for:
    • Production
    • Preview (optional)
    • Development (optional)

Important: Never commit .env files to Git! They are already in .gitignore.

Environment Variable Priority

Chameleon uses the following priority for configuration:

  1. Database (Admin AI Config) - AI provider keys stored in database via /admin/ai-config
  2. Environment Variables - .env.development, .env.local, or Vercel
  3. Defaults - Hardcoded fallback values

Important: For AI providers, the Admin System configuration takes priority. Even if you have API keys in environment variables, you must configure them in /admin/ai-config for the AI Generator to work.

Validation

To verify your environment variables are set correctly:

# Check if all required vars are present
node check-env.js

Or check the console output when starting the dev server:

pnpm dev

# Should see:
# ✓ Database connected: PostgreSQL
# ✓ NextAuth configured
# ✓ Admin emails: 1 configured

Security Best Practices

  1. Never expose secrets in client-side code

    • Only use NEXT_PUBLIC_* prefix for non-sensitive data
  2. Rotate keys regularly

    • Change API keys every 90 days
    • Update NEXTAUTH_SECRET periodically
  3. Use different keys for test and production

    • Stripe: Use test keys in development
    • AI providers: Use separate accounts if possible
  4. Restrict API key permissions

    • Use read-only keys where possible
    • Set IP restrictions if available

Troubleshooting

Variable not found

# Restart dev server after changing .env
pnpm dev

Variable has spaces

Make sure there are no spaces around =:

# ❌ Wrong
DATABASE_URL = "postgresql://..."

# ✅ Correct
DATABASE_URL="postgresql://..."

Variable not working in Vercel

  1. Check the variable name (case-sensitive)
  2. Redeploy after adding variables
  3. Check if the variable is selected for the right environment

Next Steps