Deployment
Ship it
Mastra runs anywhere Node runs, and ships deployers that target common serverless platforms. mastra build bundles your app into a production Hono server under .mastra/output. The path is the same everywhere:
The Mastra ship loop
Local development
Section titled “Local development”npx mastra devmastra dev gives you a hot-reloading endpoint and Studio — an interactive playground to exercise agents and workflows before wiring them into your app.
Build & run
Section titled “Build & run”# Bundle into a production Hono server under .mastra/outputnpx mastra build
# Serve the built output (OTEL tracing on by default)npx mastra startDeployers & targets
Section titled “Deployers & targets”A deployer packages your Mastra app for a specific platform — set it on the Mastra instance and mastra build emits platform-specific output.
import { Mastra } from '@mastra/core';import { VercelDeployer } from '@mastra/deployer-vercel';
export const mastra = new Mastra({ deployer: new VercelDeployer({ studio: true, // serve Studio as static assets on the Edge CDN maxDuration: 600, // seconds memory: 1536, // MB regions: ['sfo1', 'iad1'], }),});| Target | Deployer | Notes |
| --- | --- | --- |
| Vercel | @mastra/deployer-vercel | Serverless functions; pairs naturally with a Next.js front end. Served at /api/*. |
| Cloudflare Workers | @mastra/deployer-cloudflare | Edge runtime; mind Node-API compatibility. |
| Netlify | @mastra/deployer-netlify | Serverless functions. |
| Self-host / Node | none needed | mastra build + mastra start on any Node host or container. |
Production concerns
Section titled “Production concerns”- Serverless = external storage +
flush(). The ephemeral filesystem breaksfile:./mastra.db. Use a hosted DB and callawait mastra.getObservability().flush()before the function returns, or deploy to a long-running host. - Secrets & env — provider keys (
OPENAI_API_KEY, …) are read by the model router; never commit them. Manage remote secrets withmastra server env set/import/pull. - Storage is required for persisted memory and tracing — point them at a durable backend so suspended workflows survive restarts.
- Lock the surface — endpoints are prefixed
/api, and Swagger/OpenAPI are off in production by default. Add auth before exposing endpoints (and before exposing Studio). - Observability — sample traces and export to your provider (Langfuse/Braintrust/OTEL), and redact with
SensitiveDataFilter. See Concepts → Observability. - Evals in CI — run scorers on a reference set to catch quality regressions before they ship.
Reference: CLI · Cloud providers · Vercel guide · Server
Back to the Mastra overview · or browse all AI Engines.