Skip to main content

Documents

Sending document HTML

Send your document HTML in document_html. The AI reads it, makes changes, and returns updated HTML in document_changes.updated_html. The server keeps your document between turns. Once a session holds a document, you don’t re-send it every turn. Send just the message and the AI works on the copy it already has. Include document_html only to load a document into a session the first time, replace it wholesale, or sync edits you made to the HTML outside of chat (covered below). The one rule, for when you do send HTML back: send it faithfully. If the user edited the document in your own editor and you’re syncing those edits, send the full current HTML exactly as your editor has it. Don’t programmatically strip, modify, or reformat it. If your editor or HTML sanitizer removes custom data-* attributes, configure it to preserve them. Those data-chunk-id attributes are what let the AI make targeted edits.

Example flow

The returned HTML contains data-chunk-id attributes on elements. These identify document sections and enable the AI to make targeted edits without reprocessing the entire document. These same IDs appear in API responses — for example, chunk_id and insert_after_chunk_id in HITL proposed changes. If you make an edit you want to undo, you can rewind both the chat history and the document state to before any user message — see Revert a session to a previous message.

Loading documents from files

Upload a file to load it as the active document in a session. The file is processed synchronously — the response includes the full document HTML ready for editing. Supported formats: DOCX, DOC, ODT, PDF, TXT, HTML, MD (Markdown), RTF
Response:
Multiple documents per session. By default an upload replaces the session’s focused document. Pass open_mode=new_focused to open the file as an additional document (and focus it), or open_mode=background to open it without stealing focus. The response also includes the session’s document roster (every open document’s id + title + which is focused) so you can render tabs immediately. See the Multi-Document Sessions guide. Page geometry. For DOCX and PDF uploads, document payloads include a nullable page_setup object — detected page dimensions (width_in / height_in), per-side margins (margin_in), and orientation — anywhere a document is returned (upload responses, the session-documents roster, session history). It’s null when the source format carries no geometry (e.g. plain text or HTML).
After uploading, you can immediately send chat messages to edit the document:

Creating documents from scratch

Send a message to an empty session (no document_html, no uploaded file) and the AI will generate a complete document for you.
Example prompts that work well:
  • “Create a consulting agreement”
  • “Draft a project proposal for a mobile app”
  • “Write a company privacy policy”
  • “Create a meeting minutes template”
The AI generates structured, formatted HTML that you can then continue editing with follow-up messages.

Exporting documents

Export the current document as a downloadable file. Three ways to supply the document:
  • Inline HTML — send HTML content in html (use when you have the document HTML in your app, up to 20 MB)
  • Export from a session — send a session_id (the API retrieves the document from the session)
  • Pre-signed upload then export — upload the HTML to a pre-signed URL first, then send upload_id (use for documents between 20 MB and 100 MB — see Large documents below)
Five output formats:
  • docx (default) — Microsoft Word (Open XML), preserves tables, formatting, embedded images
  • pdf — paginated, print-ready PDF
  • html — standalone HTML file with inlined CSS
  • markdown — Markdown (.md) with ATX headings
  • txt — plain text
A sixth value, doc (Word-compatible HTML wrapper), is accepted as a legacy alias and will be removed in a future release. New integrations should use docx.

Export from inline HTML

Export from a session

Export in Python

Request parameters

Export options

Pass an options object to customise the rendered output. Defaults are sensible for English-language documents; override only what you need.
The response is a binary file download with the appropriate Content-Type header. The Content-Disposition header carries the filename (RFC 5987 encoded for non-ASCII characters).

Non-fatal warnings

Exports may complete successfully but with non-fatal issues — an image URL that 404’d, a diagram that exceeded the render timeout, an unsupported field code that was skipped. The response carries these in the X-Export-Warnings header as a base64-encoded JSON list. The header is always present alongside Content-Disposition in Access-Control-Expose-Headers, so browser clients can read it via fetch.

Large documents

There’s one size story for export, driven by how big the document HTML is: Three-tier flow: Keep inline POSTs at or under 20 MB. Above that, the hosted transport layer rejects the request (a hard ~32 MB clamp sits in front of the renderer), so switch to the upload-then-export pattern (PUT the HTML to a pre-signed URL, then export by upload_id) rather than pushing a bigger body through directly.
The signed URL is valid for 5 minutes; the uploaded blob is retained for 24 hours.

Email fallback for very large documents

For documents over 100 MB, render asynchronously and deliver via email. The endpoint accepts a session ID, queues a background job, and emails a 7-day signed download link to the recipient.
Response:
recipient_email falls back to the email on file for the authenticated user account when omitted. The job appears in /v1/jobs/{job_id} with job_type: "large_export". See Async jobs for the polling pattern.

Size and error responses

Keep inline POSTs at or under 20 MB; the hosted transport layer enforces a hard ~32 MB clamp and returns 413 Request Entity Too Large before reaching the renderer, so use the pre-signed upload-then-export pattern for anything larger. Requests above the format-specific cap return a structured 413 with a JSON body explaining the limit and pointing to the email-fallback endpoint — see Error codes.

Supported formatting

The AI can apply the following formatting when creating or editing documents:
  • Text styling — bold, italic, underline, strikethrough
  • Headings — H1 through H6
  • Lists — ordered, unordered, and nested
  • Text highlighting — with color options (e.g., yellow, green, red)
  • Text color — change the color of specific text
  • Links — clickable hyperlinks
  • Tables — with rows and columns
  • Blockquotes — indented quotation blocks
  • Code blocks — for code snippets
  • Horizontal rules — section dividers
Ask for formatting in plain language: “highlight the key terms in yellow”, “make the title bold and larger”, “add a table comparing the two options”.