# Docs

## 1\. Add your site

Create an account, add your domain in the [dashboard](https://returnmd.vercel.app/dashboard) and copy the site key into `RETURNMD_SITE_KEY`.

## 2\. Install

```
npm install returnmd
```

## 3a. Next.js

Create `proxy.ts` next to your `app` directory:

```
import { createProxy } from "returnmd/next";

export const proxy = createProxy({ siteKey: process.env.RETURNMD_SITE_KEY! });

export const config = {
  matcher: ["/((?!_next|api|favicon.ico).*)"],
};
```

## 3b. Any other framework

Call `handle(request, next, ctx)` in front of your normal handler. `next` renders the page; pass `ctx` if your platform has `waitUntil`.

```
import { returnmd } from "returnmd";

const md = returnmd({ siteKey: process.env.RETURNMD_SITE_KEY });

// Hono
app.use("*", async (c, next) => {
  c.res = await md.handle(c.req.raw, async () => { await next(); return c.res; });
});

// Cloudflare Workers / Bun
export default { fetch: (req, env, ctx) => md.handle(req, () => render(req), ctx) };
```

## 4\. Sync after each deploy

Pages listed in `/sitemap.xml` are scraped to markdown. Pages whose `<lastmod>` didn't change are skipped. Add this as the last step of your deploy:

```
RETURNMD_SITE_KEY=rmd_... npx returnmd sync
```

Pages missing from the sitemap are scraped the first time an agent asks for them. That agent gets HTML; the next one gets markdown. A request for `/page.md` waits for the scrape.

## Who gets markdown

- Requests that `@mintlify/agent-traffic` classifies as an **agent**: coding agents, assistants fetching for a person, and anything that prefers `text/markdown` in its `Accept` header.
- Any request for `/path.md` (`/index.md` for the home page).

Search crawlers, AI training crawlers, plain HTTP clients like curl, and people get HTML.

## Privacy

No cookies. Unique visitors are a hash of a random daily salt, your site, the IP address and the user agent. Salts are deleted after two days. Full IP addresses are never stored: returnmd keeps the network (the first three parts of an IPv4 address) and a daily hash, which helps tell agents from people. Request headers are stored without cookies, credentials or IP headers. Location comes from your host's geo headers (Vercel, Cloudflare).

## Limits

- Only public pages can be converted; the scraper fetches your live site.
- Client-side navigations in single-page apps aren't counted, only full page loads.
- Up to 500 changed pages per sync.