Files.toText() turns a file on the Lua CDN into text: Word, Excel, PowerPoint, email, PDF and other documents, scanned images (OCR), and audio or video (speech-to-text). It’s the same converter the platform uses for attachments in chat. Only files on the Lua CDN are read, so upload a file with CDN.upload first and pass the id it returns.
Verified against lua-cli 3.62.0.
Quick example
Methods
toText()
url, as in the SDK typings, but it takes either form: a file id or a full Lua CDN URL.
Set the file’s type when you upload it (
new File([bytes], name, { type })). The type is how the converter is picked, and a file stored without one comes back as mime_unknown.
FilesToTextResult
Errors
A file that gives no text resolves with an emptytext and an error, never an empty string on its own:
The call throws an error named
FilesToTextError only when the call itself is refused: billing_refused when the workspace is out of credits or billing can’t be reached, and files_unavailable when the runtime doesn’t support it. Inside a test session it throws test_session_tier_unsupported. Under lua test the call goes through the Lua API, so a platform outage throws UPSTREAM_UNAVAILABLE instead.
Usage and limits
- A call from a deployed tool uses one credit once the file passes its checks (it’s on the CDN, has a known, supported type, and is under 100 MB). A conversion that then fails still uses that credit. Calls from
lua testare free. - Files up to 100 MB. A conversion gets 40 seconds.
- Supported documents include doc, docx, xls, xlsx, ppt, pptx, odt, rtf, eml, msg, epub, pdf, csv, html and markdown; images (jpeg, png, tiff, bmp, heic) are read with OCR; audio and video go through speech-to-text.
- Plain-text files (txt, csv, tsv, markdown, json) come back exactly as stored, line breaks and commas included.
maxCharscuts them at a character count, so a cut CSV or JSON can end mid-row or mid-object (checktruncated).

