Skip to main content
Document API gives you a consistent way to read and edit documents without relying on editor internals.
Document API is in alpha and subject to breaking changes while the contract and adapters continue to evolve. The current API is not yet comprehensive, and more commands and namespaces are being added on an ongoing basis.

Why use Document API

  • Build automations without editor-specific code.
  • Work with predictable inputs and outputs defined per operation.
  • Check capabilities up front and branch safely when features are unavailable.

Reference

  • Full operation reference: /document-api/reference/index
  • Machine-readable files are available for automation use (contract schema, tool manifest, and agent compatibility artifacts).

Available operations

Use the tables below to see what operations are available and where each one is documented.
NamespaceOperationsReference
Core8Reference
Capabilities1Reference
Create2Reference
Format4Reference
Lists8Reference
Comments11Reference
Track Changes6Reference
Editor methodOperation ID
editor.doc.find(...)find
editor.doc.getNode(...)getNode
editor.doc.getNodeById(...)getNodeById
editor.doc.getText(...)getText
editor.doc.info(...)info
editor.doc.insert(...)insert
editor.doc.replace(...)replace
editor.doc.delete(...)delete
editor.doc.format.bold(...)format.bold
editor.doc.format.italic(...)format.italic
editor.doc.format.underline(...)format.underline
editor.doc.format.strikethrough(...)format.strikethrough
editor.doc.create.paragraph(...)create.paragraph
editor.doc.create.heading(...)create.heading
editor.doc.lists.list(...)lists.list
editor.doc.lists.get(...)lists.get
editor.doc.lists.insert(...)lists.insert
editor.doc.lists.setType(...)lists.setType
editor.doc.lists.indent(...)lists.indent
editor.doc.lists.outdent(...)lists.outdent
editor.doc.lists.restart(...)lists.restart
editor.doc.lists.exit(...)lists.exit
editor.doc.comments.add(...)comments.add
editor.doc.comments.edit(...)comments.edit
editor.doc.comments.reply(...)comments.reply
editor.doc.comments.move(...)comments.move
editor.doc.comments.resolve(...)comments.resolve
editor.doc.comments.remove(...)comments.remove
editor.doc.comments.setInternal(...)comments.setInternal
editor.doc.comments.setActive(...)comments.setActive
editor.doc.comments.goTo(...)comments.goTo
editor.doc.comments.get(...)comments.get
editor.doc.comments.list(...)comments.list
editor.doc.trackChanges.list(...)trackChanges.list
editor.doc.trackChanges.get(...)trackChanges.get
editor.doc.trackChanges.accept(...)trackChanges.accept
editor.doc.trackChanges.reject(...)trackChanges.reject
editor.doc.trackChanges.acceptAll(...)trackChanges.acceptAll
editor.doc.trackChanges.rejectAll(...)trackChanges.rejectAll
editor.doc.capabilities()capabilities.get

Common workflows

These patterns show how operations compose to cover typical tasks.

Find and mutate

Locate text in the document, then replace it:
const result = editor.doc.find({ type: 'text', text: 'foo' });
const target = result.context?.[0]?.textRanges?.[0];
if (target) {
  editor.doc.replace({ target, text: 'bar' });
}

Tracked-mode insert

Insert text as a tracked change so reviewers can accept or reject it:
const receipt = editor.doc.insert(
  { text: 'new content' },
  { changeMode: 'tracked' },
);
The receipt includes a resolution with the resolved insertion point and inserted entries with tracked-change IDs.

Check capabilities before acting

Use capabilities() to branch on what the editor supports:
const caps = editor.doc.capabilities();

if (caps.operations['format.bold'].available) {
  editor.doc.format.bold({ target });
}

if (caps.global.trackChanges.enabled) {
  editor.doc.insert({ text: 'tracked' }, { changeMode: 'tracked' });
}

Dry-run preview

Pass dryRun: true to validate an operation without applying it:
const preview = editor.doc.insert(
  { target, text: 'hello' },
  { dryRun: true },
);
// preview.success tells you whether the insert would succeed
// preview.resolution shows the resolved target range

Programmatic invocation

Every operation is also available through a dynamic invoke method on the Document API instance. It accepts an operationId string and dispatches to the corresponding method. This is useful when the operation to run is determined at runtime (for example, from a tool-use payload).
// doc is the DocumentApi instance (editor.doc)
const result = doc.invoke({
  operationId: 'insert',
  input: { text: 'hello' },
  options: { changeMode: 'tracked' },
});
invoke delegates to the same direct methods — there is no separate execution path. Type safety is available through InvokeRequest<T> for callers who know the operation at compile time, and DynamicInvokeRequest for dynamic dispatch.