Skip to content
For the complete Netlify documentation index, see llms.txt. Markdown versions of any documentation page are available by appending .md to its URL.

More flexibility and credits now available for Pro plans ๐ŸŽ‰

markdown-for-agents

Back to templates

Add an edge function that serves your site as Markdown to AI agents, cutting token usage by ~80%.

ยทUpdated Mar 16, 2026ยท1 variable
Add a Netlify Edge Function to this site that serves Markdown instead of HTML when AI agents request it, reducing token usage by ~80%. Paths to exclude (if any): {{EXCLUDED_PATHS}} The implementation should: 1. **Scan the project** to identify content pages (blog posts, docs, articles, landing pages โ€” anything with meaningful text content). Ignore utility routes, API endpoints, and asset paths. 2. **Create a Netlify Edge Function** that: - Checks for `Accept: text/markdown` in the request headers - If not present, passes through to the origin unchanged - Fetches the HTML response from the origin - Strips non-content elements (scripts, styles, nav, footer, header, sidebars) - Converts the remaining HTML to Markdown using Turndown (imported via `npm:turndown`) - Returns the Markdown response with these headers: - `Content-Type: text/markdown; charset=utf-8` - `X-Markdown-Tokens` with estimated token count (string length / 4) - `Content-Signal: ai-train=yes, search=yes, ai-input=yes` - Falls back to the original HTML response on any error 3. **Configure `netlify.toml`** to register the edge function on all content paths identified in step 1. Exclude any paths specified above. 4. **Include a code comment** with: - A curl command to test the Markdown response: `curl -H "Accept: text/markdown" https://your-site.netlify.app/path` - How to add or remove paths from the edge function scope - How to test locally with `netlify dev`

Variables

Paths to skip โ€” the agent will scan your project to find all content pages automatically. Use this to exclude specific paths you don't want served as Markdown.