Prerequisites
Before you begin, make sure you have:- Node.js 20+ (download)
- A package manager: npm, yarn, pnpm, or bun
1. Create Your Project
Scaffold a new ChatJS app using the CLI:chat.config.ts ready to go. It also asks whether to include an Electron desktop app. It automatically detects your package manager and creates the appropriate lock file.
Understanding chat.config.ts
The chat.config.ts file controls all feature toggles, branding, and app settings. It’s generated with sensible defaults when you scaffold a project with the CLI.
What the default config includes
What the default config includes
The default configuration gives you a minimal, working setup:
This keeps your initial setup simple — the CLI will tell you exactly which environment variables are needed based on your choices.Enable features incrementally by editing
| Setting | Default | Notes |
|---|---|---|
| Gateway | Vercel AI Gateway | Set gateway: "openrouter" for OpenRouter |
| Authentication | GitHub only | Google and Vercel OAuth disabled |
| Features | All disabled | No sandbox, web search, MCP, image generation, or attachments |
| Anonymous users | 10 credits | Limited access, no tools |
| Models | Curated list | GPT-5 Nano/Mini, Gemini 2.5 Flash Lite, Claude Sonnet 4.5 |
chat.config.ts and adding the required environment variables. See Configuration for details.2. Configure Environment Variables
.env.local.
Expand the sections below for setup instructions:
Database (PostgreSQL)
Database (PostgreSQL)
Option A: Neon (generous free tier)
- Go to Neon
- Create a project and database
- Copy the connection string →
DATABASE_URL
- Go to Vercel Storage
- Create a new Postgres database
- Copy the connection string →
DATABASE_URL
AI Gateway
AI Gateway
ChatJS supports multiple AI gateways. Pick one:Option A: Vercel AI Gateway (default)
- Go to Vercel AI Gateway
- Create an API key
- Copy the key →
AI_GATEWAY_API_KEY
- Go to OpenRouter
- Create an API key
- Copy the key →
OPENROUTER_API_KEY
- Go to OpenAI API Keys
- Create an API key
- Copy the key →
OPENAI_API_KEY
Authentication (at least one provider required)
Authentication (at least one provider required)
GitHub (Recommended)
- Go to GitHub Developer Settings
- Click New OAuth App
- Set Homepage URL to
http://localhost:3000 - Set Authorization callback URL to
http://localhost:3000/api/auth/callback/github - Copy the Client ID →
AUTH_GITHUB_ID - Generate a Client Secret →
AUTH_GITHUB_SECRET
- Go to Google Cloud Console
- Create a new OAuth 2.0 Client ID (Web application)
- Add Authorized redirect URI:
http://localhost:3000/api/auth/callback/google - Copy Client ID →
AUTH_GOOGLE_ID - Copy Client Secret →
AUTH_GOOGLE_SECRET
- Go to Vercel Integration Console
- Create a new integration with Sign In with Vercel
- Copy Client ID →
VERCEL_APP_CLIENT_ID - Copy Client Secret →
VERCEL_APP_CLIENT_SECRET
Blob Storage (Optional)
Blob Storage (Optional)
Required for file attachments and image generation. Skip if you don’t need these features.
- Go to Vercel Blob
- Create a new blob store
- Copy the token →
BLOB_READ_WRITE_TOKEN
features.attachments: false and ai.tools.image.enabled: false in chat.config.ts.3. Push Database Schema
4. Start the Dev Server
Deploying to Production
Once you’re running locally, deploy your app:Vercel
Recommended. Integrated database, blob storage, and AI Gateway.
Docker
Containerized deployment for any platform.
Self-Hosted
Deploy to any Node.js platform.
Troubleshooting
Missing environment variables error
Missing environment variables error
ChatJS validates env vars at build time. Check
.env.local has all required
variables and restart the dev server.Database connection failed
Database connection failed
Verify
DATABASE_URL is correct and the database is running. For local
PostgreSQL, check the service is started.OAuth redirect error
OAuth redirect error
Make sure the callback URL in your OAuth app matches exactly. For local dev,
use
http://localhost:3000/api/auth/callback/{provider}.Optional Features
Optional Features
These environment variables enable additional capabilities:
| Variable | Feature | Setup Guide |
|---|---|---|
REDIS_URL | Resumable streams | Vercel KV |
TAVILY_API_KEY | Web search | Tavily |
FIRECRAWL_API_KEY | Web search | Firecrawl |
LANGFUSE_PUBLIC_KEY | LLM observability | Langfuse |
LANGFUSE_SECRET_KEY | LLM observability | Langfuse |
MCP_ENCRYPTION_KEY | MCP connectors | openssl rand -base64 32 (must be exactly 44 chars) |
CRON_SECRET | Cleanup cron job | Generate |
Next Steps
You’re up and running. Here’s where to go next:Configuration
Customize features, branding, and settings in chat.config.ts
AI Capabilities
Explore built-in tools: web search, image generation, code execution
Desktop App
Package your app as a native desktop application with Electron