Skip to content

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

The Mastra ship loop 1. Develop (mastra dev) → 2. Build (mastra build) → 3. Deploy (deployer) → 4. Observe (traces + evals) Develop mastra dev Build mastra build Deploy deployer Observe traces + evals
Develop against a local server + Studio, build a Hono bundle, deploy with the matching deployer, then watch traces — and loop.
4111/swagger-ui
npx mastra dev

mastra dev gives you a hot-reloading endpoint and Studio — an interactive playground to exercise agents and workflows before wiring them into your app.

Terminal window
# Bundle into a production Hono server under .mastra/output
npx mastra build
# Serve the built output (OTEL tracing on by default)
npx mastra start

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. |

  • Serverless = external storage + flush(). The ephemeral filesystem breaks file:./mastra.db. Use a hosted DB and call await 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 with mastra 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.