Skip to main content
The SuperDoc SDK ships tool definitions that plug directly into OpenAI, Anthropic, Vercel AI, or any custom LLM integration. Pick tools, send them with your prompt, dispatch the model’s tool calls — the SDK handles schema formatting, argument validation, and execution.
LLM tools are in alpha. Tool names and schemas may change between releases.

Quick start

Install the SDK, create a client, and wire up an agentic loop.
npm install @superdoc-dev/sdk openai
import { createSuperDocClient, chooseTools, dispatchSuperDocTool } from '@superdoc-dev/sdk';
import OpenAI from 'openai';

const client = createSuperDocClient();
await client.connect();
await client.doc.open({ doc: './contract.docx' });

const { tools } = await chooseTools({ provider: 'openai' });
const openai = new OpenAI();

const messages = [
  { role: 'system', content: 'You edit documents using the provided tools.' },
  { role: 'user', content: 'Find the termination clause and rewrite it to allow 30-day notice.' },
];

// Agentic loop
while (true) {
  const response = await openai.chat.completions.create({
    model: 'gpt-5.2',
    messages,
    tools,
  });

  const message = response.choices[0].message;
  messages.push(message);

  if (!message.tool_calls?.length) break;

  for (const call of message.tool_calls) {
    const result = await dispatchSuperDocTool(
      client, call.function.name, JSON.parse(call.function.arguments),
    );
    messages.push({ role: 'tool', tool_call_id: call.id, content: JSON.stringify(result) });
  }
}

await client.doc.save({ inPlace: true });
await client.dispose();

Tool selection

chooseTools() returns provider-formatted tool definitions ready to pass to your LLM.
import { chooseTools } from '@superdoc-dev/sdk';

const { tools, meta } = await chooseTools({
  provider: 'openai',   // 'openai' | 'anthropic' | 'vercel' | 'generic'
});
The current SDK returns the full grouped intent tool set for the selected provider. Group filtering and meta-discovery are not part of the shipped public API here.

Current tool set

The generated catalog currently contains 9 grouped intent tools:
ToolActionsWhat it does
superdoc_get_contenttext, markdown, html, infoRead document content in different formats
superdoc_searchmatchFind text or nodes and return handles or addresses for later edits
superdoc_editinsert, replace, delete, undo, redoPerform text edits and history actions
superdoc_formatinline, set_style, set_alignment, set_indentation, set_spacingApply inline or paragraph formatting
superdoc_createparagraph, headingCreate structural block elements
superdoc_listinsert, create, detach, indent, outdent, set_level, set_typeCreate and manipulate lists
superdoc_commentcreate, update, delete, get, listManage comment threads
superdoc_track_changeslist, decideReview and resolve tracked changes
superdoc_mutationspreview, applyExecute multi-step atomic edits as a batch
Multi-action tools use an action argument to select the underlying operation. Single-action tools like superdoc_search do not require action.

Dispatching tool calls

dispatchSuperDocTool() resolves a tool name to the correct SDK method, validates arguments, and executes the call.
import { dispatchSuperDocTool } from '@superdoc-dev/sdk';

const result = await dispatchSuperDocTool(client, toolName, args);
The dispatcher validates required parameters, enforces mutual exclusivity constraints, and throws descriptive errors if arguments are invalid — so the LLM gets actionable feedback.

Providers

Each provider gets tool definitions in its native format.
const { tools } = await chooseTools({ provider: 'openai' });
// [{ type: 'function', function: { name, description, parameters } }]

Best practices

Start with the full grouped set

The current catalog is intentionally small. In most integrations you should load the full grouped set once and let the model choose among the 9 tools.

Minimize tool calls

A typical edit should take 3-5 tool calls: read, search, mutate, done. Instruct the LLM to plan all edits before calling tools, and to batch multiple changes only when atomic execution is genuinely helpful.

Read first, then search before editing

Use superdoc_get_content to understand the document, then superdoc_search to obtain stable handles or addresses. Pass those targets into superdoc_edit, superdoc_format, superdoc_create, superdoc_list, or superdoc_comment.

Prefer focused tools; use superdoc_mutations as an escape hatch

Use the focused intent tools for straightforward edits. Reach for superdoc_mutations when you need preview/apply semantics, atomic multi-step edits, or a batched workflow that would otherwise require several target refreshes.

Feed errors back to the model

dispatchSuperDocTool surfaces structured errors from the underlying SDK and Document API. Pass these back as tool results — most models self-correct on the next turn.

Add tool call examples for repeatable actions

If your workflow involves the same kind of edit across many documents (e.g., always rewriting a specific clause, always adding a comment to a section), include a concrete tool call example in your system prompt. Models that see a working example of the exact tool invocation produce correct calls more reliably than models that only see the schema.

Include a system prompt

Tell the model what it can do and how to approach edits. You can load the bundled prompt with getSystemPrompt(), or start with something like this:
You edit `.docx` files using SuperDoc intent tools. Be efficient and minimize tool calls.

## Workflow

1. **Read** — Use `superdoc_get_content` to understand the document.
2. **Search** — Use `superdoc_search` to find stable handles or block addresses.
3. **Edit** — Use the focused tool that matches the job:
   - `superdoc_edit` for insert, replace, delete, undo, redo
   - `superdoc_format` for inline or paragraph formatting
   - `superdoc_create` for paragraphs and headings
   - `superdoc_comment` for comment threads
   - `superdoc_track_changes` for review decisions
4. **Batch only when useful** — Use `superdoc_mutations` for preview/apply or atomic multi-step edits.

Keep it to 3-5 tool calls total when possible.

## Rules

- Search before mutating so targets come from fresh results.
- Use focused intent tools for normal edits.
- Use `superdoc_mutations` when you need an atomic batch or preview/apply flow.
- Set `changeMode: "tracked"` when edits need human review.
- Feed tool errors back to the model so it can recover.

Utility functions

FunctionDescription
chooseTools(input)Load grouped tool definitions for a provider
dispatchSuperDocTool(client, name, args)Execute a tool call against a connected client
listTools(provider)List all tool definitions for a provider
getToolCatalog()Load the full tool catalog with metadata
getSystemPrompt()Read the bundled system prompt for intent tools
  • MCP Server — connect AI agents via the Model Context Protocol
  • Skills — reusable prompt templates for LLM document editing
  • SDKs — typed Node.js and Python wrappers
  • Document API — the operation set behind the tools
  • AI Agents — headless mode for server-side AI workflows