Skip to main content
SuperDoc can run headless in Node.js for server-side document processing, AI agent workflows, and batch automation.

Quick example

import { Editor } from 'superdoc/super-editor';
import OpenAI from 'openai';

const openai = new OpenAI();
const completion = await openai.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'Write a service agreement in HTML.' }],
});

const editor = await Editor.open(templateDocx);
editor.commands.insertContent(completion.choices[0].message.content, {
  contentType: 'html',
});
const docx = await editor.exportDocx();

Content formats

editor.commands.insertContent(value, { contentType: 'html' });      // Recommended for LLMs
editor.commands.insertContent(value, { contentType: 'markdown' });
editor.commands.insertContent(value, { contentType: 'text' });
editor.commands.insertContent(value, { contentType: 'schema' });     // ProseMirror JSON
See Import/Export for format details, limitations, and guidance on choosing a format.

AI redlining with track changes

Use suggesting mode so AI edits appear as tracked changes that users can accept or reject:
const contract = await readFile('./contract.docx');
const editor = await Editor.open(contract, {
  documentMode: 'suggesting',
});

// AI suggestions are tracked — users review them in Word
editor.commands.insertContent(aiRevisions, { contentType: 'html' });
const redlined = await editor.exportDocx();

LLM quick reference

Point your AI assistant at these URLs for SuperDoc context:
https://docs.superdoc.dev/llms.txt        // Quick reference
https://docs.superdoc.dev/llms-full.txt   // Complete documentation

Next steps