Skip to main content
Prerequisites:
  • A Vercel account
  • Node.js version 22 or higher
  • A Mastra project ready to deploy
The Vercel deployer enables zero-configuration deployment of Mastra applications to Vercel’s serverless platform using the Build Output API.

Installation

1

Install the Vercel deployer

Install the @mastra/deployer-vercel package:
pnpm add @mastra/deployer-vercel
2

Configure the deployer

Add the Vercel deployer to your Mastra configuration:
import { Mastra } from '@mastra/core/mastra';
import { VercelDeployer } from '@mastra/deployer-vercel';

const deployer = new VercelDeployer({
  maxDuration: 60,      // Function timeout in seconds (optional)
  memory: 1024,         // Function memory in MB (optional)
  regions: ['iad1'],    // Deployment regions (optional)
});

const mastra = new Mastra({
  deployer,
  // ... other Mastra configuration
});
3

Build your project

Run your build command. The deployer will create the Vercel Build Output structure:
pnpm build
This generates:
  • .vercel/output/functions/index.func/ - Your bundled function
  • .vercel/output/config.json - Routing configuration
  • .vercel/output/functions/index.func/.vc-config.json - Function settings
4

Deploy to Vercel

Deploy using the Vercel CLI:
npx vercel deploy --prod
Or connect your Git repository to Vercel for automatic deployments.

Configuration options

The VercelDeployer constructor accepts the following options (all optional):

maxDuration

  • Type: number
  • Description: Maximum function execution time in seconds
  • Default: Depends on your Vercel plan
  • Example: maxDuration: 300 for 5 minutes

memory

  • Type: number
  • Description: Function memory allocation in MB
  • Default: 1024
  • Example: memory: 3008 for maximum memory

regions

  • Type: string[]
  • Description: Vercel regions where the function should be deployed
  • Default: All regions
  • Example: regions: ['iad1', 'sfo1']
These options are written to .vercel/output/functions/index.func/.vc-config.json and override Vercel’s defaults.

How it works

The Vercel deployer:
  1. Bundles your application using Rollup with optimizations
  2. Creates an entry point using Hono’s Vercel adapter:
import { handle } from 'hono/vercel'
import { mastra } from '#mastra';
import { createHonoServer, getToolExports } from '#server';
import { tools } from '#tools';

const app = await createHonoServer(mastra, { 
  tools: getToolExports(tools) 
});

export const GET = handle(app);
export const POST = handle(app);
export const PUT = handle(app);
export const DELETE = handle(app);
// ... other HTTP methods
  1. Generates Vercel configuration for routing and function settings
  2. Detects Node.js version automatically from your environment

Storage compatibility

The Vercel deployer does not support @mastra/libsql because it uses native Node.js bindings that cannot run in serverless environments.
Use these storage options instead:
  • @mastra/pg - PostgreSQL (recommended)
  • @mastra/mongodb - MongoDB
  • @mastra/dynamodb - AWS DynamoDB
The deployer automatically checks for incompatible dependencies during the build process.

Environment variables

Environment variables can be configured in multiple ways:
  1. Local .env files - Automatically loaded during development
  2. Vercel Dashboard - Set in your project settings
  3. Vercel CLI - Use vercel env commands
# Add environment variable via CLI
vercel env add DATABASE_URL

Project structure

After building, your project will have this structure:
your-project/
├── .vercel/
│   └── output/
│       ├── config.json              # Routing configuration
│       └── functions/
│           └── index.func/
│               ├── .vc-config.json  # Function settings
│               ├── index.mjs        # Bundled application
│               └── package.json     # Dependencies
├── src/
│   └── mastra/
│       └── index.ts                 # Your Mastra config
└── package.json

Troubleshooting

Make sure all dependencies are listed in your package.json. The deployer bundles your code but dependencies need to be properly declared.
Increase the maxDuration option:
new VercelDeployer({ maxDuration: 300 })
Note: Maximum duration depends on your Vercel plan.
The deployer automatically detects @mastra/libsql and throws an error. Switch to @mastra/pg or another compatible storage option.

Next steps

Server & API

Learn about Mastra’s server capabilities

Storage options

Explore compatible storage backends

Environment setup

Configure middleware and environment

Observability

Set up logging and tracing

Build docs developers (and LLMs) love