Skip to content

Environment Variables

Varity Team Core Contributors Updated May 2026

Varity manages most credentials automatically. You only need to set environment variables for services you manage yourself, like your own API keys for OpenAI, Stripe, SendGrid, and similar third-party services.

If your app uses third-party APIs (OpenAI, Stripe, SendGrid, Resend, or any other service), you need to inject those API keys into your deployment. Varity reads them from a .env file during varitykit app deploy and passes them through to your running app.

Create .env.varity in your project root with your custom keys:

.env.varity
# Third-party API keys
OPENAI_API_KEY=sk-...
STRIPE_SECRET_KEY=sk_live_...
RESEND_API_KEY=re_...
SENDGRID_API_KEY=SG....
MY_CUSTOM_VAR=some-value
Terminal window
varitykit app deploy

The CLI reads your .env.varity file, filters out any reserved or platform-specific keys, and injects the rest directly into your deployment’s runtime environment. Your app code accesses them the same way as any environment variable:

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);

When multiple .env files are present, Varity reads the first match (highest precedence wins):

FileWhen to use
.env.varityVarity production secrets (overrides all others)
.env.localLocal overrides / Next.js convention
.envFallback for all environments

Any key that is a valid shell variable name and is not reserved by Varity passes through automatically, including NEXT_PUBLIC_* variables.

Keys that are not forwarded (Varity sets these automatically):

KeySet by
NODE_ENV, PORT, NODE_OPTIONSRuntime defaults
DATABASE_URL, REDIS_URL, MONGODB_URI, OLLAMA_URLVarity service wiring
POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DBManaged database config
APP_NAMEDeployment metadata

Platform migration keys (VERCEL_*, AWS_*, RAILWAY_*, RENDER_*, NETLIFY_*, FLY_*) are also filtered so they don’t leak into dynamic deployments.


.env.local
# Your Varity App ID (from developer portal)
NEXT_PUBLIC_VARITY_APP_ID=your-app-id

These variables are only needed for specific use cases:

VariableRequired ForDefault
NEXT_PUBLIC_VARITY_APP_IDApp identityDev default
VARITY_API_URLCustom API endpointhttps://varity.app
VARITY_API_KEYAPI authenticationAuto-provided
.env.local
# Varity app ID (optional, dev defaults work automatically)
NEXT_PUBLIC_VARITY_APP_ID=your-app-id

In development, your app uses shared credentials automatically. No other variables are needed.

Different frameworks require different prefixes for client-side variables:

FrameworkPrefixExample
Next.jsNEXT_PUBLIC_NEXT_PUBLIC_VARITY_APP_ID
ViteVITE_VITE_VARITY_APP_ID
Create React AppREACT_APP_REACT_APP_VARITY_APP_ID
  • Use .env.local for local development (git-ignored)
  • Store production secrets in your CI/CD platform
  • Rotate keys regularly
  • Commit .env files with real credentials
  • Use production keys in development
  • Share API keys in public repositories
  • Hardcode secrets in source code

Run the doctor command to verify your configuration:

Terminal window
varitykit doctor

This checks:

  • Credential availability (auto-provided or manually set)
  • Network connectivity
  • API key validity
  • Project structure
  1. Check file name is exactly .env or .env.local
  2. Restart your development server after changes
  3. Verify no syntax errors in the file
  4. Check framework-specific prefixes (NEXT_PUBLIC_, VITE_, etc.)

Run varitykit doctor to diagnose. Credentials are auto-provided. If they fail, check your network connection.