
Delivering Markdown to Agents, HTML to Humans
This demo project shows how to serve different formats of the same documentation depending on the client. AI agents benefit from receiving lightweight Markdown instead of full HTML, while browsers still get standard HTML for human readers.
By serving Markdown directly, we cut down token usage for AI agents, making it more efficient for them to parse and process documentation.
Compare
curl -H "Accept: text/markdown" https://markdown-to-agents.vercel.app/docs/getting-startedand
curl -H "Accept: text/html" https://markdown-to-agents.vercel.app/docs/getting-startedThe rewrite in next.config.ts directs traffic asking for text/markdown to a route that returns markdown.
const nextConfig: NextConfig = { rewrites: async () => { return { beforeFiles: [ { source: "/docs/:slug", destination: "/markdown/:slug", has: [ { type: "header", key: "accept", value: "(.*)text/markdown(.*)", }, ], }, ], }; },};