Getting Started
AI Tools
Use AI SDK tools to generate Office documents from AI agents
The office-open package provides AI SDK tools that allow AI agents (Claude, GPT, etc.) to generate .docx, .pptx, .xlsx, .odt, .rtf, .ods, and .odp files using the Vercel AI SDK.
#Installation
pnpm add office-open ai
npm install office-open ai
yarn add office-open ai
bun add office-open ai
Requires the Vercel AI SDK (ai package) v6+.
#Tools
Eight tools are provided — one per supported root format plus an on-demand schema lookup:
| Tool | Description |
|---|---|
generate-docx | Generate a .docx Word document |
generate-pptx | Generate a .pptx presentation |
generate-xlsx | Generate a .xlsx spreadsheet |
generate-odt | Generate an .odt OpenDocument text document |
generate-rtf | Generate an .rtf Rich Text Format document |
generate-ods | Generate an .ods OpenDocument spreadsheet |
generate-odp | Generate an .odp OpenDocument presentation |
office-open-schema-lookup | Fetch the JSON Schema for option definitions on demand |
Each generate tool validates the input with JSON Schema (ajv) before generating. Validation errors include the instance path (e.g. at "sections.0.children.1.paragraph.children") so the model can fix and retry.
#Progressive Disclosure
The full format schema is far too large for a tool definition (~675 KB for docx), so the generate tools carry a skeleton input schema: the top-level shape plus the child wrapper keys, with stubs naming the definitions they stand for. The workflow is:
- Call
office-open-schema-lookupwith{ type, definitions: [...] }for the option types you are about to fill (e.g.ParagraphOptions,RunOptions,TableOptions). Names come from the skeleton stubs, or fromnpx office-open schema index <type>. - Fill the options and call the generate tool.
- If validation rejects the input, fix the reported paths and retry — up to five issues are reported per call.
A lookup returns the requested definitions plus their dependency closure; cataloged domains you did not request stay as expandable stubs, so request each domain root you need. At most 8 definitions per call; unknown names return closest-match suggestions instead of an error.
Provider strict structured-output modes (which require additionalProperties: false everywhere) are not supported by the skeleton; validation is owned by the tool's execute via ajv.
#Usage
import { generateText } from "ai";
import { officeOpenTools } from "office-open/ai";
const result = await generateText({
model,
prompt: "Create a quarterly report document",
tools: officeOpenTools,
});
#Tool Input
Each tool accepts the document options directly (no wrapping — pass the document structure as-is):
#generate-docx
{
"sections": [
{
"children": [{ "paragraph": { "children": [{ "text": "Hello, World!", "bold": true }] } }]
}
]
}
#generate-pptx
{
"title": "My Presentation",
"slides": [
{
"children": [
{
"shape": {
"x": 100,
"y": 100,
"width": 760,
"height": 340,
"textBody": {
"paragraphs": [{ "children": [{ "text": "Hello, World!", "size": 32 }] }]
}
}
}
]
}
]
}
#generate-xlsx
{
"worksheets": [
{
"name": "Sheet1",
"rows": [
{ "cells": [{ "value": "Name" }, { "value": "Score" }] },
{ "cells": [{ "value": "Alice" }, { "value": 95 }] }
]
}
]
}
#Tool Output
Each tool returns a base64-encoded file:
{
"base64": "...",
"mimeType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}
#JSON Schemas
The full schemas and the slicing API are exported for custom use:
import {
docxSchema,
pptxSchema,
xlsxSchema,
validateDocumentInput,
sliceDocumentSchema,
SCHEMA_ENTRIES,
} from "office-open/schemas";
// Extract the dependency closure of specific option types:
const slice = sliceDocumentSchema("docx", ["ParagraphOptions", "RunOptions"]);
The same lookup is available on the CLI (npx office-open schema index docx, npx office-open schema slice docx ParagraphOptions).
For full schema details, refer to the DOCX, PPTX, and XLSX documentation.