Workers AI - New conversion options for Markdown Conversion
Key Points
- Per-file conversionOptions
- Image description language support
- HTML extraction via CSS selector
Summary
Workers AI's Markdown Conversion endpoint now accepts a conversionOptions object so you can customize how different file types are processed (image, html, pdf). This lets you set the language for AI-generated image descriptions, extract specific HTML content via CSS selectors or resolve relative links with a hostname, and exclude PDF metadata from the generated Markdown.
Key Points
- Supported options:
- image:
descriptionLanguage— choose language for generated image descriptions (e.g.,"es"). - html:
cssSelector— extract content using a CSS selector;hostname— resolve relative links. - pdf:
excludeMetadata— omit metadata from the output.
- image:
- Use in Workers (JavaScript/TypeScript) by passing
conversionOptionstoenv.AI.toMarkdown(...)for per-file processing. - REST API: send
conversionOptionsas JSON in form-data with-F 'conversionOptions=...'.
Examples (concise):
- JavaScript/TypeScript usage:
await env.AI.toMarkdown({ name: "page.html", blob: new Blob([html]) }, { conversionOptions: { html: { cssSelector: "article.content" }, image: { descriptionLanguage: "es" } } }); - cURL REST call:
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"}}'
Refer to the Conversion Options docs for full parameter descriptions and additional examples.