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

Three tools are provided, one for each document type:

ToolDescription
generate-docxGenerate a .docx Word document
generate-pptxGenerate a .pptx presentation
generate-xlsxGenerate a .xlsx spreadsheet

Each tool validates the input with Zod schemas before generating, providing clear error messages when the AI produces invalid structures.

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": { "children": [{ "text": "Hello, World!", "fontSize": 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"
}

Zod Schemas

The schemas used for validation are also exported for custom use:

import { docxSchema, pptxSchema, xlsxSchema, validateDocumentInput } from "office-open/schemas";

For full schema details, refer to the DOCX, PPTX, and XLSX documentation.

Copyright © 2026