Production checklist
A demo runs in one trusted place. A shipped app has a browser anyone can open the dev tools in, an API that talks to the model and your data, and a bill. Most OpenUI production work is deciding which of those places each piece of the loop lives in.
By the end of this lesson you can
- draw the trust boundary of an OpenUI app and say what the browser may and may not send;
- explain why runtime tools make your tool API a public attack surface, and what it must check;
- apply the rendering rules: CSS layer order, a module-scope
componentsobject, and no fetching while a response streams; - choose between a query retry and a regenerate, and wire
onError; - say which telemetry flags exist and what Gateway and Autofix are for, without assuming you need them.
Four parties, one boundary
An OpenUI app has four parties. The browser runs the Renderer and everything the user can touch. Your API holds the system prompt, the model credentials and the tool implementations. The tools are your own code and data. The model writes OpenUI Lang. The dashed line in the figure is the trust boundary: everything left of it is controlled by whoever is sitting at the keyboard.
What crosses the boundary
- The browser sends a prompt and history, nothing else. The route's body schema has no field for a system prompt or a model name, so a forged request cannot supply them.
- Your API adds what must be trusted. The system prompt was built once on the server and the model was chosen by the server. Only then does the call to the model happen.
- The model streams plain text back. Your API forwards the chunks and the browser parses the growing text as each chunk arrives.
- The program contains a
Query. ThetoolProviderruns in the browser, so this call comes from the user's browser, not from the model and not from your server. It carries whatever arguments the program, or a tampered request, contains. - Your tool endpoint is the real gate. It looks the tool up by name, validates the arguments, authorizes the caller, runs the tool and validates the result.
Key idea
The model is not the only author of what reaches your tools. With runtime tools, a Query is a request made by the user's browser, so your tool API must be written as if it were any public endpoint: the model's good behaviour is not a control.
The simulator in this course has no server, so there is nothing to attack in its fake tools. The code boxes below are illustrations from a real app shape, not runnable on their own.
The checklist
Work through the groups below. Ticks are saved in this browser so you can come back to them. Each item states the rule and where the reasoning lives in this course.
Prompt
Tools
Model
Rendering
Errors
Telemetry and optional services
Security principle
Build the prompt in your backend, call tools only through an API you control, and treat the browser as untrusted. The language and the Renderer work with any model provider; nothing in the library forces a particular host.
The server half, in one file
The reference stream route is short on purpose. Its body schema accepts prompt and messages, the system prompt arrives as a function argument built elsewhere, and the model is a parameter of the factory, so the request cannot change either. The route never names a provider: any AI SDK model works.
One gap is left to you, deliberately: authentication and rate limiting wrap the route in whatever your framework uses. History entries from the client are also untrusted text, so cap their count and size.
The tool endpoint is the gate
The reference registry defines each tool once with a Zod input and output schema. Three consumers derive from that: the prompt, the browser's toolProvider and server-side model tool calls. Every browser call lands in runTool, which is where the checks live.
Read it as a template. Unknown tool names get not-found. Invalid arguments get invalid-args with a readable message. A handler that throws becomes failed, so the browser sees a failed query instead of a stack trace. What the snippet does not contain is an authorization check, because it does not know who the user is: add the caller's identity as a parameter and check it before t.handler runs.
The annotations in toolSpecs() travel in the ToolSpec, for MCP clients, hosts and your own code. The generated prompt does not print them, so what the model sees is the MUTATION. prefix on the description. Neither one is security. Mark queries with readOnlyHint: true and mutations with destructiveHint as appropriate, and enforce the real rules in the handler.
Rendering rules that only bite in production
Two lines in the chat page carry the rules. COMPONENTS is declared outside the component, so its identity never changes. The wrapper div gives AgentInterface the height it expects. The same module-scope rule applies to the result of openuiLibrary.extend(...) and to your own libraries: build them once.
CSS has one ordering rule worth memorizing. The layered stylesheet puts OpenUI's component styles in @layer openui. The layer order declaration must come first, before any import that registers those layers, and unlayered CSS (including a plain reset) beats every layer. So resets go inside @layer base, and the default and layered OpenUI sheets are never loaded together.
The last rule is about timing. Props of a half-streamed component are partial. A component that fetches its own data should read useIsStreaming() and wait. The reference UnitToggle uses the same hook to keep its inputs disabled until the program has finished, because a form field that is still being defined should not accept input.
Spot the bug
Each snippet is a small piece of a plausible OpenUI app with one production bug. Click the line you think is wrong. You can keep guessing; the explanation appears when you find it.
The snippets are written for this exercise (the course has no server to run). They follow the shape of the reference files.
Break it
Predict first, then open the answer.
Retry or regenerate
Two kinds of failure look similar to the user and need different fixes.
| A query failed | The program is wrong | |
|---|---|---|
| Cause | The program is fine; the tool call errored (network, your API, a handler exception). | The model wrote an unknown component, a missing argument or a broken reference. |
| Where you see it | The Renderer query state: Renderer.QueryError, and useRendererQuery(). | onError with validation errors, once the stream ends. |
| Fix | Renderer.Retry calls the tool again. No model call, no tokens. | Regenerate, or send the errors back as a correction turn. Costs a model call. |
| User sees | Cached or default data stays visible; you add the error and retry UI. | The valid part renders; the broken statement is dropped. |
Wiring the first needs Renderer.Root, which renders only its children, so you place Renderer.Content, Renderer.QueryError and Renderer.Retry yourself:
<Renderer.Root response={response} library={library} toolProvider={tools} onError={report}>
<Renderer.Content />
<Renderer.QueryError>
<p role="alert">Data is unavailable.</p>
<Renderer.Retry>Try again</Renderer.Retry>
</Renderer.QueryError>
</Renderer.Root>
OpenUI rule
The plain Renderer shows a spinner while queries load and keeps cached data on failure, but shows no error or retry view by default. Opt in with Renderer.Root and its slots. Calling preventDefault() in the retry button's click handler cancels the retry.
The simulator's OUI.Renderer reports query failures in its runtime state but has no Renderer.Root slots; the snippet above is the real React API.
Telemetry flags
OpenUI Lang collects limited telemetry about how @openuidev/lang-core is installed and used. It does not collect prompts, messages, generated output, source code, credentials or user data (the telemetry page lists what it does collect). The switches are environment variables:
| Variable | Where | Effect |
|---|---|---|
OPENUI_TELEMETRY_DISABLED=1 | install, runtime | Turns off installation telemetry. Also overrides runtime opt-in. |
DO_NOT_TRACK=1 | install, runtime | Same effect, the common cross-tool convention. |
OPENUI_RUNTIME_TELEMETRY_ENABLED=1 | server runtime | Opt in. Samples about 1 in 10 prompt generations (lang_core_system_prompt_generation_used) and about 1 in 10 parser parses (lang_core_parser_parse_used) on your server. The browser never sends. Off by default. |
Installation telemetry runs during package installation, not during your app build unless the build also installs dependencies. That is why every lab in this course installs with npm install --ignore-scripts. In CI, set the variable before the install step.
OpenUI rule
Runtime telemetry needs OPENUI_RUNTIME_TELEMETRY_ENABLED=1 and is overridden by OPENUI_TELEMETRY_DISABLED or DO_NOT_TRACK. Decide per environment and write it in your deploy config.
Optional: Gateway and Autofix
Models sometimes emit invalid OpenUI Lang, and providers sometimes go down. Thesys, the company behind OpenUI, offers two hosted services for that. Neither is required; the language, the parser and the Renderer work with any provider.
| Gateway | Autofix | |
|---|---|---|
| What it is | An OpenAI-compatible endpoint (Chat Completions and Responses) between your backend and the model. | An API you call after a generation fails validation. |
| What it does | Validates OpenUI Lang while streaming, repairs errors, and provides provider fallbacks. | Takes the generation, the library spec and the conversation, and returns corrected OpenUI Lang. |
| Your model setup | You call models through it. | You keep your own provider and inference setup. |
| Trade-offs to weigh | It builds its own prompt and accepts only preamble, examples and additionalRules in promptOptions, so tools and edit mode need your own prompt. Another vendor in the request path. | Extra call and latency when a fix is needed; a hosted dependency and API key on your server. |
A free alternative for the same failure is the correction loop from the errors lesson, which uses your own model. Reliability Monitoring, also from Thesys, tracks how often generations fail; it is automatic with the two services above and available through an SDK otherwise. Evaluate them against your failure rate: measure first with onError logging.
Details change; check the upstream docs for current endpoints and pricing before relying on any of this.
Quick check
A teammate adds an optional system field to the chat route's body so the frontend can "customize the assistant". What is wrong?
The model's program contains Query("delete_todo", {"id": ...}) in a runtime-tools app. Who calls your tool API?
Your custom component calls fetch in an effect on its city prop. In production it fires many requests while a response streams. What is the fix?
Query. Creating components inside a render function breaks identity and makes things worse.Recap
- The browser is untrusted. The prompt, the model choice and the credentials stay on your API; the request carries only the user's message and history.
- Runtime tools are called by the browser as the user, so the tool endpoint must authenticate, authorize and validate, using the same schemas that describe the tools to the model.
- Rendering: one OpenUI stylesheet with a declared layer order, module-scope libraries and component maps, a sized
AgentInterface, and no self-fetching while streaming. - Retry failed queries with
Renderer.Retry; fix wrong programs withonErrorand a regenerate or correction turn. - Runtime telemetry is opt-in; Gateway and Autofix are optional services, not requirements.