# Set up Relia in a Next.js app

> One command adds Relia to a Next.js app, including apps deployed on Vercel. It writes instrumentation.ts and records every server request with Next's own route names.

Section: Set up your stack · Page: https://tryrelia.com/docs/nextjs-setup · Last checked against the product: 2026-11-01
Video walkthrough: https://youtu.be/v97-F6jftRE

This page sets Relia up by hand from a terminal. To have your AI assistant do it instead, see [Set up Relia with your AI assistant](https://tryrelia.com/docs/setup-with-ai-assistant.md).

## Before you start

- A Relia account ([Create your account](https://tryrelia.com/docs/create-account.md)).
- A terminal open in your Next.js app's folder.

## Steps

1. **Run the setup:**

   ```bash
   npx relia-sdk@latest init
   ```

   Always use `relia-sdk`: the npm package called `relia` belongs to someone else.

2. **Sign in.** Choose the browser option, copy the token from the **CLI Authentication** page, and paste it back into the terminal.

3. **Choose what to set up.** It detects your Next.js app. Choose **Everything Relia found here** (your Next.js server, plus AI SDK calls if your app uses the Vercel AI SDK), or pick one kind.

4. **Pick your Relia project**, or create one right there.

5. **Check what it wrote:**
   - A new `instrumentation.ts` (inside `src/` when your app lives there). It starts Relia on your server, with your project's id and key inside.
   - `relia-sdk` added to your `package.json`.
   - The browser side is a separate choice: run the setup again and choose **Session & User journey monitoring**. See [Watch your web app](https://tryrelia.com/docs/web-app-setup.md).

   > **Note:** if you already have an `instrumentation.ts`, it is left alone and the lines to add are printed instead.

6. **Next.js 13 or 14 only:** turn the instrumentation hook on in `next.config`:

   ```js
   experimental: { instrumentationHook: true }
   ```

7. **Restart your app** and open a page or call one of its API routes. The console says `tracing initialized`.

## Deploying on Vercel

Nothing to add. Serverless mode switches on by itself, and your project's id and key are already inside `instrumentation.ts`, so the server needs no extra environment variable.

## What Relia records

- One entry per request, with Next's own route name, for example `GET /api/orders/[id]`.
- Errors with stack traces that point at your source files (for example `app/api/orders/[id]/route.ts:9`), not compiled `.next` chunks.
- Outgoing calls (fetch) and database calls inside each request.
- Calls made with the Vercel AI SDK (`streamText`, `generateText`), with no code change. See [Monitor AI in your product](https://tryrelia.com/docs/ai-in-your-product.md).

## Check it worked

Open your project in Relia and go to the **Setup** tab. **Requests from your server** changes from *Not yet* to *Arriving*, usually within a minute. Your requests and errors appear under **APIs**.

## If something's wrong

- **Still "Not yet" after a few minutes:** restart the app once more, then see [Relia shows no data](https://tryrelia.com/docs/no-data.md).
- **Next.js 13 or 14 and nothing arrives:** check the `instrumentationHook` setting from step 6.

## Next

- [Identify your users](https://tryrelia.com/docs/identify-users.md)
- [Teach Relia what matters](https://tryrelia.com/docs/teach-relia.md)

---
All Relia docs for AI assistants: https://tryrelia.com/llms.txt (index) · https://tryrelia.com/llms-full.txt (everything in one file)
