Generate OPF decks with the Vercel AI SDK
Use the AI SDK's generateObject with a Zod schema to make any supported model return typed, OPF-shaped JSON.
How it works
The AI SDK's generateObject takes a Zod schema and returns a typed object that matches it, using whichever provider and model you configure. Because OPF is plain JSON with a flat, predictable shape, a compact Zod schema is enough to get well-formed decks from any structured-output-capable model.
One schema works across providers — the same Zod definition drives OpenAI, Anthropic, and Google models through the AI SDK, so you can switch models without touching your deck-generation code.
Zod schema
This is a compact starter schema, not the full OPF schema. Use the schema reference when you need more OPF fields such as narratives, design hints, or multi-audience metadata.
import { z } from "zod"
export const opfDeckSchema = z.object({
$schema: z
.literal("https://openpresentation.org/schema/opf/v1")
.describe("The OPF schema URL. Always use this exact value."),
name: z.string().describe("Short title for the presentation."),
audience: z
.string()
.describe("The intended audience, as a free-form description or audiences catalog id."),
tone: z
.string()
.describe("The tone of the deck, such as formal, executive, technical, or sales."),
slides: z
.array(
z.object({
layout: z
.enum([
"title",
"title-subtitle",
"section",
"content",
"bullets",
"two-column",
"quote",
"closing",
])
.describe("Renderer layout hint."),
title: z.string().describe("Concise slide title."),
subtitle: z.string().optional().describe("Optional slide subtitle."),
text: z.string().optional().describe("Short body paragraph for the slide."),
items: z.array(z.string()).optional().describe("Bullet points or short takeaways."),
}),
)
.min(1)
.describe("Ordered slides in the deck."),
})Generate a deck
A minimal example using generateObject:
import { generateObject } from "ai"
import { opfDeckSchema } from "./opf-deck-schema"
const { object: deck } = await generateObject({
// Works with any AI SDK provider that supports structured output.
model: "anthropic/claude-opus-4-8",
schema: opfDeckSchema,
prompt: `Create an Open Presentation Format (OPF) JSON deck for this brief:
Topic: A 10-minute board update on Q2 customer retention.
Audience: Board of Directors.
Slide count: 6.
Tone: Formal and concise.`,
})
// deck is fully typed from the Zod schemaValidate
Zod validates the model output against your starter schema at runtime, but OPF tooling should still validate the finished file against the canonical schema at https://openpresentation.org/schema/opf/v1 before rendering. The validation guide shows how with Ajv and ajv-cli.
Vercel documents generateObject and provider support in the AI SDK structured data guide.