Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Learn the difference between array and object output modes with streamObject from the AI SDK.
This is a Next.js project that uses the streamObject function from the Vercel AI SDK to stream structured objects. This project showcases the new output mode which allows you to stream structured objects by complete object rather than by token. This solves layout shift issues common to AI applications using structured object generation.
streamObject from the Vercel AI SDK to generate and stream structured data.This template is ideal for developers looking to build AI applications that require reliable and visually stable streaming of structured data. It's particularly useful for:
First, clone the repository:
git clone https://github.com/vercel-labs/structured-object-generation-array-mode.gitThen, install the dependencies:
pnpm installCopy the .env.example file to .env.local and fill in the required environment variables:
OPENAI_API_KEY=sk-...
Finally, run the development server:
pnpm devOpen http://localhost:3000 with your browser to see the result.
To learn more about Next.js, take a look at the following resources:
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.