Environment Variables
Complete reference for all environment variables used by ChatJS
This page lists every environment variable recognized by ChatJS, grouped by category. The schema is defined in apps/chat/lib/env-schema.ts and validated at build time by apps/chat/scripts/check-env.ts.
Required
These variables must be set for the EVE-backed application.
| Variable | Description | How to get it |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | Neon, Vercel Postgres, or any Postgres provider |
AUTH_SECRET |
Secret used to sign and encrypt session tokens (Better Auth) | Run openssl rand -base64 32 or use generate-secret.vercel.app/32 |
The required EVE setting is an independently generated EVE_GATEWAY_SECRET. The gateway origin and local/self-hosted workflow database have defaults. Vercel deployments use managed Workflow automatically. These settings are documented below. In addition to these core settings, at least one AI gateway credential and at least one OAuth provider must be configured. See the sections below.
Authentication
Enable providers in chat.config.ts under authentication. At least one must be enabled. The build validator checks that every enabled provider has its corresponding env vars set.
authentication: {
google: false, // Requires AUTH_GOOGLE_ID + AUTH_GOOGLE_SECRET
github: true, // Requires AUTH_GITHUB_ID + AUTH_GITHUB_SECRET
vercel: false, // Requires VERCEL_APP_CLIENT_ID + VERCEL_APP_CLIENT_SECRET
},
GitHub OAuth
| Variable | Description |
|---|---|
AUTH_GITHUB_ID |
GitHub OAuth app client ID |
AUTH_GITHUB_SECRET |
GitHub OAuth app client secret |
Setup: Go to GitHub Developer Settings → New OAuth App. Set the callback URL to https://yourdomain.com/api/auth/callback/github.
Google OAuth
| Variable | Description |
|---|---|
AUTH_GOOGLE_ID |
Google OAuth 2.0 client ID |
AUTH_GOOGLE_SECRET |
Google OAuth 2.0 client secret |
Setup: Go to Google Cloud Console → Create credentials → OAuth 2.0 Client ID (Web application). Add https://yourdomain.com/api/auth/callback/google as an authorized redirect URI.
Vercel OAuth
| Variable | Description |
|---|---|
VERCEL_APP_CLIENT_ID |
Vercel OAuth integration client ID |
VERCEL_APP_CLIENT_SECRET |
Vercel OAuth integration client secret |
Setup: Follow the Sign In with Vercel guide to create an integration.
AI Gateways
Exactly one gateway must be active. Set ai.gateway in chat.config.ts to select it.
ai: {
gateway: "vercel", // "vercel" | "openrouter" | "openai" | "openai-compatible" | "litellm"
}
Vercel AI Gateway (default)
Provides access to 120+ models from OpenAI, Anthropic, Google, xAI, Meta, and more through a single key. This is the default gateway.
| Variable | Required | Description |
|---|---|---|
AI_GATEWAY_API_KEY |
Self-hosted / local dev | API key for Vercel AI Gateway |
VERCEL_OIDC_TOKEN |
Auto-set on Vercel | OIDC token injected automatically on Vercel deployments |
Setup: Go to Vercel AI Gateway and create an API key.
OpenRouter
Provides access to hundreds of models with per-token pricing.
| Variable | Required | Description |
|---|---|---|
OPENROUTER_API_KEY |
Yes | Your OpenRouter API key (sk-or-v1-...) |
Setup: Create an account at OpenRouter, then go to API Keys.
OpenAI
Direct connection to the OpenAI API. Use when you only need OpenAI models.
| Variable | Required | Description |
|---|---|---|
OPENAI_API_KEY |
Yes | Your OpenAI API key (sk-...) |
Setup: Follow the OpenAI quickstart to create an API key.
OpenAI Compatible
Works with any endpoint that follows the OpenAI API format: Ollama, LM Studio, vLLM, Azure OpenAI, and others.
| Variable | Required | Description |
|---|---|---|
OPENAI_COMPATIBLE_BASE_URL |
Yes | Base URL of the compatible API (e.g., http://localhost:11434/v1) |
OPENAI_COMPATIBLE_API_KEY |
Yes | API key for the compatible provider |
Setup: Start your compatible server (for example, run ollama serve for Ollama), set OPENAI_COMPATIBLE_BASE_URL to its /v1 endpoint, and provide OPENAI_COMPATIBLE_API_KEY.
LiteLLM
Routes requests through a LiteLLM proxy for centralized model access, key management, routing, and spend tracking.
| Variable | Required | Description |
|---|---|---|
LITELLM_BASE_URL |
Yes | Base URL of the LiteLLM proxy (e.g., http://localhost:4000) |
LITELLM_API_KEY |
Optional | Master key or virtual key if your LiteLLM proxy requires authentication |
Setup: Start your LiteLLM proxy, set LITELLM_BASE_URL to the proxy root URL without /v1, and provide LITELLM_API_KEY only when the proxy requires auth.
Features
Tool flags live under ai.tools in chat.config.ts. Attachment uploads require durable storage and a persistent sandbox, for example chat-js add attachment-uploads --storage-provider vercel-blob --sandbox-provider vercel. Configure both providers’ credentials. Each enabled capability has an associated environment variable requirement validated at build time.
Web Search
Enable real-time web search with citations. Requires at least one search provider key.
ai: {
tools: {
webSearch: { enabled: true }, // Requires TAVILY_API_KEY or FIRECRAWL_API_KEY
urlRetrieval: { enabled: true }, // Requires FIRECRAWL_API_KEY
},
}
| Variable | Feature | Description | Get it |
|---|---|---|---|
TAVILY_API_KEY |
webSearch |
Tavily API key for web search (recommended) | app.tavily.com |
FIRECRAWL_API_KEY |
webSearch, urlRetrieval |
Firecrawl API key for web search and URL content extraction | firecrawl.dev |
EXA_API_KEY |
none | Recognized by env schema but not used by build-time webSearch validation |
Exa API key guide |
MCP Connectors
Install Model Context Protocol connectors to expose custom tools and data sources to the AI:
chat-js create my-chat --mcp
# Or, inside an existing app:
chat-js add mcp
Installed registrations determine availability. You must configure MCP_ENCRYPTION_KEY whenever MCP is installed, including before any connectors are added.
| Variable | Required | Description |
|---|---|---|
MCP_ENCRYPTION_KEY |
Yes | 44-character base64 key used to encrypt stored MCP server credentials (URLs, OAuth tokens) |
Generate a key:
openssl rand -base64 32
Postgres Hosting
DATABASE_URL is the runtime connection. Set DATABASE_MIGRATION_URL when your host provides a separate direct endpoint for schema operations. It falls back to DATABASE_URL when omitted. Set DATABASE_PREPARE=false for a transaction pooler without prepared-statement support, and optionally set DATABASE_MAX_CONNECTIONS to a positive per-process limit. See Database for deployment behavior.
File Storage
Attachments, image generation, and video generation require a durable storage adapter compatible with Files SDK. Storage requirements are generated from the selected provider and validated by scripts/check-env.ts.
ai: {
tools: {
image: { enabled: true },
video: { enabled: true },
},
}
Provider credentials belong in environment variables or the provider SDK’s credential chain. Non-secret adapter options belong in chatjs/providers/storage-options.ts. See File storage and the Files SDK provider reference for the requirements of your selected provider.
Code Execution Sandbox
Enable secure Python and JavaScript execution using Vercel Sandbox. Its persistent-file support is also required by attachment uploads, even when the code-execution tool is omitted. Use bun dev:supervise for local conversations that stage attachments.
ai: {
tools: {
codeExecution: { enabled: true },
},
}
| Variable | Required | Description |
|---|---|---|
VERCEL_OIDC_TOKEN |
Auto-set on Vercel | Used automatically for OIDC auth on Vercel deployments |
VERCEL_TEAM_ID |
Self-hosted only | Your Vercel team ID (team_...) |
VERCEL_PROJECT_ID |
Self-hosted only | Your Vercel project ID (prj_...) |
VERCEL_TOKEN |
Self-hosted only | Vercel API token with sandbox permissions |
VERCEL_SANDBOX_IMAGE_PYTHON |
Optional | Python image reference (default: vercel/sandbox/python:3.14) |
VERCEL_SANDBOX_IMAGE_JAVASCRIPT |
Optional | JavaScript image reference (default: vercel/sandbox/node:22) |
EVE runtime and trusted proxy headers
| Variable | Description |
|---|---|
EVE_GATEWAY_SECRET |
Required. Private credential used between ChatJS and EVE. Generate independently from AUTH_SECRET with openssl rand -base64 32. Rotating AUTH_SECRET does not rotate this credential. |
WORKFLOW_POSTGRES_URL |
Local/self-hosted only. Optional direct/session Postgres connection for registered-chat workflows. Defaults to DATABASE_URL. Never uses DATABASE_MIGRATION_URL. Unused on Vercel deployments. |
EVE_INTERNAL_ORIGIN |
Optional application gateway origin serving /eve/chat/v1/*. Defaults to https://${VERCEL_URL}, then the origin of APP_URL or PLAYWRIGHT_TEST_BASE_URL, then http://localhost:${PORT} (port 3000 by default). |
VERCEL_AUTOMATION_BYPASS_SECRET |
Server-only deployment-protection bypass credential for calls to this Vercel project. Required when protection blocks internal EVE requests. |
TRUSTED_CLIENT_IP_HEADER |
Optional self-hosted reverse-proxy header that contains one verified client IP. The proxy must overwrite any caller-provided value. Vercel uses its native trusted header. |
DATABASE_URL stores application identity and metadata everywhere. Vercel Preview and Production use managed Workflow for EVE execution and transcripts. Local/self-hosted registered chats use WORKFLOW_POSTGRES_URL and require both schemas to be initialized. Disposable guest chats keep their isolated local backend during development. See the database setup guide.
Leave EVE_INTERNAL_ORIGIN unset for the integrated gateway. On Vercel it follows the exact deployment URL, even when OAuth uses a stable branch alias or APP_URL. Derived app/test URLs discard paths, queries, and fragments, but reject credentials and non-HTTP(S) schemes. Use HTTPS for remote gateways, including private-network workers. HTTP is allowed only for loopback hosts (localhost, 127.0.0.0/8, and [::1]). If you previously used an internal HTTP worker, configure a TLS endpoint or a loopback gateway. An override must serve the named /eve/chat/v1/* mount and contain no path, query, or credentials. A raw EVE worker exposing only /eve/v1/* is not a supported endpoint. On protected Vercel deployments, the server forwards VERCEL_AUTOMATION_BYPASS_SECRET only when this origin exactly matches https://${VERCEL_URL} or https://${VERCEL_BRANCH_URL}. It does not forward the credential to other origins, including arbitrary custom domains. The EVE bearer credential and owner identity are still required.
Optional / Advanced
Cron Job Secret
Secures the /api/cron/cleanup endpoint that removes orphaned managed files.
| Variable | Description |
|---|---|
CRON_SECRET |
Bearer token that the cron runner must send to authenticate |
Generate a secret:
openssl rand -base64 32
On Vercel, the platform automatically sends CRON_SECRET as a Authorization: Bearer <secret> header when triggering cron jobs.
App URL
| Variable | Required | Description |
|---|---|---|
APP_URL |
Non-Vercel deployments | Full public URL of the app including protocol (e.g., https://myapp.com) |
VERCEL_URL |
Auto-set by Vercel | Deployment hostname, without protocol |
VERCEL_BRANCH_URL |
Auto-set by Vercel | Stable branch hostname used in preview environments |
VERCEL_ENV |
Auto-set by Vercel | development, preview, or production |
The shared getBaseUrl() helper resolves the application origin in this order:
- Explicit
APP_URL. https://${VERCEL_BRANCH_URL}whenVERCEL_ENV=preview.https://${VERCEL_URL}.http://localhost:3000.
Better Auth uses APP_URL when set. On production Vercel deployments, its fallback is appUrl in chat.config.ts. Elsewhere, including previews, it uses getBaseUrl(). Register OAuth callbacks against the resulting auth origin. Do not carry a local or production APP_URL into a preview unless you intend to override its branch URL. This origin selection does not change EVE_INTERNAL_ORIGIN.
Observability (Langfuse)
Install langfuse to export LLM traces through OpenTelemetry and Langfuse. The integration is omitted from new apps by default and installed in the demo. When installed, set both keys below before starting Node or building the app. The installed feature descriptor supplies build-time validation, and instrumentation reports missing keys explicitly at Node startup.
| Variable | Description | Get it |
|---|---|---|
LANGFUSE_PUBLIC_KEY |
Required when Langfuse is installed. Langfuse project public key | Langfuse Cloud → Project Settings → API Keys |
LANGFUSE_SECRET_KEY |
Required when Langfuse is installed. Langfuse project secret key | Same as above |
LANGFUSE_BASE_URL |
Optional Langfuse API base URL (default: https://cloud.langfuse.com) |
Set to your self-hosted Langfuse URL if applicable |
LANGFUSE_DEBUG |
Optional exporter debug logging (default: false) |
Set to true for troubleshooting |
After running chat-js add langfuse, configure LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY in .env.local before starting the server. The SDK defaults LANGFUSE_BASE_URL to https://cloud.langfuse.com. Set LANGFUSE_DEBUG=true only when you want exporter debug logging.
Apps that omit the integration do not import its exporter or require its credentials. Playwright browser fixtures skip external trace export. Missing keys in normal Node startup raise CHATJS_MISSING_CREDENTIALS rather than silently disabling tracing.
Quick Reference
All variables in one place:
| Variable | Category | Required |
|---|---|---|
DATABASE_URL |
Core | Always |
AUTH_SECRET |
Core | Always |
AI_GATEWAY_API_KEY |
Gateway | Vercel gateway (non-Vercel hosting) |
VERCEL_OIDC_TOKEN |
Gateway | Auto-set on Vercel |
OPENROUTER_API_KEY |
Gateway | OpenRouter gateway |
OPENAI_API_KEY |
Gateway | OpenAI gateway |
OPENAI_COMPATIBLE_BASE_URL |
Gateway | OpenAI-compatible gateway |
OPENAI_COMPATIBLE_API_KEY |
Gateway | OpenAI-compatible gateway |
LITELLM_BASE_URL |
Gateway | LiteLLM gateway |
LITELLM_API_KEY |
Gateway | Optional for LiteLLM gateway |
AUTH_GITHUB_ID |
Auth | If authentication.github: true |
AUTH_GITHUB_SECRET |
Auth | If authentication.github: true |
AUTH_GOOGLE_ID |
Auth | If authentication.google: true |
AUTH_GOOGLE_SECRET |
Auth | If authentication.google: true |
VERCEL_APP_CLIENT_ID |
Auth | If authentication.vercel: true |
VERCEL_APP_CLIENT_SECRET |
Auth | If authentication.vercel: true |
BLOB_READ_WRITE_TOKEN |
Storage | When Vercel Blob is the selected provider |
TAVILY_API_KEY |
Feature | If ai.tools.webSearch.enabled (one search key required) |
FIRECRAWL_API_KEY |
Feature | If ai.tools.webSearch.enabled or ai.tools.urlRetrieval.enabled |
EXA_API_KEY |
Optional | Recognized by env schema but not required by current validation |
MCP_ENCRYPTION_KEY |
Feature | When MCP is installed |
VERCEL_TEAM_ID |
Feature | When Vercel Sandbox is installed without OIDC auth |
VERCEL_PROJECT_ID |
Feature | When Vercel Sandbox is installed without OIDC auth |
VERCEL_TOKEN |
Feature | When Vercel Sandbox is installed without OIDC auth |
VERCEL_SANDBOX_IMAGE_PYTHON |
Feature | Optional Python sandbox image override |
VERCEL_SANDBOX_IMAGE_JAVASCRIPT |
Feature | Optional JavaScript sandbox image override |
EVE_GATEWAY_SECRET |
Required | Private ChatJS-to-EVE credential |
WORKFLOW_POSTGRES_URL |
EVE | Required locally/self-hosted, unused on Vercel |
EVE_INTERNAL_ORIGIN |
EVE | Optional application gateway origin override |
TRUSTED_CLIENT_IP_HEADER |
EVE | Optional self-hosted trusted proxy header |
CRON_SECRET |
Optional | Secure cleanup cron endpoint |
APP_URL |
Optional | Required on non-Vercel deployments |
VERCEL_URL |
Optional | Auto-set by Vercel platform |
VERCEL_BRANCH_URL |
Optional | Stable preview branch hostname |
VERCEL_ENV |
Optional | Vercel environment classification |
VERCEL_AUTOMATION_BYPASS_SECRET |
EVE | Internal access to protected deployments |
LANGFUSE_PUBLIC_KEY |
Feature | When Langfuse is installed |
LANGFUSE_SECRET_KEY |
Feature | When Langfuse is installed |
LANGFUSE_BASE_URL |
Optional | Self-hosted Langfuse endpoint |
LANGFUSE_DEBUG |
Optional | Exporter debug logging |
Related
- Config Reference: feature flags and gateway settings in
chat.config.ts - Deploy to Vercel: how Vercel auto-sets several of these variables
- Gateways Overview: choosing and configuring an AI gateway
- Authentication: OAuth provider setup details
- File storage: provider configuration and credentials