scrolltotop

new Get your brand recommended by ChatGPT, Perplexity & AI search engines. Discover GEO.

new We help companies keep track of engineering health with monthly reports. Start your review today.

Laravel Markdown for Agents

One API for Cloudflare's three Markdown conversion services.

Home Company Open Source Laravel Markdown for Agents
The Problem

Three Markdown Services, Three Integrations

AI agents, crawlers, and LLM-powered search engines tokenize everything they receive. Raw HTML is expensive: Cloudflare measured a single blog post at 16,180 tokens in HTML versus 3,150 in Markdown, an 80% reduction. At scale, the savings in context window budget and inference cost are substantial.

Cloudflare shipped three services for HTML-to-Markdown conversion: Markdown for Agents (edge content negotiation), Workers AI toMarkdown (binary file conversion), and Browser Rendering (headless Chromium for JS-heavy pages). Each has its own REST endpoint, auth pattern, and response format. Wiring them individually means duplicating HTTP client setup, error handling, response parsing, and caching across each integration.

The Solution

This package wraps all three services behind a single fluent interface with a driver-based architecture. Each Cloudflare service maps to a driver (agents, workers_ai, browser), and the package handles HTTP client setup, authentication, response normalization, caching, and error recovery. The same ConversionResult DTO is returned regardless of which backend handled the request.

The package also includes a middleware that implements Cloudflare's content negotiation pattern on your own Laravel routes. When a request includes Accept: text/markdown, the middleware converts your HTML response to Markdown locally using league/html-to-markdown. No Cloudflare API calls, no external dependencies. Make your Laravel app agent-ready with a single middleware.

GitHub stars License PHP 8.2+ Laravel 11/12

Key Features

  • Three drivers, one API. Agents, Workers AI, and Browser Rendering unified behind a fluent interface.
  • URL, file & HTML conversion. Convert any source type with automatic driver selection.
  • Automatic fallback. If the primary driver fails, retry with another transparently via withFallback().
  • Middleware. Serve Markdown from your own routes with Accept: text/markdown content negotiation.
  • Smart caching. Per-request TTL, configurable store. Bypass with noCache().
  • Batch conversion. Convert multiple files in a single call via Workers AI.
  • Events. MarkdownConverted and ConversionFailed for monitoring and alerting.
  • Extensible. Register custom drivers via extend() with full caching and fallback support.

Requirements

  • PHP 8.2+
  • Laravel 11.x or 12.x
  • Cloudflare account (for Workers AI and Browser drivers)

Installation

composer require moneo/markdown-for-agents
View on GitHub
Partnership is at the core of what we do.

Unsure where to start?
Let’s figure it out together 👋

Contact Us