The Open Standard for Generative UI
Vercel AI SDK
An OpenUI example showing how to wire a Vercel AI SDK streamText backend to OpenUI's <AgentInterface />.
What this demonstrates
- Using
vercelAIAdapter()andvercelAIMessageFormatwith OpenUI's<AgentInterface /> - A Next.js route that calls
streamTextagainst OpenUI Cloud Completions (openai.chat(...)) - Server-side tools (
get_weather,get_stock_price,search_web) via the AI SDKtool()helper, looping up to 5 steps
Getting started
- Mint an OpenUI Cloud key into
.env.local:
pnpm generate:apiKey
- Install dependencies from this example directory:
pnpm install --ignore-workspace
- Run the dev server from this directory:
pnpm dev
Open http://localhost:3000 to see the chat interface.
How it works
The server (src/app/api/chat/route.ts) uses streamText with Cloud Completions (POST /v1/embed/chat/completions), cloudInstructions() (generated openuiLibrary spec), and the tools in src/lib/tools.ts. It returns toUIMessageStreamResponse() — the Vercel AI SDK's native UIMessage stream.
The frontend (src/app/page.tsx) renders <AgentInterface /> with fetchLLM({ streamAdapter: vercelAIAdapter(), messageFormat: vercelAIMessageFormat }). Storage is omitted, so AgentInterface uses its built-in in-memory default (wiped on reload).
To add more tools, define them with tool() in src/lib/tools.ts and pass them to streamText.
Learn more
Verify
pnpm verify