Skip to content

Commit 930bc3a

Browse files
authored
Add documentation for ToMarkdown supported formats endpoint (#26026)
* Add documentation regarding new endpoint for ToMarkdown * Added changelog entry
1 parent 960009f commit 930bc3a

File tree

2 files changed

+121
-10
lines changed

2 files changed

+121
-10
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
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:
10+
11+
```typescript
12+
await env.AI.toMarkdown().supported()
13+
```
14+
15+
Or call the REST API:
16+
17+
```bash
18+
curl https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/tomarkdown/supported \
19+
-H 'Authorization: Bearer {API_TOKEN}'
20+
```
21+
22+
Both return a list of file formats that users can convert into Markdown:
23+
24+
```json
25+
[
26+
{
27+
"extension": ".pdf",
28+
"mimeType": "application/pdf",
29+
},
30+
{
31+
"extension": ".jpeg",
32+
"mimeType": "image/jpeg",
33+
},
34+
...
35+
]
36+
```
37+
38+
Learn more about our [Markdown Conversion utility](/workers-ai/features/markdown-conversion/).

src/content/docs/workers-ai/features/markdown-conversion.mdx

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ import { Code, Type, MetaInfo, Details, Render } from "~/components";
1313

1414
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.
1515

16-
## Methods and definitions
16+
## Methods
1717

1818
### async env.AI.toMarkdown()
1919

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.
2121

2222
#### Parameter
2323

24-
- <code>documents</code>: <Type text="array" />- An array of
25-
`toMarkdownDocument`s.
24+
- <code>files</code>: <Type text="MarkdownDocument | MarkdownDocument[]" />- an instance of or an array of
25+
`MarkdownDocument`s.
2626

2727
#### Return values
2828

29-
- <code>results</code>: <Type text="array" />- An array of
30-
`toMarkdownDocumentResult`s.
29+
- <code>results</code>: <Type text="Promise<ConversionResult | ConversionResult[]>" />- An instance of or an array of
30+
`ConversionResult`s.
3131

32-
### `toMarkdownDocument` definition
32+
#### `MarkdownDocument` definition
3333

3434
- `name` <Type text="string" />
3535

@@ -39,23 +39,54 @@ Takes a list of documents in different formats and converts them to Markdown.
3939

4040
- A new [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob) object with the document content.
4141

42-
### `toMarkdownDocumentResult` definition
42+
#### `ConversionResult` definition
4343

4444
- `name` <Type text="string" />
4545

4646
- Name of the converted document. Matches the input name.
4747

48+
- `format` <Type text="'markdown' | 'error'" />
49+
50+
- The format of this `ConversionResult` object
51+
4852
- `mimetype` <Type text="string" />
4953

5054
- The detected [mime type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types) of the document.
5155

5256
- `tokens` <Type text="number" />
5357

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`.
5559

5660
- `data` <Type text="string" />
5761

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` <Type text="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>: <Type text="SupportedFormat[]" />- An array of all formats supported for markdown conversion.
79+
80+
#### `SupportedFormat` definition
81+
82+
- `extension` <Type text="string" />
83+
84+
- Extension of files in this format.
85+
86+
- `mimeType` <Type text="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+
5990

6091
## Supported formats
6192

@@ -65,6 +96,8 @@ This is the list of support formats. We are constantly adding new formats and up
6596

6697
## Example
6798

99+
### Converting files
100+
68101
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.
69102

70103
```typescript
@@ -79,6 +112,7 @@ export default {
79112
const cat = await env.R2.get("cat.jpeg");
80113

81114
return Response.json(
115+
// env.AI.toMarkdown().transform(...) would return the same result
82116
await env.AI.toMarkdown([
83117
{
84118
name: "somatosensory.pdf",
@@ -119,17 +153,56 @@ This is the result:
119153
]
120154
```
121155

156+
### Getting supported file formats
157+
158+
```typescript
159+
import { Env } from "./env";
160+
161+
export default {
162+
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
163+
return Response.json(
164+
await env.AI.toMarkdown().supported(),
165+
);
166+
},
167+
};
168+
```
169+
170+
results in
171+
172+
```json
173+
[
174+
{
175+
"extension": ".pdf",
176+
"mimeType": "application/pdf",
177+
},
178+
{
179+
"extension": ".jpeg",
180+
"mimeType": "image/jpeg",
181+
},
182+
...
183+
]
184+
```
185+
122186
## REST API
123187

124188
In addition to the Workers AI [binding](/workers-ai/configuration/bindings/), you can use the [REST API](/workers-ai/get-started/rest-api/):
125189

190+
### Conversion
191+
126192
```bash
127193
curl https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/tomarkdown \
128194
-H 'Authorization: Bearer {API_TOKEN}' \
129195
-F "files=@cat.jpeg" \
130196
-F "files=@somatosensory.pdf"
131197
```
132198

199+
### Supported formats
200+
201+
```bash
202+
curl https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/tomarkdown/supported \
203+
-H 'Authorization: Bearer {API_TOKEN}' \
204+
```
205+
133206
## Pricing
134207

135208
`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

Comments
 (0)