---
title: "Deploy to Vercel"
description: "What an app gets on Vercel, the host the package is built on first: BotID, Sentry's integration, the AI Gateway and the project's env, then this site's own setup as a reference: Web Analytics and Speed Insights without cookies, Firewall rate limits and a keyless model for the docs assistant."
canonical_url: "https://nuxt-backend.dev/docs/ship/deploy/vercel"
---
# Deploy to Vercel

> What an app gets on Vercel, the host the package is built on first: BotID, Sentry's integration, the AI Gateway and the project's env, then this site's own setup as a reference: Web Analytics and Speed Insights without cookies, Firewall rate limits and a keyless model for the docs assistant.

Version: nuxt-backend 0.6.x · Tab: Ship · Kind: how-to · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

- [Source](https://github.com/qruto/nuxt-backend/blob/main/website/shared/vercel.ts)

Vercel is the host the package is built and tested on first: the deploy itself is the one every host shares ([Deploy to production](https://nuxt-backend.dev/docs/ship/deploy)), and on Vercel a few capabilities take what the platform gives. [Vercel](https://nuxt-backend.dev/docs/services/vercel) has the account and the project's setup. Off Vercel each of them keeps working another way ([Vercel first, not Vercel only](https://nuxt-backend.dev/docs/start/concepts/principles#vercel-first-not-vercel-only)).

## What an app gets on Vercel

<table>
<thead>
  <tr>
    <th>
      Capability
    </th>
    
    <th>
      On Vercel
    </th>
    
    <th>
      Read
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        protection
      </code>
    </td>
    
    <td>
      BotID, an invisible bot check before a code is sent or an account created: the Nuxt server runs it and signs a proof the deployment checks, once <code>
        botid
      </code>
      
       (an optional peer) is installed
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/services/bot-protection">
        Bot protection
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        monitoring
      </code>
    </td>
    
    <td>
      Sentry's integration sets the names a build uploads source maps with. The package reads the DSN the integration sets, <code>
        NEXT_PUBLIC_SENTRY_DSN
      </code>
      
      , as <code>
        MONITORING_DSN
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/services/sentry">
        Sentry
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        ai
      </code>
    </td>
    
    <td>
      Models by <code>
        provider/model
      </code>
      
       id at their real cost, through the Convex AI Gateway on a paid Convex plan, else the Vercel AI Gateway. The backend's calls run in Convex actions, never on Vercel, so the Vercel AI Gateway needs <code>
        AI_GATEWAY_API_KEY
      </code>
      
       on the deployment
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/ai/models#where-a-model-id-goes">
        Choose a model
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        hosting
      </code>
    </td>
    
    <td>
      The build command and the env split, set in the project's settings. One-command production writes the app's env into the project, and a deploy template starts a new app with Convex through the Marketplace
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/ship/deploy/one-command">
        One-command production
      </a>
      
      , <a href="https://nuxt-backend.dev/docs/ship/deploy/template">
        Start from the deploy template
      </a>
    </td>
  </tr>
</tbody>
</table>

### The backend's URL at build

The build bakes in the deployment's URLs, derived from `NUXT_PUBLIC_BACKEND_URL` (or the `CONVEX_DEPLOYMENT` the Convex CLI names) where the build runs. The sign-in proxy at `/api/auth` forwards to the HTTP routes' origin it baked in. When the build knew no backend URL (`NUXT_PUBLIC_BACKEND_URL` set for the runtime only, say), that origin is empty, and every sign-in request answers `500`. Set `NUXT_PUBLIC_BACKEND_URL` for builds too, or set `NUXT_PUBLIC_CONVEX_SITE_URL` to the deployment's `https://<name>.convex.site` URL on the project as well. `npx nuxt-backend doctor --prod` asks the proxy through the live site, and reports it as [`site-auth-proxy`](https://nuxt-backend.dev/docs/reference/cli/diagnostics#site-auth-proxy).

## This site's setup

This site, the docs, the homepage and the playground, is one Nuxt app on Vercel, built and deployed as [Deploy to production](https://nuxt-backend.dev/docs/ship/deploy) describes. Beside hosting it uses a few Vercel features, each through Vercel's own package or integration, and each turns off by itself anywhere else, so a local or CI build behaves as before. Take the parts your app needs:

<table>
<thead>
  <tr>
    <th>
      Feature
    </th>
    
    <th>
      What it gives
    </th>
    
    <th>
      How it is turned on
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Web Analytics
    </td>
    
    <td>
      Page views and referrers, with no cookies
    </td>
    
    <td>
      Its Nuxt module in a Vercel build, and the dashboard toggle
    </td>
  </tr>
  
  <tr>
    <td>
      Speed Insights
    </td>
    
    <td>
      Core Web Vitals from real visits
    </td>
    
    <td>
      Its Nuxt module in a Vercel build, and the dashboard toggle
    </td>
  </tr>
  
  <tr>
    <td>
      Firewall
    </td>
    
    <td>
      Rate limits per IP at the edge, held across every server instance
    </td>
    
    <td>
      <code>
        @vercel/firewall
      </code>
      
       in a server middleware, and one rule per limit
    </td>
  </tr>
  
  <tr>
    <td>
      Sentry's integration
    </td>
    
    <td>
      Error reports from the browser and the Nuxt server, with source maps
    </td>
    
    <td>
      <code>
        @sentry/nuxt
      </code>
      
      , the integration, and the DSN in <code>
        MONITORING_DSN
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      AI Gateway
    </td>
    
    <td>
      A model for the docs assistant, with no key on Vercel
    </td>
    
    <td>
      The deployment's OIDC token
    </td>
  </tr>
</tbody>
</table>

## Count visits without cookies

Install Vercel's two packages, and add their Nuxt modules for a build on Vercel only:

```bash
npm install @vercel/analytics @vercel/speed-insights
```

```ts [nuxt.config.ts]
// A deployment's build, not a machine that loaded what `vercel env pull`
// wrote: that file sets VERCEL too, beside VERCEL_ENV=development.
const onVercel = Boolean(process.env.VERCEL) && process.env.VERCEL_ENV !== 'development'

export default defineNuxtConfig({
  modules: [
    'nuxt-backend',
    ...(onVercel ? ['@vercel/analytics/nuxt', '@vercel/speed-insights/nuxt'] : []),
  ],
})
```

Then turn on **Analytics** and **Speed Insights** in the project's dashboard before the next deploy. Each module adds a client plugin that loads its script from the site's own origin, `/_vercel/insights/script.js` and `/_vercel/speed-insights/script.js`, which only Vercel serves, and only once the feature is on. That is why the modules are left out elsewhere: another host answers those paths with `404`, and in dev each module loads a debug script from Vercel's CDN.

Neither sets a cookie or stores anything on the visitor's device. Web Analytics tells visitors apart by a hash of the request that it discards after a day, and Speed Insights sends only the page's timings. The Content Security Policy the package sets through `nuxt-security` lets both scripts load: each plugin inserts its script from code the page already trusts (`'strict-dynamic'`).

## Rate-limit at the edge

A per-IP limit in the Nuxt server, such as `nuxt-security`'s, counts in each server instance's memory, and Vercel runs as many instances as traffic needs. The Vercel Firewall counts at the edge, once for the whole deployment. This site checks it from a server middleware with `@vercel/firewall`, for three endpoints, each against a rule of its own:

<table>
<thead>
  <tr>
    <th>
      Rule id
    </th>
    
    <th>
      What it counts
    </th>
    
    <th>
      Budget per IP
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        docs-assistant
      </code>
    </td>
    
    <td>
      The docs assistant's chat endpoint, <code>
        /__docus__/assistant
      </code>
    </td>
    
    <td>
      10 requests a minute
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        docs-mcp
      </code>
    </td>
    
    <td>
      The <a href="https://nuxt-backend.dev/docs/develop/agents/docs-mcp">
        docs MCP
      </a>
      
      : <code>
        /mcp
      </code>
      
       on the docs host, and its route on the site, <code>
        /api/docs-mcp
      </code>
    </td>
    
    <td>
      120 requests a minute
    </td>
  </tr>
</tbody>
</table>

The docs MCP's budget is the one its route keeps in memory, now held across instances, whichever of its two addresses a caller uses. A request the site makes to itself is not counted again: the docs host hands `/mcp` to the route in the same server, and the assistant reads the docs through it, each already counted as the request that made it.

```ts [server/middleware/0.firewall.ts]
import { checkRateLimit } from '@vercel/firewall'

// Each limited path, and the id of the Firewall rule that counts it.
const RULES: Record<string, string> = {
  '/__docus__/assistant': 'docs-assistant',
  '/api/docs-mcp': 'docs-mcp',
}

// What the check hands the Firewall: the host it asks, the IP it counts.
// It forwards every header it gets, and a rule needs none of the caller's
// cookies or tokens.
const FORWARDED = ['host', 'x-real-ip', 'x-forwarded-for', 'user-agent']

// The Firewall answers only on a deployment (see the config above).
const onVercel = Boolean(process.env.VERCEL) && process.env.VERCEL_ENV !== 'development'

export default defineEventHandler(async (event) => {
  if (!onVercel) return
  // The router ignores a trailing slash, so the lookup does too.
  const id = RULES[event.path.split('?')[0]!.replace(/\/+$/, '') || '/']
  if (!id) return
  const headers = new Headers()
  for (const name of FORWARDED) {
    const value = event.headers.get(name)
    if (value) headers.set(name, value)
  }
  let verdict
  try {
    verdict = await checkRateLimit(id, { headers })
  }
  catch {
    // Fail open: an outage of the limiter must not take the endpoint down.
    return
  }
  if (!verdict.rateLimited) return
  // A deny rule blocked the caller outright: not a budget to wait out.
  if (verdict.error === 'blocked') {
    setResponseStatus(event, 403)
    return { error: 'forbidden', message: 'This request was blocked.' }
  }
  setResponseStatus(event, 429)
  setResponseHeader(event, 'retry-after', '60')
  return { error: 'rate_limited', message: 'Too many requests. Try again in 60 seconds.' }
})
```

The `0.` keeps it first: Nitro runs a project's middleware in file-name order, and the middleware modules add after them, so the request is counted before the package's own handlers see it. `checkRateLimit` throws when the Firewall answers with anything it does not expect, so the `try` matters: without it, a hiccup of the limiter answers `500` on every limited path. The site's version also tells the docs host's `/mcp` from its own, skips the requests it makes to itself, and gives up after a second.

`checkRateLimit` asks the Firewall only when `NODE_ENV` is `production`, as it is in Vercel's functions; anywhere else it answers "not limited" and logs a warning. To see a rule work, deploy, then send the endpoint more requests in a minute than its budget: the one past it answers `429`.

Create each rule in the project's dashboard, under **Firewall**, **Configure**, then **New Rule**:

1. **If** `@vercel/firewall` (the rate limit id) equals the rule's id, `docs-assistant` for the first.
2. **Then** **Rate Limit**, fixed window, 60 seconds, the budget from the table, counted by IP, answering `429`.
3. **Save**, then **Publish**.

Until its rule exists, the Firewall answers that it does not know the id, and the request goes on. Off Vercel the middleware does nothing, and the per-IP limits in the Nuxt server hold alone: 10 a minute for the assistant, 120 for the docs MCP.

## Report errors

Install `@sentry/nuxt` and add Sentry's Vercel integration, which sets the names a build needs to upload its source maps (`SENTRY_AUTH_TOKEN`, `SENTRY_ORG`, `SENTRY_PROJECT`). It sets the DSN as `NEXT_PUBLIC_SENTRY_DSN`, a Next.js name the package reads as it is (set `MONITORING_DSN` to report to another project). The package's monitoring capability wires the SDK once a build sees the DSN: the site's own code never names it, and nothing in the repository holds one. [Monitoring](https://nuxt-backend.dev/docs/ship/operate/monitoring) has what each side reports, and how the backend reports through `MONITORING_DSN`, which `npx nuxt-backend env push --prod` sets on the deployment.

The SDK loads on every page. This site reports errors only, as Speed Insights already measures its pages, and leaves the SDK's tracing code out at build, some 22 kB of each page's initial JavaScript:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  sentry: { bundleSizeOptimizations: { excludeTracing: true, excludeDebugStatements: true } },
})
```

## Reach a model with no key

The site's docs assistant, Docus's own, reaches its model through the AI Gateway. On Vercel the deployment's OIDC token authenticates it, so the project holds no key; a local build turns the assistant on only with `AI_GATEWAY_API_KEY` in `.env.local`, and without either credential nothing of it renders. A token `vercel env pull` wrote into `.env.local` does not count: it expires within hours. It reads these docs through the [docs MCP](https://nuxt-backend.dev/docs/develop/agents/docs-mcp)'s route, in the same server, as the visitor.

Its endpoint is public and every question is a billed model call, so the site serves it from a route of its own, Docus's handler built from Docus's own helpers, with checks in front. It answers a JSON `POST` from the site's own pages only, so another site cannot spend the budget from its visitors' browsers. And it reads the conversation the chat sends as text alone: the question, at most 4,000 characters, and the newest turns before it, so a client cannot hand the model a `system` message, a page it claims a tool read, or a megabyte of history. A [budget](https://vercel.com/docs/ai-gateway/observability-and-spend/budgets) on the project caps what the gateway spends in a month.

The token belongs to code running in Vercel's functions, the Nuxt server. Your app's own model calls run in the backend, which reads `AI_GATEWAY_API_KEY` from the deployment's env instead: [Models](https://nuxt-backend.dev/docs/build/ai/models).

## Check the dashboard

Once per project, before the deploy that brings these in:

- **Analytics** and **Speed Insights** are on.
- **Settings**, **Security**: "Secure backend access with OIDC federation" is on (the default for a new project), and the team can use the AI Gateway.
- **Firewall**: the two rules above are published.
- **AI Gateway**, **Budgets**: a project budget, so a flood of questions stops at a sum you chose (`vercel ai-gateway budgets set project <name> --limit <usd> --refresh-period monthly`).
- **Integrations**: Sentry's integration is installed and linked to the project, and `MONITORING_DSN` holds the project's DSN.
- **Settings**, **Environment Variables**: "Enable access to System Environment Variables" is on, so the functions see `VERCEL` and `VERCEL_ENV` and check the Firewall.

## Related

- [Deploy to production](https://nuxt-backend.dev/docs/ship/deploy): the build command and the env split on any host
- [Deploy in one command](https://nuxt-backend.dev/docs/ship/deploy/one-command): writes the app's env into the Vercel project for you
- [Start from the deploy template](https://nuxt-backend.dev/docs/ship/deploy/template): a new app on Vercel with Convex through the Marketplace
- [Monitoring](https://nuxt-backend.dev/docs/ship/operate/monitoring): what each side reports, and the health endpoint
- [Rate limiting](https://nuxt-backend.dev/docs/ship/security/rate-limits): the backend's own limits, per user and per address
- [Docs MCP](https://nuxt-backend.dev/docs/develop/agents/docs-mcp): the server the docs assistant reads


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
