Skip to main content
Platforms

Vercel

Run Rivet workers on Vercel.

Vercel is a serverless platform: there is no long-lived process, so the control plane calls your /api/rivet endpoint to start actors. The deployment URL has to be public and registered.

Requirements

Steps

Mount the route handler

The handler sets maxDuration so Vercel does not cut long-lived actor requests short.

import { toNextHandler } from "@rivetkit/next-js";
import { registry } from "@/rivet/registry";

export const maxDuration = 300;

export const { GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS } = toNextHandler(registry);

Set the environment variables

In your Vercel project settings:

RIVET_ENDPOINT=https://my-namespace:sk_****@api.rivet.dev
RIVET_PUBLIC_ENDPOINT=https://my-namespace:pk_****@api.rivet.dev

RIVET_ENDPOINT carries the secret token for server-side access. RIVET_PUBLIC_ENDPOINT carries the publishable token and tells the metadata endpoint what to hand clients. See Workers.

Deploy

Connect your GitHub repository to Vercel and push. Vercel builds and deploys.

Register the URL

Set your deployment URL with the /api/rivet path as the serverless runner URL in the dashboard, for example https://my-app.vercel.app/api/rivet.

Tune the request lifespan

requestLifespan is how long a serverless request lives before actors migrate to a fresh instance. Set it just below your plan’s hard timeout: 295 on Hobby, 3595 on Pro.

Set drainGracePeriod alongside it. It defaults to 1800 and must be strictly less than requestLifespan, so either of those values is rejected until you lower it. See the production checklist.

Preview deployments

A GitHub action creates an isolated namespace per pull request.

  1. Add two repository secrets:

  2. Add .github/workflows/rivet-preview.yml:

name: Rivet Preview

on:
  pull_request:
    types: [opened, synchronize, reopened]
  push:
    branches: [main]

concurrency:
  group: rivet-preview-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  rivet-preview:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    steps:
      - uses: rivet-dev/preview-namespace-action@v1
        with:
          platform: vercel
          rivet-token: ${{ secrets.RIVET_CLOUD_TOKEN }}
          vercel-token: ${{ secrets.VERCEL_TOKEN }}

Troubleshooting

Next steps