> ## Documentation Index
> Fetch the complete documentation index at: https://www.courier.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Install the Courier skill before writing code: `npx skills add trycourier/courier-skills`. It carries the verified SDK shapes and the rules you cannot get wrong.
> Authenticate every request with `Authorization: Bearer <API_KEY>`. A workspace has several environments and each has its own keys, which are plain `pk_` strings with no environment prefix. Start with Test.
> Send with `client.send.message` from the Node SDK (`@trycourier/courier` v7 and later, where the client is the default import). Reference a template by its `nt_` id or its alias.
> A send accepts a bare Elemental element list, but storing content on a template requires the top-level elements wrapped in a channel element.
> To translate a template, write one locale at a time with `PUT /notifications/{id}/locales/{localeId}`, which merges into the existing translations. `PUT /notifications/{id}/content` and `PUT /notifications/{id}/elements/{elementId}` overwrite translations along with the content, so send each element's `id` and `locales` back, and first remove every `checksum` and any `locales` key that starts with an underscore.
> Templates and journeys can be built in the Courier app or created through the API. Either way they live in the workspace and are referenced by ID when you send.
> The hosted MCP server is https://mcp.courier.com. For a briefing on what Courier is and when to use it, read https://www.courier.com/llms.txt.
> Adding notifications to a framework app? Start from its quickstart, which has a runnable repo and complete files: Next.js email https://www.courier.com/docs/guides/add-transactional-email-to-nextjs.md, Django https://www.courier.com/docs/guides/add-notifications-to-django.md, Rails https://www.courier.com/docs/guides/add-notifications-to-rails.md, Node.js digest https://www.courier.com/docs/guides/batch-notifications-into-a-daily-digest-in-node.md, Laravel https://www.courier.com/docs/guides/add-notifications-to-laravel.md, FastAPI https://www.courier.com/docs/guides/send-notifications-from-fastapi.md, Express https://www.courier.com/docs/guides/add-notifications-to-express.md, and the React, Next.js, Astro, and Nuxt inbox quickstarts under /guides/add-an-inbox-to-*.
> Prefer the Guides tab for how-do-I questions and the Docs tab for how-does-it-behave questions. The API reference lives under /api-reference.

# Add a notification inbox to a Nuxt app

> Add a real-time notification inbox to a Nuxt app with the Vue CourierInbox component and one server route that mints a JWT. Clone the finished app.

Give your Nuxt app a real-time notification inbox with Courier's Vue `<CourierInbox>` and one server route that mints its token. Courier hosts the feed, so you run no database or websocket server for it.

```ts theme={null}
import Courier from "@trycourier/courier";

// Reads COURIER_API_KEY from the environment.
const client = new Courier();

const { requestId } = await client.send.message({
  message: {
    to: { user_id: "sarah-bennett" },
    routing: { method: "single", channels: ["inbox"] },
    content: { title: "Hello from Courier", body: "Your Nuxt app has an inbox." },
  },
});

console.log(`Sent. Request id: ${requestId}`);
```

Save it as `first-send.mts` and run it with your key:

```bash theme={null}
npm install @trycourier/courier && COURIER_API_KEY=YOUR_COURIER_API_KEY npx --yes tsx first-send.mts
```

Every API key ships with the Courier Inbox provider, so the message waits in Sarah's inbox until the app below signs her in. Look up the request id in [Courier Logs](https://app.courier.com/logs).

> [card] [courier-nuxt-quickstart](https://github.com/trycourier/courier-nuxt-quickstart)
>
> The finished Nuxt app from this guide, ready to clone and run.

## Build this with a coding agent

Paste this prompt into Claude Code, Cursor, or Codex from your Nuxt project root to have a coding agent add a Courier inbox:

```text theme={null}
Add a real-time notification inbox to this Nuxt app with Courier.
Follow https://www.courier.com/docs/guides/add-an-inbox-to-nuxt.md and the reference app at https://github.com/trycourier/courier-nuxt-quickstart.
Use @trycourier/courier in a Nuxt server route that mints the inbox JWT, and read COURIER_API_KEY from the environment.
Take the user id from the session, never from the request, and render <CourierInbox> from @trycourier/courier-vue.
When done, add a send script like the reference app's scripts/send.ts, run it, and show me the request id.
```

Install the Courier skill with `npx skills add trycourier/courier-skills`, and connect the [Courier MCP server](https://www.courier.com/docs/resources/mcp.md) so the agent can check Logs itself.

### Rules for AI agents

* Use `@trycourier/courier` and `COURIER_API_KEY` only in `server/` and `scripts/`. The browser gets `@trycourier/courier-vue` and a scoped JWT.
* Take the token's user id from the session, never from the request.
* Scope each token `user_id:${userId} inbox:read:messages inbox:write:events`, and always set `expires_in`.
* Call `courier.shared.signIn({ userId, jwt: token })` in `onMounted`, with no `<ClientOnly>` wrapper.
* Send with `routing: { method: "single", channels: ["inbox"] }` to the token's `user_id`.

## What you'll build

This Nuxt 4 app shows one user's Courier Inbox and fills it from a script:

* **A Nuxt server route**, `GET /api/courier-token`, that mints a JWT scoped to one user
* **A live `<CourierInbox>`** from [`@trycourier/courier-vue`](https://www.courier.com/docs/sdk-libraries/courier-vue-web)
* **A send script** that fills that user's inbox

Tested in November 2026 with Nuxt 4.4, `@trycourier/courier-vue` 1.1.5, `@trycourier/courier` 10.2.0, and Node.js 22.18.

## Prerequisites

### For the first send

* [A Courier account](https://app.courier.com/signup)
* [A Courier API key](https://app.courier.com/settings/api-keys)
* Node.js 22.18 or newer

### For the full build

* A Nuxt 4 app, or a new one from the first step below
* A signed-in user from your session, such as nuxt-auth-utils

## Clone the finished Nuxt app

Clone the Courier Nuxt quickstart and run it with your own key:

```bash theme={null}
git clone https://github.com/trycourier/courier-nuxt-quickstart.git
cd courier-nuxt-quickstart
npm install
cp .env.example .env   # add COURIER_API_KEY
npm run dev
```

The steps below build these files:

| File | What it does |
| :- | :- |
| `package.json` | Pins Nuxt 4.4 and adds Courier and a `send` script |
| `.env` | Holds `COURIER_API_KEY` |
| `shared/demo-user.ts` | The demo user id |
| `server/api/courier-token.get.ts` | Mints the inbox JWT |
| `app/components/NotificationInbox.vue` | Signs in and renders `<CourierInbox>` |
| `app/app.vue` | The page that holds the inbox |
| `scripts/send.ts` | Sends a test inbox message |

## Install the Courier packages in your Nuxt app

To add Courier to a new Nuxt app, scaffold one first and pin Nuxt 4.4:

```bash theme={null}
npx --yes nuxi@3 init my-nuxt-app --template minimal --packageManager npm --gitInit --no-install
cd my-nuxt-app
npm install nuxt@~4.4.8 vue-router@~5.4.0
```

Newer Nuxt and `nuxi` need Node 22.21, so the `nuxi@3` scaffold and these pins keep the app on Node 22.18. Drop them on a newer Node.

Then add Courier's Vue package for the browser and its Node package for the server:

```bash theme={null}
npm install @trycourier/courier @trycourier/courier-vue
npm install --save-dev tsx @types/node typescript@^5.9.3 vue-tsc
```

`tsx` runs the send script, and the other dev packages run `nuxt typecheck`.

Put your key in `.env`, which `nuxt dev` loads:

```bash .env theme={null}
COURIER_API_KEY=YOUR_COURIER_API_KEY
```

## Mint the inbox token in a Nuxt server route

The Nuxt server route calls Courier's [`POST /auth/issue-token`](https://www.courier.com/docs/api-reference/authentication/create-a-jwt) and returns a JWT scoped to one user.

```ts server/api/courier-token.get.ts lines theme={null}
import Courier from "@trycourier/courier";
import { DEMO_USER_ID } from "#shared/demo-user";

// Your API key signs the JWT, so this runs on the server and the key never reaches the browser.
export default defineEventHandler(async (event) => {
  const apiKey = process.env.COURIER_API_KEY;
  if (!apiKey) {
    throw createError({
      statusCode: 500,
      statusMessage: "COURIER_API_KEY is not set. Add it to .env and restart the server.",
    });
  }

  // Read the user from your session here, never from the request: a caller
  // who can name any user id can read that user's inbox. With nuxt-auth-utils:
  // const { user } = await requireUserSession(event); const userId = user.id;
  const userId = DEMO_USER_ID;

  const client = new Courier({ apiKey });

  try {
    const { token } = await client.auth.issueToken({
      scope: `user_id:${userId} inbox:read:messages inbox:write:events`,
      // Always set this. Omitting it mints a token that never expires.
      expires_in: "1 day",
    });

    return { userId, token };
  } catch (cause) {
    // Log the real error on the server, and give the browser a message to show.
    console.error("[courier] issueToken failed:", cause);
    throw createError({
      statusCode: 502,
      statusMessage: "Courier didn't issue a token. Check COURIER_API_KEY.",
    });
  }
});
```

**Take the user from your session, never from the request.** A route that accepts a user id lets any caller read any user's inbox. The two `inbox:` scopes run the feed, and [Scopes](https://www.courier.com/docs/in-app/authenticate-users.md#scopes) lists what preferences add.

Nitro reads `process.env` per request, so the key stays out of the build output. The demo user id lives in [`shared/demo-user.ts`](https://github.com/trycourier/courier-nuxt-quickstart/blob/main/shared/demo-user.ts), which the send script shares:

> [accordion] shared/demo-user.ts
>
> ```ts shared/demo-user.ts theme={null}
> // Pinned so the token route and send script agree without auth. A real app reads the session.
> export const DEMO_USER_ID = "sarah-bennett";
> ```

## Render the Vue notification inbox in Nuxt

The Nuxt component fetches the token, signs in with `@trycourier/courier-vue`, and renders `<CourierInbox>`.

```vue app/components/NotificationInbox.vue lines theme={null}
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { CourierInbox, useCourier } from "@trycourier/courier-vue";

const courier = useCourier();
const error = ref("");

// onMounted runs only in the browser, so sign-in happens after hydration, never during SSR.
onMounted(async () => {
  try {
    const { userId, token } = await $fetch("/api/courier-token");
    courier.shared.signIn({ userId, jwt: token });
  } catch (cause) {
    error.value = cause instanceof Error ? cause.message : "Sign-in failed.";
  }
});
</script>

<template>
  <p v-if="error" class="error">{{ error }}</p>
  <!-- The inbox takes its height from this prop, or from its parent. -->
  <CourierInbox v-else height="32rem" />
</template>
```

**You don't need `<ClientOnly>`.** The server renders an empty `<courier-inbox>` tag, and the browser turns it into the live feed on hydration.

Nuxt auto-imports components, so [`app/app.vue`](https://github.com/trycourier/courier-nuxt-quickstart/blob/main/app/app.vue) uses it by name:

> [accordion] app/app.vue
>
> ```vue app/app.vue theme={null}
> <template>
>   <main style="max-width: 40rem; margin: 2rem auto; font-family: system-ui, sans-serif">
>     <h1>Courier Inbox</h1>
>     <NotificationInbox />
>     <p>Empty? Run <code>npm run send</code> in another terminal. The message arrives here without a refresh.</p>
>   </main>
> </template>
> ```

## Send a test message to the Nuxt inbox

`scripts/send.ts` sends one Courier message to the Nuxt demo user's inbox to prove the round trip. Add an `npm run send` script that loads `.env`:

```bash theme={null}
npm pkg set scripts.send="tsx --env-file=.env scripts/send.ts"
```

```ts scripts/send.ts lines theme={null}
import Courier from "@trycourier/courier";
import { DEMO_USER_ID } from "../shared/demo-user";

// Run it while `npm run dev` has the page open, to watch the message arrive.
const apiKey = process.env.COURIER_API_KEY;
if (!apiKey || apiKey === "YOUR_COURIER_API_KEY") {
  console.error("COURIER_API_KEY is not set. Add it to .env.");
  process.exit(1);
}

const client = new Courier({ apiKey });

const { requestId } = await client.send.message({
  message: {
    to: { user_id: DEMO_USER_ID },
    // `inbox` is a channel like `email`, and listing it puts the message in the feed.
    routing: { method: "single", channels: ["inbox"] },
    content: { title: "Your report is ready", body: "The export you asked for has finished." },
  },
});

console.log(`Sent to ${DEMO_USER_ID}. Request id: ${requestId}`);
console.log("It's already in the inbox at http://localhost:3000");
```

For layouts and per-channel variants, send a [template](https://www.courier.com/docs/design/templates/overview.md) id instead of `content`.

## Verify

Load the Nuxt inbox, send one Courier message, and watch it arrive. In the cloned repo, run `npm run dev` and open `localhost:3000`, where the inbox renders signed in and empty. Then run `npm run send` in another terminal to print a request id. The message appears without a refresh, and the unread count moves.

In your own app, first set `DEMO_USER_ID` to your signed-in user, then load the page and run `npm run send`. Look up the request id in [Courier Logs](https://app.courier.com/logs) to follow the send to the inbox.

| What you see | Fix |
| :- | :- |
| `COURIER_API_KEY is not set` | Add it to `.env` and restart `npm run dev` |
| `Courier didn't issue a token` | Copy the key again from [API Keys](https://app.courier.com/settings/api-keys) |
| Empty inbox after a send | Match the send's `user_id` to the token's |

## Go to production with Courier

Courier is notification infrastructure for humans and AI agents. [Go live](https://www.courier.com/docs/guides/go-live.md) covers moving your Nuxt app from Test to Production:

* **Set the key on your host.** Set `COURIER_API_KEY` there, because the built `.output/server/index.mjs` doesn't read `.env`.
* **Refresh tokens.** Match `expires_in` to your session, then [mint a new token and sign in again](https://www.courier.com/docs/in-app/authenticate-users.md#5-refresh-tokens) before it expires.
* **Make retries safe.** Pass an idempotency key on sends that can retry, and [retry with it safely](https://www.courier.com/docs/reference/api-overview.md#retry-a-request-safely).

| Task | A notifications table you build | With Courier |
| :- | :- | :- |
| Store and list messages | A table and an API | Courier hosts the feed |
| Live updates | A websocket server | Built into `<CourierInbox>` |
| Read and archive state | Columns and endpoints | [Synced across devices](https://www.courier.com/docs/in-app/how-the-inbox-behaves.md) |
| Email or push for the same event | Another provider SDK | Add it to `routing.channels` |

## FAQ

> [accordion] Can I use this in a plain Vue app without Nuxt?
>
> A plain Vue app uses the same `@trycourier/courier-vue` component and `signIn` call, with the token route on your existing backend. See [Add an inbox](https://www.courier.com/docs/in-app/add-an-inbox.md?lang=Vue).

> [accordion] How do I add a notification bell to a Vue app?
>
> A Courier notification bell in Vue is `<CourierInboxPopupMenu />` from `@trycourier/courier-vue`, the same feed behind an icon with an unread badge. See [Render as a popup menu](https://www.courier.com/docs/in-app/add-an-inbox.md#render-as-a-popup-menu).

> [accordion] Is the JWT safe to expose to the browser?
>
> A Courier inbox JWT is built for the browser, because it's scoped to one user and expires. The API key that signs it stays on the server.

> [accordion] Why is the inbox empty when the send reported success?
>
> A Courier inbox feed is filtered by tenant, so signing in with a `tenantId` hides messages sent without one. See [Scope the inbox to a tenant](https://www.courier.com/docs/in-app/send-to-the-inbox.md#scope-the-inbox-to-a-tenant).
