Why generate UI?
Ask a model a question about data and it answers with paragraphs. Ask it through generative UI and it answers with a chart, a table and a callout drawn from components your app already has. This lesson shows the difference, the four ways projects do it, and where OpenUI sits among them.
By the end of this lesson you can
- say what an interface answer gives the user that a text answer does not;
- name the four generative UI paradigms and what travels from the model in each;
- place real projects in the right paradigm;
- quote OpenUI's token and latency figures together with the caveats that come with them;
- describe what makes OpenUI different from the other three paradigms.
Same question, two answers
The question is "How did Q3 revenue break down by region?". On the left is the kind of answer a chat model gives by default: Markdown text. On the right is the same answer written in OpenUI Lang, the compact language an OpenUI model writes instead, and the interface it turns into. Both stream at the same speed, 120 characters per second, which is roughly what a hosted model produces.
Text answer (Markdown)
Interface answer (OpenUI Lang)
Things to look for
- The two answers are about the same length. An interface answer does not have to cost more output than a paragraph.
- The interface starts to appear after the first line. The model writes
root = Stack([title, metrics, chart, tbl])first and fills in the pieces below it, so the layout is known before the data arrives. - In the text answer, the reader has to compare four numbers in their head. In the interface answer, the bar chart does the comparison and the table keeps the exact figures.
- Every component on the right (
TextContent,Callout,BarChart,Table) comes from a library the app defined. The model chose which ones to use and filled them with data; it did not invent HTML.
The interface on this page is drawn by the course's teaching simulator, a subset of @openuidev/react-lang that renders a few stock components as plain HTML. A real app renders its own React components.
Four ways to answer with an interface
Every generative UI system has to answer one question: what does the model actually produce, and who turns it into pixels? There are four common answers. In the first two the model composes the layout itself; in the last two it calls a tool and someone else decides what the interface looks like.
What travels from the model, and who draws it
- DSL streaming. The model writes a small domain-specific language, one complete statement per line. A renderer in the browser parses the text after every chunk and draws the finished lines with your components, so the interface grows while the model is still writing. OpenUI Lang works this way.
- JSON spec. The model writes a JSON description of the interface against a catalog of allowed component types. It is constrained and easy to validate, but every node repeats keys such as
typeandprops, and a JSON document is not valid until its brackets close, so these systems stream patches or repair partial JSON. json-render, A2UI and Thesys C1 JSON work this way. - Tool call to component. The model does not describe a layout at all. It calls a tool, and the app has decided ahead of time that this tool's result is drawn by one particular component, such as a weather card. Reliable and simple, but the model can only show interfaces someone built for that exact tool.
- Iframe app. The model calls a tool on a server, and the server returns its own interface as HTML, which the host shows in a sandboxed iframe. MCP Apps (a
ui://resource) and the OpenAI Apps SDK work this way. The server's author designed the interface; the model only decided to call the tool. - OpenUI is a DSL streaming system: the model composes the layout from your components and the interface renders while it streams. The next lesson adds the part that sets it apart, a runtime that keeps the interface live without the model.
Key idea
The paradigms differ in who decides the layout. In DSL streaming and JSON spec the model decides, within the components you allow. In tool call to component the app decides, one component per tool. In iframe apps the tool's server decides, with its own HTML.
Sort the approaches
Put each approach in its paradigm. The question to ask every time: what does the model actually emit, and who designed the interface the user sees?
- The model writes
root = Stack([title, chart])and then one line per component. This is OpenUI Lang: a line-oriented language, rendered statement by statement while it streams. - json-render: the model streams JSON Patch operations that add elements from a component catalog. The output is JSON describing the tree (as JSONL patches), validated against a catalog.
- A2UI: an agent sends a declarative interface description, and the client maps it to trusted native components. A declarative JSON description against components the client trusts: a JSON spec.
- The model calls
get_weather, and the chat app always shows its ownWeatherCardfor that tool's result. The model chose a tool, not a layout. The app mapped the tool to one fixed component. - A React chat library lets you register a component for a tool name, and renders that component whenever the tool is called. Tool UIs of this kind (assistant-ui offers them) are the tool call to component paradigm.
- An MCP server answers a tool call with a
ui://HTML resource, and the host shows it in a sandboxed iframe. This is MCP Apps. The server shipped the interface; the model only called the tool. - A ChatGPT app built with the OpenAI Apps SDK shows its widget inside the conversation. The app's server provides the widget's HTML and the host runs it in an iframe.
- The model writes a patch of two changed lines, and the existing interface updates without being regenerated. Line-oriented statements can be replaced one at a time by name. OpenUI's edit mode does this (lesson 13).
What the format costs: OpenUI's own benchmark
Output tokens are what a user waits for, because a model writes them one at a time. OpenUI publishes a benchmark that encodes the same interfaces in four formats and counts the tokens. The figures below are OpenUI's own numbers, copied from its benchmark page; this course did not reproduce them.
| Format | Bar | Tokens, 7 scenarios | Contact form at 60 tok/s |
|---|---|---|---|
| OpenUI Lang | 4,800 | 4.90 s | |
| YAML spec | 9,122 | 12.70 s | |
| Thesys C1 JSON | 9,948 | 14.15 s | |
| Vercel json-render (JSONL) | 10,180 | 14.88 s |
Taken at face value, OpenUI Lang needs about half the tokens of the JSON formats across the seven scenarios (47 to 53 percent fewer), and up to 67 percent fewer for the best case, the contact form. The reason is structural: a JSON tree repeats type, props and children for every node, while OpenUI Lang passes arguments by position and names each statement once.
Vendor claim: read the method
The benchmark has seven scenarios, generated once by one model (GPT-5.2) at temperature 0, as OpenUI Lang. The YAML, json-render and C1 versions were converted from that same output, not written by a model in those formats, so the comparison measures encoding size, not how well a model writes each format. Tokens were counted with one tokenizer (tiktoken, the gpt-5 encoder). The token column sums all seven scenarios. The latency column covers the contact form alone: its token count (294 for OpenUI Lang) divided by a constant 60 tokens per second, which ignores time to first token and the network. Treat the ratio as a direction, and measure your own components with your own model before relying on it.
OpenUI rule
The benchmark page itself says the latency model "assumes constant throughput (60 tok/s). Real latency also depends on TTFT and network", and that the streaming advantage is most visible for the last element to render.
Where OpenUI fits
OpenUI is a DSL streaming system with three properties that, together, define it:
- The model composes, you constrain. The model may use only the components in your component library, each described by a Zod schema. The same library generates the model's instructions and validates what it writes.
- It renders while it streams. OpenUI Lang is line-oriented and allows forward references, so the model writes the layout first and the browser shows it before the details arrive.
- The interface keeps working after the model stops. The model can write state (
$city), data fetching (Query), writes (Mutation) and button actions into the program. The browser runs them, without another model call. This is the subject of the next lesson.
It is not the right tool for everything. When a tool always deserves the same hand-built interface, mapping the tool to a component is simpler. When a third party owns both the tool and its interface, an iframe app keeps their code out of yours. OpenUI fits best when the model should decide what to show, from parts you trust: data answers, dashboards, forms and tool-connected views in a chat or an agent.
Break it: stop the stream halfway
Go back to the side-by-side answers and press Restart, then press Step until the raw stream reaches line 4, chart = BarChart(regions, [rev], "grouped"). Before you look, predict: what does each answer show if the connection drops right there?
What should happen
The text answer stops mid-sentence. Whatever was written is readable, but the comparison the user asked for may be missing.
The interface answer already shows the heading and the callout with the total, because those statements finished. The chart is declared but its data, regions and rev, has not arrived, so those references are still unresolved and the table has not started. The real parser drops what it cannot resolve yet; this simulator draws grey placeholders there so you can see where they will go. Nothing is broken: as soon as the next lines arrive, the chart and table fill in. That is the payoff of writing the layout first.
Quick check
The model calls search_flights and the app always draws the result with its own FlightList component. Which paradigm is this?
Which statement about OpenUI's token benchmark is accurate?
Why can an OpenUI Lang answer show a useful interface before it has finished streaming?
root first. The parser updates the tree after every chunk, and the Renderer draws whatever statements are complete. A single JSON document is not valid until its brackets close; JSONL patch formats such as json-render work around that.Recap
- An interface answer can cost about the same output as a text answer, and it shows comparisons the reader would otherwise do in their head.
- Four paradigms: DSL streaming and JSON spec (the model composes the layout), tool call to component (the app maps a tool to a fixed component), iframe app (the server ships its own HTML).
- OpenUI's benchmark reports about half the tokens of JSON formats. It is a vendor benchmark: one model, converted formats, one tokenizer, latency estimated at 60 tokens per second.
- OpenUI is DSL streaming from your own component library, with a runtime that keeps the interface live without the model.