If you haven’t set up your project yet, start with the Quickstart to scaffold and run locally first.
Vercel Integrations
ChatJS uses several Vercel platform features. Enable them in your Vercel dashboard under Storage and AI.| Integration | Purpose | Required |
|---|---|---|
| Vercel Postgres or Neon | Primary database | Yes |
| Vercel Blob | File attachments, generated images | If using attachments/image gen |
| Vercel KV | Resumable streams (Redis) | Optional |
| AI Gateway | Unified access to 120+ AI models | Yes |
AI Gateway
By default, ChatJS uses Vercel AI Gateway to access 120+ models from OpenAI, Anthropic, Google, and more.- Go to Vercel AI Gateway
- Create an API key
- Add to environment:
AI_GATEWAY_API_KEY
chat.config.ts. See Multi-Model Support for configuring available models.
Blob Storage
Required for file attachments and AI image generation.- Go to Storage → Create → Blob
- Connect to your project
- Environment variable
BLOB_READ_WRITE_TOKENis auto-added
chat.config.ts:
KV (Redis)
Enables resumable streams - users can refresh the page mid-generation and continue where they left off.- Go to Storage → Create → KV
- Connect to your project
- Environment variable
REDIS_URLis auto-added
Cron Jobs
ChatJS includes a daily cleanup job that removes orphaned blob attachments (uploaded but never saved to a message).Configuration
Defined invercel.json:
Security
The cron endpoint requires aCRON_SECRET environment variable:
Customizing Cleanup
Editapp/api/cron/cleanup/route.ts to add cleanup tasks:
Code Execution Sandbox
The code execution tool uses Vercel Sandbox for secure Python execution.Authentication
On Vercel, sandbox uses OIDC automatically. For local development or self-hosted:Runtime Configuration
Set the Python version via environment variable:Resource Limits
Sandboxes run with:- 2 vCPUs
- 5 minute timeout
- Pre-installed: matplotlib, pandas, numpy, sympy, yfinance
Environment Variables
Required
| Variable | Description |
|---|---|
DATABASE_URL | PostgreSQL connection string |
AUTH_SECRET | Session encryption key |
AI_GATEWAY_API_KEY | Vercel AI Gateway key (or OPENROUTER_API_KEY if using OpenRouter) |
Optional (Vercel Features)
| Variable | Feature |
|---|---|
BLOB_READ_WRITE_TOKEN | Blob storage (auto-set by integration) |
REDIS_URL | KV/Redis for resumable streams |
CRON_SECRET | Secure cron endpoint |
Pull from Vercel
After linking your project, pull all environment variables:Rate Limiting and Security
The/api/chat endpoint is expensive (it calls AI providers on every request). Protect it from abuse in production.
Vercel Firewall
Enable Vercel Firewall in your project settings. Create a rate limiting rule for the chat endpoint:- Go to Settings → Firewall
- Add a rule targeting
POST /api/chat - Set a rate limit (for example, 20 requests per minute per IP)
- Choose Challenge or Block as the action
Vercel WAF
For additional protection, enable the Web Application Firewall to block common attack patterns (SQL injection, XSS) at the edge before requests reach your application.Environment Variable Security
- Never commit
.env.localto version control - Use Vercel’s environment variable management to set secrets per environment (production, preview, development)
- Rotate
AUTH_SECRETand API keys periodically
Production Checklist
Before going live:Enable production domain
Enable production domain
- Go to Settings → Domains
- Add your custom domain
- Update OAuth callback URLs to use the new domain
Configure OAuth for production
Configure OAuth for production
Update your OAuth apps (GitHub, Google) with production callback URLs:
Enable rate limiting
Enable rate limiting
Set up Vercel Firewall rules for the
/api/chat endpoint to prevent abuse. See the section above for details.Set up monitoring
Set up monitoring
- Enable Vercel Analytics for web vitals
- Configure Langfuse for LLM observability (optional)
Review storage limits
Review storage limits
Check your plan limits for:
- Blob storage (file count and size)
- KV operations (for resumable streams)
- AI Gateway usage
Troubleshooting
Cron job not running
Cron job not running
- Verify
CRON_SECRETis set in environment variables - Check Vercel dashboard → Logs → filter by
/api/cron - Crons only run in production (not preview deployments)
Blob upload fails
Blob upload fails
- Ensure
BLOB_READ_WRITE_TOKENis set - Check blob storage isn’t at capacity
- Verify file size is under 500MB limit
Code execution times out
Code execution times out
- Default timeout is 5 minutes
- Check sandbox logs in Vercel dashboard
- Ensure OIDC is working (automatic on Vercel)