---
title: Quickstart
description: Install Agentside, describe your markdown twins and mount the handler in front of your app.
sidebar:
  order: 1
---

## Install

```bash
npm install @usenotra/agentside
```

Agentside ships ESM with TypeScript types and has `effect` as its only peer dependency.

There are two ways to set it up. If your pages render on demand, or your twins come from a CMS, describe them as routes and mount the handler as shown below. If your pages are prerendered, skip to [Convert a static build](#convert-a-static-build) and you won't write any markdown.

## Describe your twins

Create one module that owns the config. Each key in `routes` is a page path and each value is the source of its markdown twin.

```ts agentside.ts
import { agentside, remote } from "@usenotra/agentside";

export const twins = agentside({
  routes: {
    "/": "# Acme\n\nAcme sends invoices your customers actually pay.",
    "/pricing": () => renderPricingMarkdown(),
    "/blog/[slug]": ({ params }) => getPost(params.slug)?.markdown ?? null,
    "/docs/[...path]": remote(({ params }) => `https://cms.acme.dev/docs/${params.path}.md`),
  },
  skip: ["/api", "/assets"],
});
```

`agentside()` validates the routes and builds the cache synchronously, so create it once at module scope and reuse it for every request.

## Mount the handler

`handle(request, next)` takes a fetch `Request` and a function that renders your page. It returns the markdown twin when the request asks for one and otherwise calls `next()` and decorates the HTML response.

```ts
const response = await twins.handle(request, () => renderPage(request));
```

The [framework guides](/docs/frameworks) show where this line goes in each framework.

## Try it

```bash
curl -i http://localhost:3000/pricing.md
curl -i -H "Accept: text/markdown" http://localhost:3000/pricing
curl -i -A "GPTBot/1.2" http://localhost:3000/pricing
curl -I http://localhost:3000/pricing
```

The first three return `Content-Type: text/markdown` with an `X-Agentside-Variant` header. The last returns your HTML page with `Link: </pricing.md>; rel="alternate"; type="text/markdown"`.

## Serve a twin directly

When you already route `.md` URLs yourself, call `serve` instead. It always treats the request as an explicit markdown request and answers with the twin, a markdown 404 or a 503.

```ts
export const GET = (request: Request) => twins.serve(request);
```

Pass a pathname as the second argument when the request URL differs from the page path, for example `twins.serve(request, "/pricing")`.

## Convert a static build

For a static site, run `prerenderHtml` after your framework's build. It converts each page's `<main>` to a `.md` file next to the HTML and writes `llms.txt` and `llms-full.txt`.

```ts scripts/agentside.ts
import { prerenderHtml, vercelRoutes } from "@usenotra/agentside/build";

const pages = await prerenderHtml({
  dir: "dist",
  siteUrl: "https://acme.dev",
  llms: { title: "Acme", description: "Acme sends invoices your customers actually pay." },
});

await Bun.write("vercel.json", JSON.stringify(vercelRoutes(pages.map((page) => page.path)), null, 2));
```

`vercelRoutes` adds the CDN rules that send `Accept: text/markdown` and known AI agents to the `.md` files. Add `data-ai-ignore` to anything agents should skip. [Static sites](/docs/static-sites) covers the conversion rules, adapters that write `.vercel/output` and mixing both approaches.

