AgenticWebScore
Scan

Learn

Markdown for agents: how to serve text/markdown with the Accept header and Vary

Serve markdown on Accept: text/markdown with Vary: Accept. Whether GPTBot asks for it, a curl test, Cloudflare's Markdown for Agents, and Next.js code.

8 min read 1964 words

Reviewed by a human editor before publication. How we write

  • markdown
  • content negotiation
  • HTTP
  • Cloudflare

To serve markdown to agents, answer a request that names text/markdown in Accept with a markdown body at the page's own URL. Send Content-Type: text/markdown; charset=utf-8 and Vary: Accept on every representation, and keep sending HTML to everyone else. One command tests it:

curl -sS -D- -o /dev/null -H 'Accept: text/markdown' https://agenticwebscore.com/ | grep -iE '^(HTTP|content-type|vary)'
HTTP/2 200
content-type: text/markdown; charset=utf-8
vary: Accept

That is this site's answer on 27 October 2026. Run the command against your own URL. A content-type of text/html means the server ignored the header, and a vary without Accept means a shared cache can hand the wrong version to the next visitor.

AgenticWebScore scores this as an agent convention: markdown-negotiation. It is experimental, it earns points in the 30% conventions part and it holds no level. Google says a site needs no markdown or other special files for its generative AI features, so this is not an SEO task. The hard part is not the header. It is producing the markdown without a second content pipeline that drifts from the first within a quarter.

Why serve markdown to agents?

An agent that fetches a page wants 3 things HTML makes expensive.

Structure that survives parsing. Headings, list items, table rows and code fences are a page's skeleton. In HTML you walk a tree of wrapper elements to reach them. In markdown they are the content.

Fewer tokens for the same facts. Navigation markup, inline SVG and tracking attributes cost tokens and carry no meaning. Cloudflare's launch post gives one example, its own blog post: 16,180 tokens as HTML and 3,150 as markdown. That is one page from one vendor, so measure your own. The scanner no longer scores token efficiency, and /methodology says why.

No chrome. A markdown twin should hold the page, not the site. The header, cookie banner and footer links add noise for an agent that arrived with one question.

Do AI crawlers like GPTBot request markdown?

OpenAI, Anthropic, Perplexity, and Google do not document that their crawlers send Accept: text/markdown. We read their crawler pages on 9 November 2026. OpenAI's page gives the user-agent strings and IP lists of GPTBot, OAI-SearchBot, and ChatGPT-User, and names no other request header. Anthropic's page names ClaudeBot, Claude-User, and Claude-SearchBot, with one IP list and no header.

The clients that do ask, by Cloudflare's count, are coding agents. Its Agent Readiness post of 17 April 2026 reports a test of 7 agents in February 2026. Only Claude Code, OpenCode, and Cursor sent the header by default. That is one vendor's test, not a statement by the agents' makers.

Your access log answers the question for your own site. The combined format of nginx and Apache does not record Accept. Add it after the user agent: "$http_accept" in an nginx log_format, or \"%{Accept}i\" in an Apache LogFormat. Then count markdown requests per user agent. The new value is field 8:

awk -F'"' '$8 ~ /text\/markdown/ { print $6 }' access.log | sort | uniq -c | sort -rn

A user agent is a claim, not an identity. AI crawler logs shows how to check a GPTBot or ClaudeBot in that list against the operator's IP list.

How does Accept-based content negotiation work?

RFC 9110 §12 describes proactive negotiation. The client states preferences in request headers, and the server picks a representation from what it has. The header is Accept (§12.5.1), a list of media types with optional quality values:

GET /pricing HTTP/1.1
Host: example.com
Accept: text/markdown, text/html;q=0.9

A quality value is q= followed by a number from 0 to 1. Absent means 1, and the most specific matching media range has precedence. Two rules matter when you implement it.

  • */* is not a request for markdown. A browser's default Accept usually ends in */*;q=0.8, and curl sends */* alone. Treat that as markdown and a browser shows raw text. Return markdown only when text/markdown is named.
  • No Accept header means no preference. Some HTTP libraries send none. Answer with the HTML document, and keep a .md URL twin for clients that cannot negotiate.

The URL stays the same. One resource has 2 representations, chosen per request. RFC 7763 registers text/markdown and marks charset as required, so text/markdown; charset=utf-8 is the right type. text/plain tells a client nothing about the syntax.

Why does Vary: Accept matter?

Vary (RFC 9110 §12.5.5) tells a cache which request headers shaped the response. Vary: Accept says the response was one of several, so the cache key must include Accept. Without it a shared cache, such as a CDN or a proxy, keys on the URL alone. The first request to warm the entry decides what everyone receives until it expires.

It fails in both directions. An agent warms /pricing, and the next visitor gets markdown rendered as raw text. Or a browser warms it, and every agent gets HTML.

  • Give the markdown and HTML responses the same Vary value, 304 Not Modified replies included. MDN says the same value belongs on all responses for a URL.
  • Do not use Vary: User-Agent instead. Every distinct user-agent string becomes its own cache entry.

How do you serve markdown without a second codebase?

A second codebase appears when markdown is a separate artifact: someone exports the HTML, runs a converter, fixes the headings by hand, and then the page changes. Treat markdown as a projection instead.

Model each page as data, a document with blocks, and write 2 renderers over it, one for HTML and one for markdown. The blocks an agent needs are few: paragraph, heading, code, list, table and quote. The server is then a preference check, not a second routing table.

// server.js — Node/Express; the same shape works in any framework.
import express from 'express';
import { pages } from './content.js';   // a Map of path -> document with blocks
import { toMarkdown, toHtml } from './render.js';

const app = express();

app.get('*', (req, res, next) => {
  const path = req.path.replace(/\/$/, '') || '/';

  const doc = pages.get(path);
  if (!doc) return next();

  // Only an explicit text/markdown, never */*, selects the twin.
  if (req.accepts(['text/html', 'text/markdown']) === 'text/markdown') {
    return res.type('text/markdown; charset=utf-8').set('Vary', 'Accept').send(toMarkdown(doc));
  }

  // The HTML representation declares the same Vary value.
  res.set('Vary', 'Accept').type('text/html; charset=utf-8').send(toHtml(doc));
});

app.use((req, res) => res.status(404).type('text/plain; charset=utf-8').send('Not found'));

req.accepts() reads the quality values you would otherwise parse by hand, and it returns HTML for a wildcard or a missing header. The markdown comes from the same object as the HTML, so a copy edit cannot land in one representation only. And Vary is set on the HTML response too, which is the half people forget.

Add a .md URL twin for clients that cannot negotiate, or render the twins at build time and serve them as files. Do not convert HTML to markdown per request by stripping tags. It is slower, and it flattens the headings.

How do you serve markdown from Next.js?

Next.js 16 deprecated its middleware file and renamed it proxy. The file runs before routes render, so it can rewrite a request that names text/markdown to a route handler that returns the markdown.

// proxy.ts (middleware.ts before Next.js 16)
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';

export function proxy(request: NextRequest) {
  const { pathname } = request.nextUrl;
  if ((request.headers.get('accept') ?? '').includes('text/markdown')) {
    return NextResponse.rewrite(new URL(`/md${pathname === '/' ? '/index' : pathname}`, request.url));
  }
  const response = NextResponse.next();
  response.headers.append('Vary', 'Accept');
  return response;
}

export const config = {
  matcher: ['/((?!api|md/|_next/static|_next/image|favicon.ico|robots.txt|sitemap.xml).*)'],
};
// app/md/[...path]/route.ts
import { markdownFor } from '@/lib/markdown'; // your content source: a string, or null for an unknown page

export async function GET(_request: Request, { params }: { params: Promise<{ path: string[] }> }) {
  const { path } = await params;
  const markdown = await markdownFor(path[0] === 'index' ? '/' : `/${path.join('/')}`);
  if (markdown === null) return new Response('Not found', { status: 404 });
  return new Response(markdown, {
    headers: { 'Content-Type': 'text/markdown; charset=utf-8', Vary: 'Accept' },
  });
}

We have not run this against a Next.js build. Confirm both responses with the curl test at the top, and check that the HTML response lists Accept in Vary.

Cloudflare Markdown for Agents: what it does, what it costs, and is it cloaking?

Cloudflare's Markdown for Agents converts your HTML to markdown at the edge when a request names text/markdown. Your origin keeps serving HTML. Turn it on under Agent Readiness in the dashboard, or for one hostname or path with a Configuration Rule.

Plans and limits. The docs list the Pro, Business and Enterprise plans and SSL for SaaS customers, at no cost. The Free plan is not on the list. Conversion covers HTML only, up to 6 MiB of decompressed HTML. The launch post of 12 February 2026 called the feature a beta.

Headers. The response is text/markdown; charset=utf-8, and Vary includes Accept next to any value your origin set. Cloudflare removes ETag and Last-Modified, because a converted body cannot honour conditional requests. The launch post adds x-markdown-tokens, an estimate of the token count of the markdown document, so a client can size its context window.

Content-Signal. If your origin sends no Content-Signal header, the converted response carries ai-train=yes, search=yes, ai-input=yes. Set your own at the origin first if you want another policy. Content-Signal in robots.txt explains the values.

Is it cloaking? Google's spam policy defines cloaking as showing different content to users and search engines to manipulate rankings. Its examples turn on the user agent, and it does not mention the Accept header. Cloudflare's pages do not discuss the question. Search Engine Journal reported on 13 February 2026 that Google had not said whether negotiation falls under the policy. It reads John Mueller's criticism as aimed at serving markdown by user agent. We found no Google statement on Accept itself.

The practical rule follows from that gap. Keep the markdown equal in content to the HTML, and choose by Accept, not by user agent. Cloudflare converts any HTML the origin returns, so fix a soft 404 before you turn it on.

How does the scanner measure markdown negotiation?

The Markdown for agents checker runs this measurement on your site.

The scanner requests the homepage a second time with Accept: text/markdown, text/html;q=0.5 and reads the status, Content-Type and Vary. markdown-negotiation has 3 outcomes you can act on.

  • Present. The answer is text/markdown with Vary: Accept or Vary: *.
  • Served with an error. Markdown arrives without Vary: Accept, a markdown body is typed text/plain, or the markdown request fails with 400 or above while the homepage answers 2xx.
  • Not used. The answer is HTML. The request accepts HTML, so that is a valid response, and it earns no points.

On 2 November 2026, under rubric v0.9.1, 3 of the 5 exemplars answered with markdown and Vary: Accept: cloudflare.com, resend.com and vercel.com. github.com and developer.mozilla.org answered HTML. The v0.9 records of 20 October showed the same.

This site's record of 2 November passes the check. On 27 October the same URL with Accept: text/html returned text/html and vary: Accept, Cookie. The /index.md twin works without negotiation. Scan your site to see what your homepage answers.

What are the common failure modes?

What are the common failure modes? — Symptom, What it means, Fix
Symptom What it means Fix
Accept: text/markdown returns 200 with Content-Type: text/html The handler ignored Accept, or a cache stored the HTML without Vary Branch on Accept before rendering, and set Vary: Accept on every representation.
Markdown returned, Vary missing The cache key ignores Accept, so the first representation wins Add Vary: Accept to both responses, 304s included. The check calls this "Served with an error".
Markdown body with no # or ## lines The twin was made by stripping tags, so headings became paragraphs Render headings from your content model.
text/plain, or no charset, on a markdown body Clients cannot tell the syntax, and non-ASCII text may decode wrongly Send text/markdown; charset=utf-8.
Browser shows raw markdown A wildcard or a missing Accept was treated as a markdown request Return markdown only when the client names text/markdown.
The twin is an empty shell The page assembles its content in the browser, so there is nothing to project Render on the server first. See no-js-fallback.

The last row is why negotiation and server rendering are one conversation. You cannot project content you only assemble in the browser.

What are the limits of markdown negotiation?

You cannot assume a given agent sends Accept: text/markdown. Treat this as a bet that agents will increasingly ask for a low-markup representation, not as a fix for a measured loss. If your markdown route sees no such request this quarter, that is expected.

  • Do not degrade the HTML path to make the bet. Browsers and most crawlers get the HTML document. Negotiation is additive.
  • Keep the .md twin. It costs one route, and it works without client cooperation.
  • Expect loss. Anchors, figures with captions and interactive components do not survive a naive projection. Decide per block type what the markdown form is.

The implementation is small: one branch on Accept, one Vary header on every representation and one content model with 2 renderers. The failure is a second codebase that drifts until an agent reads the wrong price. What agent readiness means puts this check beside the others. The same single-source idea generates an llms.txt at build time.