跳转到内容
搜索文档

REST API

最后更新 查看 MarkdownAgent 设置

您也可以使用 Markdown Conversion REST API 将文档转换为 Markdown。

前提条件:获取 Workers AI API token

要通过 REST API 使用 Markdown Conversion 服务,您需要具有 Workers AI REST API 权限的 API token。请参阅 Workers AI REST API 快速入门 了解如何获取具有正确权限的 API token。

Transform

此端点允许您将提供的任何文件转换为 markdown。

curl https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/tomarkdown \
  -X POST \
  -H 'Authorization: Bearer {API_TOKEN}' \
  -F "files=@cat.jpeg" \
  -F "files=@somatosensory.pdf" \
  -F 'conversionOptions={ ... }'

参数

files File[]required

您要转换的文件。

conversionOptions ConversionOptionsoptional

允许您控制文件转换方式的选项。请参阅转换选项了解更多详情。

响应

{
	"success": true,
	"result": [
		{
			"id": "...",
			"name": "good.html",
			"mimeType": "text/html",
			"format": "markdown",
			"tokens": 49,
			"data": "# Image Embedded with a Data URI\n\nThis _image_ is directly encoded in the HTML:\n\n\n\nAn image description\n\n \n\nIt's a tiny 5x5 pixel PNG, scaled up to 50x50px.\n\n"
		},
		{
			"id": "...",
			"name": "bad.pdf",
			"mimeType": "application/pdf",
			"format": "error",
			"error": "Some error that prevented this image from being converted"
		}
	]
}

Supported

此端点允许您以编程方式检索支持转换的完整富格式集合。

curl https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/tomarkdown/supported \
  -H 'Authorization: Bearer {API_TOKEN}'

响应

{
  "success": true,
  "result": [
    {
      "extension": ".html",
      "mimeType": "text/html"
    },
    {
      "extension": ".pdf",
      "mimeType": "application/pdf"
    },
    ...
  ]
}

这篇文档对您有帮助吗?