---
title: Content negotiation
description: How Agentside decides whether a request gets markdown or HTML and which headers it sets.
sidebar:
  order: 4
---

`handle(request, next)` decides between your HTML page and the markdown twin from the URL, the `Accept` header and the `User-Agent` header. Only `GET` and `HEAD` requests are considered. Paths under a `skip` prefix, and paths that match no route (your API, assets, `.md` files your app serves itself), go straight to `next()` with the request untouched.

## Decision order

1. **The path ends in `.md` and matches a route.** The request is explicit, so Agentside serves the twin. A route that returns no twin gets a markdown 404 and a failing twin gets a markdown 503.
2. **`Accept` mentions `text/markdown` or the user agent is a known AI agent.** Agentside serves the twin when it exists. When it is missing or fails, the request falls through to `next()` and the visitor gets your HTML page.
3. **`Accept` rules out both HTML and markdown.** Agentside answers `406 Not Acceptable`. This only happens on paths that match a route.
4. **Everything else** gets your HTML page from `next()`, with a `Link` header pointing at the twin.

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

Set `linkHeader: false` to leave HTML responses without the `Link` header.

## The Accept header

By default `handle` serves markdown whenever `Accept` contains `text/markdown` or the older `text/x-markdown`, whatever its q-value, unless that q-value is `0`. That is the only rule a CDN can express, so `handle` and the routes from [`vercelRoutes`](/docs/static-sites#negotiating-at-the-cdn) always agree on the same request.

Set `accept: "q-value"` to weigh q-values instead. Agentside then compares `text/markdown` and `text/x-markdown` against `text/html` and `application/xhtml+xml`, with `*/*` and `text/*` counting for whichever side has no specific entry. Markdown has to score strictly higher, so a tie goes to HTML.

```ts
agentside({ routes, accept: "q-value" });
```

| Accept | Default (`"contains"`) | `"q-value"` |
| --- | --- | --- |
| *(none)* | HTML | HTML |
| `text/html,*/*;q=0.8` | HTML | HTML |
| `text/markdown` | Markdown | Markdown |
| `text/x-markdown` | Markdown | Markdown |
| `text/markdown, text/html;q=0.9` | Markdown | Markdown |
| `text/html, text/markdown` | Markdown | HTML |
| `text/html, text/markdown;q=0.5` | Markdown | HTML |
| `text/html, text/markdown;q=0` | HTML | HTML |
| `application/json` | 406 on a route path | 406 on a route path |

The same logic is exported as `negotiateFormat(accept, mode)`, which returns `"markdown"`, `"html"` or `null`. Unlike `handle`, its `mode` defaults to `"q-value"`.

## Agent detection

`detectAgent(userAgent)` matches the user agent against a list of known AI agents, case insensitively, and returns `{ name, vendor, purpose }` or `null`. Purposes are `"training"`, `"search"` and `"user-action"`.

| Agent | Vendor | Purpose |
| --- | --- | --- |
| ChatGPT-User | OpenAI | user-action |
| OAI-SearchBot | OpenAI | search |
| GPTBot | OpenAI | training |
| Claude-User, Claude-Web | Anthropic | user-action |
| Claude-SearchBot | Anthropic | search |
| ClaudeBot, Anthropic-ai | Anthropic | training |
| Perplexity-User | Perplexity | user-action |
| PerplexityBot | Perplexity | search |
| MistralAI-User | Mistral | user-action |
| Google-Extended, GoogleOther | Google | training |
| Applebot-Extended | Apple | training |
| Meta-ExternalAgent | Meta | training |
| Meta-ExternalFetcher | Meta | user-action |
| DuckAssistBot | DuckDuckGo | search |
| YouBot | You.com | search |
| cohere-ai | Cohere | training |
| Amazonbot | Amazon | training |
| Bytespider | ByteDance | training |
| CCBot | Common Crawl | training |
| Diffbot | Diffbot | training |
| ImagesiftBot | ImageSift | training |
| Omgilibot | Webz.io | training |

The full list is exported as `KNOWN_AGENTS`.

## Markdown response headers

Markdown responses carry these headers.

| Header | Value |
| --- | --- |
| `Content-Type` | `text/markdown; charset=utf-8` |
| `X-Agentside-Variant` | The variant id that was served, `control` by default. Only on 200 responses. |
| `X-Markdown-Tokens` | A whitespace-based token estimate of the body. |
| `Cache-Control` | `public, max-age=3600`, or your `cacheControl`. |
| `Vary` | `Accept, User-Agent` |
| `X-Robots-Tag` | `noindex` on `.md` URLs, unless you set `noindex: false` (`vercelRoutes()` takes no config and always sets it). On markdown that `handle` negotiates on the page URL only with `noindex: true`, and never on `vercelRoutes()` rewrites. |
| `X-Content-Type-Options` | `nosniff` |
| `Retry-After` | `30`, only on a 503. |

`HEAD` requests get the same status and headers with an empty body.

`noindex` defaults to on for `.md` URLs, so search engines index your HTML page instead of a duplicate twin. A twin that `handle` negotiates on the page URL itself, through `Accept` or a known agent, gets no `noindex` by default: for AI search crawlers such as OAI-SearchBot, Claude-SearchBot and PerplexityBot that response is the page, and a crawler that honors the header could drop the page from its index. If the HTML page is `noindex` itself, set `noindex: true` so its twin matches on every URL. `vercelRoutes()` has no such option: its rewrites on the page URL never send `noindex`, so leave a `noindex` page out of its `paths`. HTML responses on a path with a route get `Vary: Accept, User-Agent` too, whether they come from step 4 or fall through after a negotiated request, so shared caches never hand a twin to a browser or a page to an agent. When a negotiated request has no twin, or the twin fails, it always falls back to the HTML page, even if `Accept` lists only `text/markdown`, so an agent never ends up with an error for a page that exists. When `Accept` rules HTML out, Agentside sets it to `text/html` on the request before calling `next()`, because frameworks such as TanStack Start refuse to render a page for a request that doesn't accept HTML. Only explicit `.md` URLs answer with a markdown 404 or 503.
