DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Keeping AI Code Generation Honest: A Deterministic Control Plane for Multi-Agent LLM Workflows
  • Spring AI Migration: From the Vertex AI Gemini Module to the Google GenAI SDK
  • Building Fault-Tolerant MCP Servers With Temporal for Durable AI Agent Execution
  • Spec-Driven Delegation: Governing Uneven AI Coding Capacity

Trending

  • Slopsquatting: Building a Scanner That Catches AI-Hallucinated Packages Before They Reach Production
  • Understanding Vector Databases: Concepts, Similarity Search, and Trade-offs for Enterprise Applications
  • Measuring AI Impact at the Team Level
  • Detecting and Measuring Bias in Training Data Before It Reaches Production

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Content Negotiation for AI Agents: Serving Markdown Beside Your HTML

Content Negotiation for AI Agents: Serving Markdown Beside Your HTML

Agents ask for text/markdown, and most sites answer with HTML. The Accept/Vary pattern, the cache key that keeps negotiation honest, and three curl checks for CI.

By 
Prajwal Hallale
·
Dec. 04, 26 · Analysis
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
110 Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

A product page now has two audiences. A browser renders it, and an assistant fetches it, reads the response, and quotes what it finds. The second audience does not need layout, scripts, or tracking pixels. It needs the facts in a form it can lift without reverse-engineering a template.

On our directory, a tool page arrives as 119,486 bytes of HTML. The same URL with Accept: text/markdown returns 5,638 bytes of Markdown, about 4.7% of the original weight, with the fields an assistant asks about already separated into front matter. Both responses came from the same data object in the same request path. One measurement, taken on 2026-11-02 against a single tool page, is not a benchmark, but the size gap is large enough to explain why the Markdown route was worth building.

This article covers the parts that caused trouble: the negotiation header, the cache key, the shape of the Markdown, and the checks that keep the two representations from drifting.

Negotiate on Accept, Then Check the Q-Value

The HTTP contract already supports this. A client states a preference:

Shell
 
curl -H 'Accept: text/markdown' https://example.com/tool/foo


The handler picks the representation. In a Laravel controller, the first version looked like this:

PHP
 
$wantsMarkdown = str_contains($request->header('Accept', ''), 'text/markdown');

if ($wantsMarkdown) {
    return response($markdown, 200, [
        'Content-Type' => 'text/markdown; charset=utf-8',
    ]);
}

return response($html);


That works for a browser and for a simple agent. It fails on a client that sends Accept: text/markdown;q=0, text/html. A bare str_contains treats an explicit rejection as a request. If the endpoint is public and other services cache it, that mistake is visible.

A small parser fixes it. Only the media ranges that matter need handling:

PHP
 
function acceptsMarkdown(string $accept): bool
{
    foreach (explode(',', $accept) as $range) {
        [$type, $params] = array_pad(explode(';', trim($range), 2), 2, '');
        if (strtolower(trim($type)) !== 'text/markdown') {
            continue;
        }
        if (preg_match('/q=([0-9.]+)/i', $params, $m)) {
            return (float) $m[1] > 0;
        }
        return true;
    }
    return false;
}


Two rules keep this from breaking existing clients. Browsers send text/html first and keep getting HTML. And the endpoint never rewrites a request that asks only for text/html, so the change is additive for every current visitor.

Send Vary: Accept, or a Cache Will Erase the Negotiation

The response header matters as much as the request header:

HTTP
 
Vary: Accept


Without it, a shared cache can store the HTML response under the URL and serve it to the next agent, or store the Markdown and serve it to a browser. Either way, the negotiation quietly stops working. On our page the Markdown response carried:

HTTP
 
content-type: text/markdown; charset=utf-8
vary: X-Inertia, Accept
cache-control: no-cache, private


The X-Inertia token was already there from the framework. The important addition was Accept.

If you cache both representations, do not put the raw Accept string in the cache key. Agents send long lists with different orderings and quality values, so a raw header key creates dozens of entries that hold two or three distinct bodies. Normalize the header to the chosen format and key on that:

Plain Text
 
page:{id}:format:markdown
page:{id}:format:html


That keeps the cache honest and small.

Give the Markdown a Shape, Not Just Prose

Stripping the HTML tags produces text that reads badly and still forces the model to guess at structure. The useful version starts with front matter and keeps the same order as the page.

This is the top of a live page from the directory, fetched with Accept: text/markdown:

Markdown
 
---
title: The Body Report
description: "The Body Report uses AI and evidence-based formulas to analyze body shape, proportions, posture, and body fat from a photo or tape measurements."
url: https://eliteai.tools/tool/the-body-report
---

# The Body Report

Understand your body shape, proportions, and posture from a single photo.

## Summary

The Body Report uses AI and evidence-based formulas to analyze body shape, proportions, posture, and body fat from a photo or tape measurements.

## Details

- **Pricing:** Freemium
- **Website:** https://yourbodyreport.com
- **Monthly from:** $15


The body continues with tags, professions, features, use cases, FAQs, and alternatives. Those are the fields an assistant needs to answer "what does this cost", "what is it similar to", and "who is it for". A model quoting the page gets the same facts a reader gets, in the same order, without parsing a navigation menu.

Front matter is the cheapest schema most sites will ever ship. It also gives you a place to state the canonical URL, which matters when the Markdown is consumed outside the browser where relative links and redirects behave differently.

Test It Like an API

Three header checks catch most regressions:

Shell
 
curl -sI -H 'Accept: text/markdown' "$URL" | grep -i '^content-type: text/markdown'
curl -sI "$URL" | grep -i '^vary:.*accept'
curl -s  -H 'Accept: text/markdown' "$URL" | head -1


The third should print ---. Add a fourth check for the size ratio, because a renderer that starts including the whole layout will pass the first three:

Shell
 
html=$(curl -s "$URL" | wc -c)
md=$(curl -s -H 'Accept: text/markdown' "$URL" | wc -c)
echo "$md / $html" | bc -l


On the page measured above, the ratio was 0.047. A sudden jump toward 1.0 means the Markdown route is leaking HTML.

There is one more check worth adding if the site documents its agent surface: an llms.txt that names the URL patterns (/tool/{slug}, /category/{slug}) and says which one answers which kind of question. It is a small file, and it saves an agent from guessing.

What Negotiation Does Not Fix

Content negotiation makes a page readable. It does not make it complete. A page with no pricing field, no category, and no alternatives still has nothing an assistant can quote, in either format. During the rollout of our directory, the renderer was the easy part. The harder part was finding how many pages had no pricing value to render, because the field had never been filled in. The Markdown surface made that gap visible; it did not create it.

Freshness is the other limit. Markdown and HTML diverge as soon as one renderer changes, and the other does not. Generate both from the same object in the same request path, or accept that the agent copy will drift. A scheduled diff between the two outputs, run against a sample of pages, is cheaper than discovering the drift from a wrong answer quoted back to you.

Rollout Notes

Ship the route behind the same middleware and authentication as the HTML page. Add Vary: Accept at the response layer, not in one controller, so a new endpoint cannot forget it. Normalize the format in the cache key. Keep the renderer next to the HTML template, because the two views will be edited together.

The whole change is two routes, one data object, a Vary header, and a cache key. The payoff is a surface you can test with curl, and a page that answers an assistant with fields instead of a template.

AI HTML

Opinions expressed by DZone contributors are their own.

Related

  • Keeping AI Code Generation Honest: A Deterministic Control Plane for Multi-Agent LLM Workflows
  • Spring AI Migration: From the Vertex AI Gemini Module to the Google GenAI SDK
  • Building Fault-Tolerant MCP Servers With Temporal for Durable AI Agent Execution
  • Spec-Driven Delegation: Governing Uneven AI Coding Capacity

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook