Quick deploy
The fastest way to deploy is using the Deploy Button:- Fork the repository to your GitHub account
- Create a new Vercel project
- Configure basic settings
- Deploy the application
Manual deployment
For more control over the deployment process, follow these steps:Prerequisites
Before deploying, ensure you have:
- A Vercel account
- A GitHub, GitLab, or Bitbucket account
- The Vercel CLI installed:
npm i -g vercel - Your repository pushed to your Git provider
Create Vercel project
Option A: Using Vercel DashboardFollow the prompts to link your project and deploy.
- Go to vercel.com/new
- Import your Git repository
- Configure project settings:
- Framework Preset: Next.js
- Build Command:
tsx lib/db/migrate && next build(detected automatically) - Output Directory:
.next(default) - Install Command:
pnpm install(or your package manager)
Provision storage
Add required storage services to your Vercel project:
Postgres database
- Go to your project dashboard
- Click Storage tab
- Click Create Database
- Select Postgres
- Choose a region (select one close to your deployment region)
- Click Create
POSTGRES_URL and related variables to your project.Blob storage
- In the Storage tab
- Click Create Store
- Select Blob
- Click Create
BLOB_READ_WRITE_TOKEN to your project.Redis (KV)
- In the Storage tab
- Click Create Store
- Select KV (Redis)
- Click Create
REDIS_URL and related variables to your project.Configure environment variables
Set required environment variables in your Vercel project:
- Go to Settings → Environment Variables
- Add the following variables:
Generate a secret:Add this value to your environment variables.
The following variables are automatically added when you provision storage:
POSTGRES_URL(Postgres)BLOB_READ_WRITE_TOKEN(Blob)REDIS_URL(KV)
AI_GATEWAY_API_KEY is not required for Vercel deployments. AI Gateway uses OIDC tokens automatically.Deploy
Trigger a deployment:Option A: Push to GitVercel automatically deploys when you push to your main branch.Option B: Manual deployment via CLIOption C: Redeploy from dashboard
- Go to your project Deployments page
- Click the three dots menu on the latest deployment
- Click Redeploy
Configuration files
The application includes Vercel-specific configuration:vercel.json
vercel.json
next.config.ts
next.config.ts
cacheComponents: true- Enables Next.js component cachingimages.remotePatterns- Allows images from:avatar.vercel.sh(user avatars)*.public.blob.vercel-storage.com(uploaded files)
withBotId()- Wraps config with BotID security features
Environment-specific deployments
Vercel supports multiple environments:Production
- Main branch deployments
- Production environment variables
- Production database
- URL:
your-project.vercel.app
Preview
- Pull request and branch deployments
- Preview environment variables (optional)
- Can use separate preview database
- URL:
your-project-git-branch.vercel.app
Development
- Local development with
vercel dev - Development environment variables
- Uses
.env.localfile - URL:
localhost:3000
Setting environment-specific variables
When adding environment variables in the Vercel dashboard, choose which environments they apply to:- ✅ Production
- ✅ Preview
- ✅ Development
For sensitive production data, uncheck Preview to prevent preview deployments from accessing production resources.
AI Gateway configuration
The application uses Vercel AI Gateway to access multiple LLM providers through a unified interface.Automatic authentication (Vercel deployments)
On Vercel, AI Gateway authentication is handled automatically using OIDC tokens. No additional configuration needed.Supported models
The application is configured to use the following models through AI Gateway:lib/ai/models.ts
How it works
The application uses the AI SDK’s Gateway provider:lib/ai/providers.ts
- Routes requests to the appropriate LLM provider
- Handles authentication automatically (OIDC on Vercel)
- Provides unified API across all models
- Includes rate limiting and monitoring
Local development with Vercel
To develop locally with Vercel environment variables:Run development server
vercel dev to run with Vercel’s development server:
- Serverless functions
- Environment variables
- Edge functions
- Middleware
Monitoring and logs
Vercel provides built-in monitoring:Deployment logs
- Go to Deployments
- Click on a deployment
- View Build Logs and Function Logs
Runtime logs
- Go to Logs tab
- Filter by:
- Time range
- Status code
- Source (Function, Edge, etc.)
- Search query
Analytics
The application includes Vercel Analytics:- Page views
- Visitor stats
- Performance metrics
- Web Vitals
Custom domains
To add a custom domain:Configure DNS
Follow Vercel’s instructions to configure DNS:For apex domain (example.com):
- Add A record to
76.76.21.21
- Add CNAME record to
cname.vercel-dns.com
Troubleshooting
Build fails - migration error
Build fails - migration error
Cause: Database migration failed during build.Solutions:
- Check
POSTGRES_URLis set correctly - Verify database is accessible from Vercel
- Review build logs for specific error
- Ensure database user has necessary permissions
- For preview deployments, consider skipping migrations or using a preview database
Runtime error - Cannot find module
Runtime error - Cannot find module
Cause: Missing dependency or build issue.Solutions:
- Check
package.jsonincludes all dependencies - Ensure build completed successfully
- Try redeploying:
vercel --prod --force - Check Node.js version compatibility
AI Gateway authentication failed
AI Gateway authentication failed
Cause: OIDC token issue or misconfiguration.Solutions:
- Verify project is deployed on Vercel (OIDC only works on Vercel)
- Check AI Gateway is enabled for your account
- Review function logs for detailed error messages
- Ensure you’re not setting
AI_GATEWAY_API_KEY(not needed on Vercel)
File upload fails
File upload fails
Cause: Blob storage not configured or token invalid.Solutions:
- Verify Blob store is provisioned
- Check
BLOB_READ_WRITE_TOKENis set - Ensure token has read and write permissions
- Review function logs for specific error
Session/auth issues
Session/auth issues
Cause: Missing or invalid
AUTH_SECRET.Solutions:- Verify
AUTH_SECRETis set in environment variables - Generate a new secret:
openssl rand -base64 32 - Redeploy after adding the variable
- Clear browser cookies and try again
Performance optimization
Edge runtime
Consider using Edge runtime for API routes that don’t need Node.js APIs:- Faster cold starts
- Lower latency
- Better global distribution
Image optimization
Next.js automatically optimizes images on Vercel. Use theImage component:
Caching
Configure caching in your API routes:Security best practices
- Set
AUTH_SECRETto a strong random value - Use environment-specific databases (separate prod/preview/dev)
- Enable Vercel’s DDoS protection
- Configure allowed domains in CORS if needed
- Review security headers in
next.config.ts - Enable Vercel’s Web Application Firewall (WAF)
- Monitor logs for suspicious activity
- Keep dependencies updated
Next steps
Environment variables
Learn about all environment variables
Database setup
Configure and manage your database