Skip to main content

VercelDeployer

The VercelDeployer bundles your Mastra server and generates output conforming to Vercel's Build Output API. Vercel deploys this output directly as serverless functions.

Installation
Direct link to Installation

To use VercelDeployer, install the @mastra/deployer-vercel package:

npm install @mastra/deployer-vercel@latest

Usage example
Direct link to Usage example

Import VercelDeployer and set it as the deployer in your Mastra configuration:

src/mastra/index.ts
import { Mastra } from '@mastra/core'
import { VercelDeployer } from '@mastra/deployer-vercel'

export const mastra = new Mastra({
deployer: new VercelDeployer(),
})

Constructor options
Direct link to Constructor options

The deployer accepts the following options:

  • studio?: boolean: Deploy Studio alongside your API as static assets served from Vercel's Edge CDN. Defaults to false.
  • maxDuration?: number: Function execution timeout (in seconds). This sets Vercel's limit only; Mastra's own request timeout is configured separately, see Request timeouts.
  • memory?: number: Function memory (in MB)
  • regions?: string[]: Regions to deploy the function (e.g. ['sfo1','iad1'])

The maxDuration, memory, and regions options are merged into .vercel/output/functions/index.func/.vc-config.json while preserving default fields (handler, launcherType, runtime, shouldAddHelpers).

Example with overrides
Direct link to Example with overrides

src/mastra/index.ts
import { Mastra } from '@mastra/core'
import { VercelDeployer } from '@mastra/deployer-vercel'

export const mastra = new Mastra({
deployer: new VercelDeployer({
studio: true,
maxDuration: 600,
memory: 1536,
regions: ['sfo1', 'iad1'],
}),
})

Request timeouts
Direct link to Request timeouts

Vercel's function execution time and Mastra's request timeout are enforced separately:

  • Vercel function execution time: set by the deployer's maxDuration option, in seconds.
  • Mastra request timeout: set by server.timeout in your Mastra config, in milliseconds. When unset it defaults to 180000 (180 seconds), and requests that exceed it are answered with 504 Gateway Timeout.

maxDuration doesn't change server.timeout. A request that takes longer than 180 seconds fails even if maxDuration is higher, so raise both when you run long requests such as workflow runs or streaming agents:

src/mastra/index.ts
import { Mastra } from '@mastra/core'
import { VercelDeployer } from '@mastra/deployer-vercel'

export const mastra = new Mastra({
deployer: new VercelDeployer({
maxDuration: 600, // seconds
}),
server: {
timeout: 600_000, // milliseconds, keep at or below maxDuration
},
})

Build output
Direct link to Build output

After running mastra build, the deployer generates a .vercel/output directory conforming to Vercel's Build Output API (v3). This directory contains routing configuration and serverless function bundles that Vercel deploys directly, bypassing framework detection.

The output contains:

  • config.json: Routing configuration that directs requests to the appropriate handler
  • functions/: Your Mastra server bundled as a serverless function
  • static/: Studio SPA assets (only when studio: true)

Without studio:

.vercel/
└── output/
├── config.json
└── functions/
└── index.func/
├── .vc-config.json
├── index.mjs
└── node_modules/

With studio: true:

.vercel/
└── output/
├── config.json
├── static/
│ ├── index.html
│ └── assets/
│ ├── *.js
│ └── *.css
└── functions/
└── index.func/
├── .vc-config.json
├── index.mjs
└── node_modules/

When studio is enabled, the routing is configured so that / and the Studio routes listed in the Studio build's route manifest are served from index.html for client-side routing, and static assets (JS, CSS) are served from Vercel's Edge CDN with no function invocations. All other paths, including /api/* and custom routes registered with registerApiRoute(), are handled by the serverless function. Custom routes that fall under a Studio route (for example, /agents/custom) are served from index.html instead, so register custom routes outside Studio's route roots.

This folder is generated during build and shouldn't be committed to version control.