Let your model draw the UI with OpenUI
OpenUI is an MIT-licensed Generative UI framework where you define the components, it generates the system prompt from them, and a streaming renderer draws the model's OpenUI Lang output as it arrives.
TL;DR
OpenUI lets a model build interface from components you allow. You define or reuse a component library, generate a system prompt from it, and render the model's compact OpenUI Lang stream progressively. The fastest start is the scaffold command npx @openuidev/cli@latest create --name genui-chat-app.
Why this repo matters
Chat that only returns text makes users read tables and charts as prose. Model-generated JSON UI works, but the README says OpenUI Lang uses up to 67% fewer tokens than JSON (measured in its benchmarks/ folder, not re-run here) and, because it is streaming-first, the UI builds up as tokens arrive. A framework-agnostic core powers first-party runtimes for React, Vue, Svelte and Angular, and React also ships built-in component libraries and ready-made chat interfaces.
Best practices
- Let your components define what the model can generate. The README's flow is: component library, system prompt, LLM, OpenUI Lang stream, renderer, live UI.
- Generate the prompt from the library instead of hand-writing it (
generateSystemPromptin the spec's quickstart), so the prompt and renderer agree. - Pass
isStreamingto theRendererwhile tokens arrive; the spec says form interactions are disabled during streaming. - Keep stored UIs working: add props only at the end of a component's list, never reorder or remove one, and give a new required prop a default (spec overview, section 3).
- Let the client handle interactions. State (
$variables), expressions and actions run in the client, andQuery/Mutationcall tools your app provides. - Send parser errors back to the model;
result.meta.errorsidentifies the statement and problem, with available component names embedded in relevant messages, and in edit mode the model can answer with a one-line patch.
How-to
Where do I start?
1. Scaffold a working app
"What is the quickest way to see it work?" Use the CLI from the README:
npx @openuidev/cli@latest create --name genui-chat-app
The README says the scaffold gives you streaming, built-in UI and OpenUI Lang support as an end-to-end starting point. You will need a model provider key for your own runs; follow the generated app's instructions.
Next: how does the model know my components?
Try it
Define two components, Card(children) and Metric(label, value), with Zod and createLibrary. Print library.prompt() and find the two signature lines. Then parse root = Card([a,b]) with a = Metric("Open", 12) and b = PieChart("x") using createParser(library.toJSONSchema(), "Card"). You should see the valid metric kept and one unknown-component error for PieChart that lists the available components.
Pitfalls
- Do not reorder or remove props in a shipped component; stored programs use positional arguments and would break.
- Merge a patch only after it has finished streaming; the spec warns that merging earlier can drop statements a half-written
rootcannot reach yet. - Write queries as
tickets = Query(...)without$;$ticketsreads the state store, not the result. - The README states OpenUI has no official cryptocurrency or token; anything using the name is unaffiliated.
Next steps
- Docs and the Playground
- Quickstart
- Cookbooks and examples
- Language spec
- OpenUI agent skill (
npx skills add thesysdev/skills --skill openui)