← Back
Cloudflare Workers AI adds conversion options for Markdown, HTML, and PDF processing

New Markdown Conversion Options

Cloudflare has expanded the Markdown Conversion service in Workers AI with a new conversionOptions object that gives developers fine-grained control over file processing.

What's New

The update introduces three sets of customization options:

  • Image Processing: Specify the language for AI-generated image descriptions (e.g., Spanish, French, etc.)
  • HTML Extraction: Use CSS selectors to target specific content sections, or provide a hostname to properly resolve relative links
  • PDF Handling: Exclude metadata from the converted output for cleaner results

How to Use

Both the JavaScript binding and REST API support the new feature:

await env.AI.toMarkdown(
  { name: "page.html", blob: new Blob([html]) },
  {
    conversionOptions: {
      html: { cssSelector: "article.content" },
      image: { descriptionLanguage: "es" },
    },
  },
);

Developers using the REST API can pass conversion options directly in curl requests:

curl https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/tomarkdown \
  -H 'Authorization: Bearer {API_TOKEN}' \
  -F 'files=@index.html' \
  -F 'conversionOptions={"html": {"cssSelector": "article.content"}}'

Next Steps

For complete details on all available options and use cases, refer to the Conversion Options documentation.