Quickstart
Get ChatJS running in minutes
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:
npx @chat-js/cli@latest create my-app
cd my-app
The CLI walks you through selecting your AI gateway, features, and auth providers, then generates a configured project with chat.config.ts ready to go. It also asks whether to include a Desktop app. It preserves bun, pnpm, and yarn when launched from those tools, and defaults npx/npm launches to npm unless you pass --package-manager.
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
The default configuration gives you a minimal, working setup:
| 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 |
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 chat.config.ts and adding the required environment variables. See Configuration for details.
2. Configure Environment Variables
cp .env.example .env.local
After scaffolding, the CLI prints the exact environment variables required for your configuration. Fill in those values in .env.local.
Expand the sections below for setup instructions:
Database (PostgreSQL)
Option A: Neon (generous free tier)
- Go to Neon
- Create a project and database
- Copy the connection string →
DATABASE_URL
Option B: Vercel Postgres
- Go to Vercel Storage
- Create a new Postgres database
- Copy the connection string →
DATABASE_URL
Option C: Local PostgreSQL
# macOS
brew install postgresql && brew services start postgresql
createdb chatjs
# DATABASE_URL=postgres://localhost:5432/chatjsAI 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
Option B: OpenRouter
- Go to OpenRouter
- Create an API key
- Copy the key →
OPENROUTER_API_KEY
Option C: OpenAI
- Follow the OpenAI quickstart to create an API key
- Create an API key
- Copy the key →
OPENAI_API_KEY
Option D: OpenAI Compatible Use any endpoint that follows the OpenAI API format (Ollama, LM Studio, vLLM, Azure).
See Gateways Overview for a full comparison and configuration details.
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
Vercel
- 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
File Storage (Optional)
Required for file attachments, image generation, and video generation. The installer asks you to select a Files SDK provider when you enable one of these capabilities.
Configure the environment variables printed by the CLI for your selected
provider. For Vercel Blob, connect a Blob store and copy its token to
BLOB_READ_WRITE_TOKEN for local development.
See File storage for provider configuration, credentials, and migration behavior.
3. Push Database Schema
npm run db:push
This pushes the Drizzle schema directly to your database. For production migrations, see deployment guides.
4. Start the Dev Server
npm run dev
Open http://localhost:3000. You should see the ChatJS interface with a model selector and chat input.
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
ChatJS validates env vars at build time. Check .env.local has all required
variables and restart the dev server.
Database connection failed
Verify DATABASE_URL is correct and the database is running. For local
PostgreSQL, check the service is started.
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
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: