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 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

The model What it sends Who draws it 1. DSL streaming writes the UI line by line root = Stack([title, chart]) chart = BarChart(labels, [s]) Renderer + your components draws each line as it lands 2. JSON spec writes the UI as JSON {"type": "BarChart", "props": {"labels": […]}} Catalog renderer maps types to your components 3. Tool call to component calls a tool with arguments get_weather({city: "Pune"}) plus the tool's result Your app one fixed component per tool 4. Iframe app calls a tool on a server ui://weather/card.html the server's own HTML Sandboxed iframe the server designed the UI OpenUI Lang lives in this row
  1. 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.
  2. 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 type and props, 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.
  3. 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.
  4. 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.
  5. 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 own WeatherCard for 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.

Output tokens for seven benchmark scenarios combined, per format
FormatBarTokens, 7 scenariosContact form at 60 tok/s
OpenUI Lang4,8004.90 s
YAML spec9,12212.70 s
Thesys C1 JSON9,94814.15 s
Vercel json-render (JSONL)10,18014.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:

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?

  • DSL streaming
  • JSON spec
  • Tool call to component
  • Iframe app
The model chose a tool, not a layout. The app decided in advance which component draws that tool's result. In DSL streaming or JSON spec, the model would compose the layout itself.

Which statement about OpenUI's token benchmark is accurate?

  • A model was asked to write each format separately, and OpenUI Lang came out shortest
  • The latency figures were measured end to end against real providers
  • One model output in OpenUI Lang was converted into the other formats, and the encodings were counted with one tokenizer
The other formats were converted from the same OpenUI Lang output, so the benchmark compares encoding size. Latency is the token count divided by a constant 60 tokens per second, with no time to first token or network.

Why can an OpenUI Lang answer show a useful interface before it has finished streaming?

  • The model sends the finished interface first and the text afterwards
  • Statements are line-oriented, root comes first, and the parser updates the tree after every chunk
  • The browser waits for the closing bracket, then renders everything at once
Line-oriented statements and forward references let the model write 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