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

# Express

> Verify AI agent tokens and authenticate requests in Express.js using @agentonboard/sdk/express.

`@agentonboard/sdk/express` exports `requireAgentAccount(req, res, options)` for Express applications. Because Express handlers write responses via `res`, the adapter accepts both `req` and `res` and writes `401`, `403`, or `500` responses directly when verification fails.

## Copy-paste agent prompt

```text theme={null}
Integrate AgentOnboard into this Express repository.

1. Inspect the codebase and install `@agentonboard/sdk`.
2. Read these docs before editing:
   - https://docs.agentonboard.xyz/express.md
   - https://docs.agentonboard.xyz/verify.md
   - https://docs.agentonboard.xyz/accounts.md
   - https://docs.agentonboard.xyz/auth-md.md
3. Ask me three questions before writing code:
   - Which auth provider or users table should `resolveAccount` query?
   - Should unknown emails return `403 ACCOUNT_REQUIRED` (reject) or create an account on `POST /api/signup`?
   - What is the production Domain hostname (e.g. `notes.com` or `api.notes.com`)?
4. Implement the integration following these invariants:
   - Call `requireAgentAccount(req, res, options)` from `@agentonboard/sdk/express`.
   - Hardcode `audience` to the normalized production Domain.
   - Normalize emails with `normalizeEmail(email)` from `@agentonboard/sdk` (never raw `email.toLowerCase()`).
   - Serve the discovery file at both `/auth.md` and `/.well-known/auth.md` with matching `## Audience` and `403` instructions.
5. Verify against localhost by minting a test token with `POST https://agentonboard.xyz/api/v1/token/exchange` and testing `403 ACCOUNT_REQUIRED`, `200 OK`, and `401 INVALID_SIGNATURE`.
```

***

## 1. Install the SDK

> [tab] npm
>
> ```bash theme={null}
> npm install @agentonboard/sdk
> ```

> [tab] pnpm
>
> ```bash theme={null}
> pnpm add @agentonboard/sdk
> ```

> [tab] yarn
>
> ```bash theme={null}
> yarn add @agentonboard/sdk
> ```

> [tab] bun
>
> ```bash theme={null}
> bun add @agentonboard/sdk
> ```

***

## 2. Guard your Express route

```ts title="api/notes.ts" theme={null}
import express from "express";
import { normalizeEmail } from "@agentonboard/sdk";
import { requireAgentAccount } from "@agentonboard/sdk/express";

const app = express();
app.use(express.json());

// Simulated database lookup
const accounts = new Map([["ada@example.com", "user_123"]]);

app.post("/api/notes", async (req, res) => {
  const session = await requireAgentAccount(req, res, {
    audience: "notes.com",
    resolveAccount: async ({ email }) => {
      return accounts.get(normalizeEmail(email)) ?? null;
    },
  });

  // If verification failed or user was not found, status and JSON body
  // were already written to `res`. Return immediately.
  if (!session.ok) return;

  res.json({ success: true, created_by: session.user });
});

app.listen(3000);
```

> [!NOTE]
>
> **Why Express takes both `req` and `res`**
>
> Express ignores a route handler's return value. Passing `res` into `requireAgentAccount` ensures `401`, `403`, and `500` JSON responses are sent before the promise resolves, so handlers only need `if (!session.ok) return;`.

***

## 3. Test with curl

Mint a 5-minute test token using [`POST /api/v1/token/exchange`](https://docs.agentonboard.xyz/api/token-exchange) and call your Express route:

```bash theme={null}
# Mint a 5-minute test token
TOKEN=$(curl -s -X POST https://agentonboard.xyz/api/v1/token/exchange \
  -H "Authorization: Bearer aon_live_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{"audience":"notes.com"}' \
  | jq -r '.token')

# Test your Express endpoint
curl -i -X POST http://localhost:3000/api/notes \
  -H "Authorization: Bearer $TOKEN"
```

***

> [card] [Accounts & Agent Signup](https://docs.agentonboard.xyz/accounts.md)
>
> Resolve App Accounts or add explicit agent signup at POST /api/signup.

> [card] [Testing & Production](https://docs.agentonboard.xyz/testing-and-production.md)
>
> Run all six curl checks and review JWKS caching.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.