API reference · Documents
GET/api/documents/download/{fileId}

Download or export document file

Downloads a stored document file, or exports the document as PDF or Markdown based on the optional format query parameter. The fileId path value may be either a documents.document_id or an external_files.file_id. The route requires an Auth.js session cookie and runs within the session tenant. The normal download path uses document read permission and document authorization rules; PDF and Markdown export paths perform tenant-scoped document lookup and generation.

Path parameters

fileIdstring <uuid>Required
Document UUID or file UUID. The download handler resolves document_id first, then file_id.

Query parameters

formatstringOptional
Optional export format. pdf generates a PDF; markdown or md exports markdown; omitted downloads the original stored file.

Response codes

200
File bytes for the original stored file, generated PDF, or Markdown text. Content-Type varies by requested format and stored MIME type.
400
Invalid or missing fileId.
401
No valid session is present.
404
Document or file was not found, has no associated file, or has no exportable content.
500
Export, generated-PDF download, storage, or unexpected internal failure.