Skip to Content

Markdown extraction

Turn documents and web pages into Markdown for LLM context and indexing

POST /v1/markdown returns the content of a document as Markdown: headings, lists, tables and links. Pass it to an LLM as context, store it for search, or split it into chunks in the same request.

curl http://127.0.0.1:8000/v1/markdown \
  -H 'Authorization: Bearer dev' \
  -F file=@pricing.html
{
  "source": {
    "uri": "file://file",
    "name": "pricing.html",
    "size": 610,
    "mimeType": "text/html",
    "extension": "html",
    "label": "html",
    "group": "markup",
    "title": "Service levels"
  },
  "result": {
    "name": "pricing.md",
    "size": 412,
    "mimeType": "text/markdown",
    "extension": "md",
    "label": "markdown",
    "group": "markup",
    "encoding": "utf-8",
    "content": "# Service levels\n\nEvery plan includes monitoring, incident response and a named engineer.\n\n## Response times\n\n| Severity | First response | Resolution target |\n| --- | --- | --- |\n| Critical | 15 minutes | 4 hours |\n…"
  },
  "options": {"readMode": "text"}
}

source.title is the document title when the converter finds one, such as an HTML <title>; it is omitted otherwise. Use it as the display name of the document in your index.

Pick how you send the document

You haveSend
A file in your serviceA multipart upload, as above
A public URL{"source": "https://…"} as JSON
An object in a bucket{"source": "s3://<connector>/<key>"}; see remote storage

Read scans and images

By default, readMode is auto: Papyrus checks each document, sends scans, images and presentations to a vision model, and reads everything else from the text stored in the file. options.readMode in the response is the mode that was used, text or ocr. Your operator connects the model once; without one, auto reads every document as text.

Set readMode to text to never send a page to the model, or to ocr to read every page from its image:

curl http://127.0.0.1:8000/v1/markdown \
  -H 'Authorization: Bearer dev' \
  -F 'metadata={"options": {"readMode": "ocr"}};type=application/json' \
  -F file=@scan.pdf

A document read with OCR starts each page with a <!-- Page number: N --> marker. OCR covers how auto decides, the formats, the backends, long documents and the errors.

Get a file instead of JSON

Set output to file to receive the Markdown itself, named after the source:

curl http://127.0.0.1:8000/v1/markdown \
  -H 'Authorization: Bearer dev' \
  -F 'metadata={"output": "file"};type=application/json' \
  -F file=@pricing.html \
  -o pricing.md

The response is text/markdown; charset=utf-8 with Content-Disposition: attachment; filename="pricing.md".

What each format gives you

  • PDF: the text layer. Scanned pages have no text layer: auto reads them with OCR when the server has a model, otherwise they come back empty; see OCR.
  • Word, PowerPoint, Excel: headings, lists and tables. Slides keep their text, tables and notes; spreadsheets become one table per sheet.
  • Legacy and OpenDocument (.doc, .ppt, .rtf, .odt, .odp, .ods): converted with LibreOffice first, so expect a slower response than the OOXML equivalents.
  • HTML and web pages: the page as Markdown, including navigation and footer text. Links stay relative when the page uses relative links.
  • Email (.msg): headers and body.
  • Code and config: one fenced block tagged with the detected language.
  • ZIP: every entry converted.

The full list is in file formats.

Handle failures

  • 415 unsupported_format: the detected format cannot become Markdown, for example a video, or an image read as text: in text mode, or in auto when the server has no OCR model. Corrupt and encrypted files fail the same way. Use Inspect to check the format first.
  • 413 too_many_pages, 502 ocr_failed or 503 ocr_rate_limited: OCR errors, see OCR.
  • 413 payload_too_large or source_too_large: the document exceeds the server limit, 100 MB by default.
  • 504 processing_timeout: one step took too long. LibreOffice conversion and text extraction each stop after 120 seconds.
  • 504 deadline_exceeded: the conversion took longer than the server deadline, 300 seconds by default.

On this page