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, and .xlsx files using the Vercel AI SDK.

Installation

pnpm add office-open ai

Requires the Vercel AI SDK (ai package) v6+.

Tools

Four tools are provided — one per document type plus an on-demand schema lookup:

ToolDescription
generate-docxGenerate a .docx Word document
generate-pptxGenerate a .pptx presentation
generate-xlsxGenerate a .xlsx spreadsheet
office-open-schema-lookupFetch 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:

  1. Call office-open-schema-lookup with { type, definitions: [...] } for the option types you are about to fill (e.g. ParagraphOptions, RunOptions, TableOptions). Names come from the skeleton stubs, or from npx office-open schema index <type>.
  2. Fill the options and call the generate tool.
  3. 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.

Copyright © 2026