The Open Standard for Generative UI
OpenUI Svelte Chat
A chat application built with SvelteKit, Vercel AI SDK, and @openuidev/svelte-lang — demonstrating how to render structured LLM output as live Svelte components.
How it works
- User sends a message via the chat input
- Server streams a response using the Vercel AI SDK with OpenAI, guided by a system prompt written in openui-lang syntax
@openuidev/svelte-langRenderer parses the streaming openui-lang text and renders it as Svelte components in real time- Tool calls (weather, stocks, math, web search) are displayed inline with status indicators
Setup
Prerequisites
- Node.js 18+
- pnpm, npm, or Bun
- An OpenUI Cloud API key (https://console.thesys.dev/keys)
Install dependencies
From this example directory:
pnpm install --ignore-workspace
Configure environment
cp .env.example .env
Edit .env and add your OpenUI Cloud API key:
THESYS_API_KEY=sk-th-...
Run
pnpm dev
Open http://localhost:5173.
Project structure
src/
├── routes/
│ ├── +page.svelte # Chat UI with AI SDK Chat class + OpenUI Renderer
│ ├── +layout.svelte # Root layout (imports Tailwind)
│ ├── +layout.ts # Disables SSR (client-side rendering)
│ └── api/chat/+server.ts # AI SDK streaming endpoint
├── lib/
│ ├── library.ts # OpenUI component definitions (Stack, Card, TextContent, Button)
│ ├── tools.ts # AI tool definitions (weather, stocks, math, search)
│ └── components/ # Svelte component renderers
│ ├── Stack.svelte
│ ├── Card.svelte
│ ├── TextContent.svelte
│ └── Button.svelte
Adding components
- Create a Svelte component in
src/lib/components/ - Define it with
defineComponent()insrc/lib/library.ts - Export it from
src/lib/library.ts; the API builds the system prompt from the library at runtime
See the @openuidev/svelte-lang README for the full API.
Verify
pnpm verify