Skip to content

Clean page content

Accept: text/markdown: when the site hands your fetcher Markdown

Ask a site for Markdown with one header, confirm you got it from Content-Type and Vary, and know which metadata a site-served Markdown copy keeps or drops.

By Curtis Mccann, Live Web Data team · Published

This article was drafted with AI assistance from the sources listed below and edited and published by the Live Web Data team. Disclosure: the Live Web Data API, which this article mentions, is this site's own product.

Before you trust a Markdown response
  • Name text/markdown in the Accept header; some servers ignore text/* and */*.
  • Check Content-Type: text/markdown means Markdown; text/html means convert it yourself.
  • Look for Vary: Accept, which keeps caches from mixing the HTML and Markdown copies.
  • Record your own fetch time: Cloudflare's converted copy drops ETag and Last-Modified.
  • Cite the HTML page, not a .md copy; Vercel recommends a canonical Link header.

An AI app that reads a page usually gets HTML and converts it. Some sites can skip that step for you: send the right request header and they answer with their own Markdown. The decision for your fetcher is simple to state. Ask for Markdown, check what came back, and know what the site's copy leaves out compared with the page you would have converted.

How to ask: name text/markdown in Accept

The default is to list Markdown first and keep HTML as a fallback. Vercel's post on content negotiation shows agents sending Accept: text/markdown, text/html, */*. A server that supports Markdown can pick it; one that does not still has HTML on the list.

Do not rely on a wildcard. curl sends Accept: */* by default, according to MDN. Static Web Server turns Markdown negotiation on with its --accept-markdown flag and switches only on an explicit text/markdown value. Its docs state that text/* and */* do not trigger it. So a fetcher that never names the type gets HTML even from a site that has Markdown ready.

curl -sS -D headers.txt -o page.out \
  -H "Accept: text/markdown, text/html, */*" \
  https://example.com/
grep -i -E '^(content-type|vary|link|content-signal):' headers.txt

How to tell you got it: Content-Type, then Vary

The server tells the client which representation it chose through the Content-Type response header (MDN). That header, not the file extension and not a guess from the first line, decides how your pipeline treats the body. Cloudflare and Static Web Server both answer with text/markdown; charset=utf-8.

  • text/markdown: pass the body on as Markdown.
  • text/html: the site ignored the preference. Convert the page yourself, as you would for any other HTML page.

Then look for Vary: Accept. Cloudflare's docs say it adds accept to Vary so caches store the Markdown and HTML copies apart, and Vercel's guide recommends the same header. Without it, a cache between you and the site can hand the wrong copy to the next request.

The check also matters in the other direction. Vercel's guide says it returns Markdown when a request prefers it, or when it "detects an AI agent without a format preference". A fetcher that asked for nothing in particular can still receive Markdown, so read Content-Type on every response.

import urllib.request

req = urllib.request.Request(
    "https://example.com/",
    headers={"Accept": "text/markdown, text/html, */*"},
)
with urllib.request.urlopen(req, timeout=30) as resp:
    ctype = resp.headers.get("Content-Type", "")
    vary = resp.headers.get("Vary", "")
    body = resp.read().decode("utf-8", errors="replace")

is_markdown = ctype.lower().startswith("text/markdown")
print("markdown" if is_markdown else "html, convert it", "| Vary:", vary or "none")

What the site's Markdown keeps

A site's own Markdown can be much smaller than its HTML. Vercel's post gives about 500 KB of HTML against 3 KB of Markdown for one of its pages, and says the Markdown keeps the heading hierarchy, working links and code blocks.

Cloudflare's Markdown for Agents converts a site's HTML into Markdown for clients that ask for it. Its output has three parts: YAML frontmatter, the body as Markdown, and the page's JSON-LD in a fenced json block at the end. The frontmatter holds title, description and image from the page's meta tags, and a standard name tag wins over its og: twin. Headers, footers, navigation, scripts and styles are removed. Only HTML is converted, up to 6 MiB (6,291,456 bytes) of decompressed HTML.

For a model, that is close to what a main-content Markdown conversion gives you. The pillar on Markdown, text or HTML for LLMs covers when Markdown is the right format at all.

What it drops or changes

This is where the site's copy differs from a page you fetch and convert yourself.

  • Freshness headers. Cloudflare's docs list ETag and Last-Modified among the headers removed from the Markdown response, along with Content-Length. If your app reads those headers to judge a page's age, as the post on Last-Modified and ETag describes, a Markdown read gives you neither. Record your own fetch time instead. Cache-Control is kept.
  • The content signal. Cloudflare keeps a Content-Signal header the origin sets. If the origin sets none, the header defaults to ai-train=yes, search=yes, ai-input=yes. Treat that value as a default, not as a line the site owner necessarily wrote.
  • The address to cite. A Markdown copy can live at its own URL: Vercel serves its docs with a .md suffix as well. Its guide recommends a Link: <…>; rel="canonical" header pointing to the HTML page. Cite that page, not the .md address.
  • Which content you get. The site decides what goes into its Markdown. Vercel builds its blog Markdown from CMS content on request, through rewrites to separate Markdown routes. That copy can be cleaner than a conversion, but it is the site's selection, and it can differ from what a reader sees in the browser.

When the site serves only HTML

Many pages will still answer with HTML. Then the conversion is your job or your provider's. Live Web Data API returns each page as clean Markdown, plain text or HTML, with the title and other metadata when the page exposes them, and verbosity set to compact for the main content or full for the whole page. You can try a URL in the playground.

The rule for your fetcher: always name text/markdown in Accept, trust Content-Type over the URL, and keep your own fetch time and the HTML address next to every Markdown copy.

Frequently asked questions

What Accept header asks a site for Markdown?

Put text/markdown in the Accept header, for example Accept: text/markdown, text/html, */*. Vercel's post shows agents listing Markdown first like this. Some servers only switch on an explicit text/markdown value, so a request with only */* gets HTML.

How do I know the site actually returned Markdown?

Read the Content-Type of the response. The server reports its choice there. Cloudflare and Static Web Server send text/markdown; charset=utf-8. If the response says text/html, the site ignored the request and you need to convert the page yourself.

Does site-served Markdown keep the page's metadata?

It depends on the site. Cloudflare's conversion adds YAML frontmatter with title, description and image from the meta tags, keeps JSON-LD in a code block at the end, and removes the ETag and Last-Modified headers from the response.

Should an LLM cite the .md URL or the HTML page?

Cite the HTML page. The Markdown copy is another representation of the same page. Vercel's guide recommends a Link header with rel=canonical on Markdown responses so search engines index the HTML page.

Sources

  1. Making agent-friendly pages with content negotiation (Vercel) (Blog)
  2. How to serve documentation for agents (Vercel) (Documentation)
  3. Markdown for Agents (Cloudflare docs) (Documentation)
  4. Markdown content negotiation (Static Web Server) (Documentation)
  5. Accept header (MDN) (Documentation)