# Serve AI agents a markdown version of every page.

Agentside is a TypeScript library that answers ChatGPT, Claude and Perplexity with a markdown twin of the page they asked for, and it lets you A/B test what each agent reads.

`npm install @usenotra/agentside`

[Read the quickstart](https://useagentside.com/docs/quickstart) [View the source on GitHub](https://github.com/usenotra/agentside)

A browser requests /pricing

```http
GET /pricing
Accept: text/html
User-Agent: Mozilla/5.0 (Macintosh) Safari/605.1.15

200 OK
Content-Type: text/html; charset=utf-8
Link: </pricing.md>; rel="alternate"; type="text/markdown"
Vary: Accept, User-Agent

<!doctype html>
<html lang="en">
  <head>
    <title>Pricing</title>
    <link rel="stylesheet" href="/assets/app.css" />
  </head>
  <body>
    <div id="app">
```

GPTBot requests the same URL

```http
GET /pricing
Accept: */*
User-Agent: GPTBot/1.2

200 OK
Content-Type: text/markdown; charset=utf-8
X-Markdown-Tokens: 212
Vary: Accept, User-Agent

# Pricing

Acme sends invoices your customers actually pay.

| Plan    | Price         | Invoices  |
| ------- | ------------- | --------- |
| Starter | $0 a month    | 20        |
| Team    | $49 a month   | Unlimited |
```

## One URL serves people and agents.

Agentside reads the path, the Accept header and the user agent of each request, and then it decides whether the visitor gets your HTML page or its markdown twin.

### Content negotiation

A request gets markdown when its path ends in .md, when its Accept header mentions text/markdown or when its user agent belongs to a known AI agent, and every other request gets your HTML page.

Requests to /pricing

Six requests and the response each one receives

| Request | Response |
| --- | --- |
| GET /pricing.md | text/markdown |
| Accept: text/markdown | text/markdown |
| User-Agent: GPTBot/1.2 | text/markdown |
| Accept: text/html | text/html with a Link header |
| Accept: application/json | 406 Not Acceptable |
| POST /pricing | Passed to your app |

### Agent detection

Agentside matches the user agent against a list of known AI agents and tags each match with a vendor and a purpose, and you can target variants at any of those tags.

Known agents

A sample of the list that ships with the package

| Agent | Vendor | Purpose |
| --- | --- | --- |
| ChatGPT-User | OpenAI | User action |
| OAI-SearchBot | OpenAI | Search |
| GPTBot | OpenAI | Training |
| Claude-User | Anthropic | User action |
| ClaudeBot | Anthropic | Training |
| PerplexityBot | Perplexity | Search |
| Google-Extended | Google | Training |

### Variants per agent

A route can carry a list of variants that target agents by name, vendor or purpose. Agentside serves the first variant that matches and names it in the X-Agentside-Variant header.

Variants on /pricing

Agentside checks them from top to bottom

| Variant | Served to | Source |
| --- | --- | --- |
| pricing-search | Search agents | pricing-v2.md on the CMS |
| pricing-short | ChatGPT-User and Claude-User | shortPricing |
| control | Every other agent | renderPricingMarkdown() |

### Fallbacks for broken twins

Each source runs inside Effect with retries and a timeout. When a twin fails, a negotiated request gets your HTML page and an explicit .md request gets a markdown 404 or 503.

When a twin fails

What the agent receives in each case

| Situation | Response |
| --- | --- |
| The variant source throws | The control twin |
| The twin render throws | Your HTML page with a 200 |
| The page has no twin | Your HTML page with a 200 |
| A .md URL has no twin | 404 as markdown |
| A .md render throws | 503 with Retry-After |
| A remote source hangs | 503 after the timeout |

## Describe your twins in one file.

A route maps a path to a source, and the handler takes a standard Request and returns a standard Response, which lets the same config run in server middleware, an edge worker or a plain fetch handler.

### Routes and sources

A source is a string, a function that returns markdown or a remote URL that Agentside fetches with a timeout and retries. When a function returns null the page has no twin, and Agentside passes the request to your app.

[Read about routes and sources](https://useagentside.com/docs/routes)

middleware.ts

```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"],
});

export const onRequest = (context, next) => twins.handle(context.request, () => next());
```

### Test what each agent reads

The onServe callback hands you an exposure event for each read, with the path, the variant, the agent and the response status. A GEO team can join those events with the citations and answers that follow.

[Read about A/B variants](https://useagentside.com/docs/variants)

variants

```ts
agentside({
  routes: { "/pricing": () => renderPricingMarkdown() },
  variants: {
    "/pricing": [
      { id: "pricing-search", purposes: ["search"], source: remote("https://cms.acme.dev/pricing-v2.md") },
      { id: "pricing-short", agents: ["ChatGPT-User", "Claude-User"], source: shortPricing },
    ],
  },
  onServe: (event) => analytics.track("agent_read", event),
});
```

onServe event

```json
{
  "path": "/pricing",
  "variant": "pricing-search",
  "agent": { "name": "OAI-SearchBot", "vendor": "OpenAI", "purpose": "search" },
  "status": 200,
  "cached": true,
  "durationMs": 0.21
}
```

## Benchmarks against Dualmark and a homegrown setup.

Agentside and Dualmark 0.11 ran through the same harness on Bun 1.4 and an Apple M5, and lower numbers are better. The AI Inbx column is their own measurement of a homegrown setup on a 39 KB pricing page, so treat it as indicative.

| Scenario | Agentside | AI Inbx (homegrown) | Dualmark by Dodo Payments |
| --- | --- | --- | --- |
| Agent gets a markdown page, cached | 2.76 µs | 2.89 µs | 38.1 µs (no cache) |
| Agent gets a markdown page, cache off | 16.2 µs | 3.3 ms | 38.1 µs |
| Agent detection | ~50 ns | 160 to 240 ns | ~500 ns |
| Browser request getting HTML | 1.40 µs | 20.5 µs | 2.03 µs |
| Agent hits a page whose render throws | Serves the HTML page | 500 | Request throws |
| Agent hits a page with no markdown version | Serves the HTML page | HTML page, or 406 for `Accept: text/markdown` alone | 404 |
| Prerender twins to static files | `agentside/build`, fails the build on errors | Yes, fails the build on errors | Next.js static params only |

A network round trip to your server takes thousands of times longer than any number in this table, so these latencies will not change how fast an agent gets your page, and we optimized them anyway. You can [run the benchmark harness yourself](https://github.com/usenotra/agentside#benchmarks) to check them.

## Questions people ask before they install.

Which frameworks does Agentside run in?

The handler takes a standard Request and returns a standard Response, so it runs in TanStack Start, Astro, Hono, Next.js middleware, Bun and Workers, and the docs have a guide for each of them.

Do I have to write the markdown by hand?

You can skip that step on a static site, because prerenderHtml reads every built .html file, converts the main element to markdown and writes the result next to the page. When you pass an llms option, the same call also writes llms.txt and llms-full.txt for the whole site.

What changes for people who visit in a browser?

Browsers get your HTML page untouched, and when a twin exists the response carries a Link header that points agents at the markdown version of the same URL.

How does Agentside recognise an AI agent?

It matches the user agent against a built-in list that includes GPTBot, ClaudeBot and PerplexityBot, and it tags each match with a vendor and a purpose. A client that is missing from the list still gets markdown when it sends Accept: text/markdown or requests a .md URL.

Do I need to know Effect to use it?

The default import is a plain function that takes a Request, so you can use Agentside without writing any Effect code. Teams that want the Effect program and its typed errors can import them from @usenotra/agentside/effect.

How do I move over from Dualmark?

The migration guide in the docs maps a Dualmark route handler and middleware to Agentside routes and a single handle call, which removes the rewrite, the internal /md route and generateStaticParams.

What does Agentside cost?

Agentside is free and open source under the MIT license, and you install it from npm as @usenotra/agentside.

## Start serving markdown to the agents that read your site.

The quickstart takes you from the install command to a first markdown response, and the docs cover each framework and the move from Dualmark.

[Read the quickstart](https://useagentside.com/docs/quickstart) [Migrate from Dualmark](https://useagentside.com/docs/migrating-from-dualmark)
