Deploying to Vercel
Deploy your Next.js Rivet app to Vercel.
This guide assumes a Next.js app.
Prerequisites
- Vercel account
- A Next.js Rivet app
- Access to the Rivet Cloud or a self-hosted Rivet Engine
Steps
Set up your project
Follow the Next.js Quickstart to set up your project.
Verify Your Project Structure
Your Next.js project should have the following structure:
src/app/api/rivet/[...all]/route.ts: RivetKit route handlersrc/rivet/registry.ts: Actor definitions and registry
The route handler sets maxDuration to extend the serverless function timeout so long-lived actor requests are not cut 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 Environment Variables
Set RIVET_ENDPOINT and RIVET_PUBLIC_ENDPOINT in your Vercel project settings using the URL auth format:
RIVET_ENDPOINT=https://my-namespace:sk_****@api.rivet.dev
RIVET_PUBLIC_ENDPOINT=https://my-namespace:pk_****@api.rivet.dev
RIVET_ENDPOINT uses the secret token for server-side access. RIVET_PUBLIC_ENDPOINT uses the publishable token and tells the metadata endpoint what connection info to provide to clients.
Deploy to Vercel
- Connect your GitHub repository to Vercel
- Vercel will deploy your app
Configure Preview Deployments (Recommended)
Add a GitHub action to automatically create isolated Rivet namespaces for each PR:
-
Add these secrets to your GitHub repository:
RIVET_CLOUD_TOKEN: Get from Rivet Dashboard → Settings → Advanced → Cloud API TokensVERCEL_TOKEN: Get from Vercel Account Settings
-
Create
.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 }}