Documentation

Deploy a Nitro API server

Build and run a portable Nitro pattern export in production.

Generated Nitro exports are API-only Node.js apps. Use the scripts in the exported package.json.

Build and start

pnpm install
pnpm typecheck
pnpm build
pnpm start

pnpm start runs node .output/server/index.mjs after nitro build.

Environment variables

.env and .env.local are loaded only by nitro dev. In production, set environment variables through your host (process env, platform secrets, etc.).

At minimum:

  • pattern credentials from .env.example (for example AI_GATEWAY_API_KEY)
  • PORT β€” default in the artifact is 3001
  • HOST β€” use 0.0.0.0 in containers
  • CORS_ORIGINS β€” comma-separated browser origins that may call the API
  • CORS_ALLOW_CREDENTIALS β€” set true only when cookies or credentialed fetches are required

Streaming and proxies

AI SDK UI message streams expose x-vercel-ai-ui-message-stream. The generated CORS middleware allows that header. Disable response buffering on reverse proxies in front of long-lived streams.

Native modules

Some patterns depend on native packages such as @resvg/resvg-js. If pnpm build fails while pnpm dev works, add an externals entry in nitro.config.ts for that package and rebuild.