Create spreadsheets & documents with Vercel AI SDK
In the Vercel AI SDK you can give the model a tool to create real spreadsheets using the tool() helper with a Zod schema. When the model calls it, your execute function hits the OpenOfficeAI API and returns a shareable URL — perfect for Next.js chat apps that need to produce documents.
import { tool } from "ai";
import { z } from "zod";
export const createSpreadsheet = tool({
description: "Create a shareable spreadsheet and return its URL.",
parameters: z.object({
title: z.string(),
rows: z.array(z.array(z.string())),
}),
execute: async ({ title, rows }) => {
const res = await fetch("https://openofficeai.com/api/v1/sheets", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.OPENOFFICEAI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ title, sheets: [{ rows }] }),
});
const { url } = await res.json();
return url;
},
});
// Pass it to generateText/streamText: tools: { createSpreadsheet }How to create a spreadsheet with Vercel AI SDK
- 1Define the tool with tool() and a Zod parameters schema.
- 2In execute, POST to /api/v1/sheets with your key from an env var.
- 3Return the url from the response.
- 4Pass the tool to generateText or streamText via the tools option.
Why use OpenOfficeAI with Vercel AI SDK
- Type-safe tool calls with Zod, runs in Next.js route handlers.
- The key stays server-side via process.env — never exposed to the client.
- Stream a chat reply that ends in an openable document link.
Frequently asked questions
Where does this run in a Next.js app?
Define the tool in a server module and use it from a Route Handler (app/api/chat/route.ts) with streamText. The execute function runs on the server, so your API key from process.env stays secret.
Does it work with any model provider?
Yes. The AI SDK abstracts the provider, so the same tool works whether you use OpenAI, Anthropic, Google, or others — as long as the model supports tool calling.
Can I render the link in the chat UI?
Yes. The tool result (the URL) is available in the message parts; render it as a clickable link or a preview card in your chat component.
Start creating documents with Vercel AI SDK
Free tier includes 500 API calls per month — no card required.
Related integrations