You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: 'Workers AI Markdown Conversion: New endpoint to list supported formats'
3
+
description: You can now programmatically get a list of all supported file formats that can be converted by our Markdown Conversion utility.
4
+
date: 2025-10-23
5
+
---
6
+
7
+
Developers can now programmatically retrieve a list of all file formats supported by the [Markdown Conversion utility](/workers-ai/features/markdown-conversion/) in Workers AI.
8
+
9
+
You can use the [`env.AI`](/workers-ai/configuration/bindings/) binding:
For these reasons, document conversion plays an important role when designing and developing AI applications. Workers AI provides the `toMarkdown` utility method that developers can use from the [`env.AI`](/workers-ai/configuration/bindings/) binding or the REST APIs for quick, easy, and convenient conversion and summary of documents in multiple formats to Markdown language.
15
15
16
-
## Methods and definitions
16
+
## Methods
17
17
18
18
### async env.AI.toMarkdown()
19
19
20
-
Takes a list of documents in different formats and converts them to Markdown.
20
+
Takes a document or list of documents in different formats and converts them to Markdown.
21
21
22
22
#### Parameter
23
23
24
-
- <code>documents</code>: <Typetext="array" />- An array of
25
-
`toMarkdownDocument`s.
24
+
- <code>files</code>: <Typetext="MarkdownDocument | MarkdownDocument[]" />- an instance of or an array of
25
+
`MarkdownDocument`s.
26
26
27
27
#### Return values
28
28
29
-
- <code>results</code>: <Typetext="array" />- An array of
30
-
`toMarkdownDocumentResult`s.
29
+
- <code>results</code>: <Typetext="Promise<ConversionResult | ConversionResult[]>" />- An instance of or an array of
30
+
`ConversionResult`s.
31
31
32
-
###`toMarkdownDocument` definition
32
+
#### `MarkdownDocument` definition
33
33
34
34
-`name` <Typetext="string" />
35
35
@@ -39,23 +39,54 @@ Takes a list of documents in different formats and converts them to Markdown.
39
39
40
40
- A new [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob) object with the document content.
41
41
42
-
###`toMarkdownDocumentResult` definition
42
+
#### `ConversionResult` definition
43
43
44
44
-`name` <Typetext="string" />
45
45
46
46
- Name of the converted document. Matches the input name.
47
47
48
+
-`format` <Typetext="'markdown' | 'error'" />
49
+
50
+
- The format of this `ConversionResult` object
51
+
48
52
-`mimetype` <Typetext="string" />
49
53
50
54
- The detected [mime type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types) of the document.
51
55
52
56
-`tokens` <Typetext="number" />
53
57
54
-
- The estimated number of tokens of the converted document.
58
+
- The estimated number of tokens of the converted document. Only present if `format` is equal to `markdown`.
55
59
56
60
-`data` <Typetext="string" />
57
61
58
-
- The content of the converted document in Markdown format.
62
+
- The content of the converted document in Markdown format. Only present if `format` is equal to `markdown`.
63
+
64
+
-`error` <Typetext="string" />
65
+
66
+
- The error message explaining why this conversion failed. Only present if `format` is equal to `error`.
67
+
68
+
### async env.AI.toMarkdown().transform()
69
+
70
+
This method is similar to `env.AI.toMarkdown` except that it is exposed through a new handle. It takes the same arguments and returns the same values.
71
+
72
+
### async env.AI.toMarkdown().supported()
73
+
74
+
Returns a list of file formats that are currently supported for markdown conversion. See [Supported formats](#supported-formats) for the full list of file formats that can be converted into Markdown.
75
+
76
+
#### Return values
77
+
78
+
- <code>results</code>: <Typetext="SupportedFormat[]" />- An array of all formats supported for markdown conversion.
79
+
80
+
#### `SupportedFormat` definition
81
+
82
+
-`extension` <Typetext="string" />
83
+
84
+
- Extension of files in this format.
85
+
86
+
-`mimeType` <Typetext="string" />
87
+
88
+
- The [mime type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types) of files of this format
89
+
59
90
60
91
## Supported formats
61
92
@@ -65,6 +96,8 @@ This is the list of support formats. We are constantly adding new formats and up
65
96
66
97
## Example
67
98
99
+
### Converting files
100
+
68
101
In this example, we fetch a PDF document and an image from R2 and feed them both to `env.AI.toMarkdown`. The result is a list of converted documents. Workers AI models are used automatically to detect and summarize the image.
69
102
70
103
```typescript
@@ -79,6 +112,7 @@ export default {
79
112
const cat =awaitenv.R2.get("cat.jpeg");
80
113
81
114
returnResponse.json(
115
+
// env.AI.toMarkdown().transform(...) would return the same result
`toMarkdown` is free for most format conversions. In some cases, like image conversion, it can use Workers AI models for object detection and summarization, which may incur additional costs if it exceeds the Workers AI free allocation limits. See the [pricing page](/workers-ai/platform/pricing/) for more details.
0 commit comments