A full-stack example that renders answers with @openuidev/intelligent-ui-library and keeps @openuidev/react-ui for the chat window, with a FastAPI (Python) backend. The LLM streams responses in OpenUI Lang and the React frontend renders them as live components rooted at Col.
This is the first example in the repo using a non-Node.js backend — the same frontend that works with Next.js works here unchanged.
┌────────────────────────┐ ┌─────────────────────────┐
│ Vite + React │ POST │ FastAPI (Python) │
│ (port 5173) │ ──────► │ (port 8000) │
│ │ │ │
│ • AgentInterface UI │ │ • POST /api/chat │
│ • openAIReadable- │ NDJSON │ • OpenUI Cloud │
│ StreamAdapter() │ ◄────── │ Chat Completions │
└────────────────────────┘ └─────────────────────────┘
The Vite dev server proxies /api/* to FastAPI, so CORS is handled transparently.
fastapi/
├── backend/
│ ├── .env.example # Environment template
│ ├── pyproject.toml # Python dependencies
│ └── app/
│ └── main.py # Streaming chat endpoint
└── frontend/
├── package.json
├── vite.config.js # Vite + proxy to localhost:8000
├── index.html
└── src/
├── library.ts # Intelligent UI library + promptOptions re-exports
├── generated/spec.json # Generated before dev/build/verify (gitignored)
├── main.jsx
├── App.jsx # AgentInterface + library + ThemeProvider
└── index.css
- Python 3.10+
- uv (or pip)
- Node.js 20.19+ or 22.12+
- An OpenUI Cloud API key (https://console.thesys.dev/keys)
cd backend
cp .env.example .envAdd your key to backend/.env:
THESYS_API_KEY=sk-th-...
THESYS_API_KEY is the only required environment variable; no OPENAI_API_KEY is
needed. Optionally set OPENUI_MODEL to override the backend's default Cloud model
(google/gemini-3.6-flash-free).
cd backend
uv run uvicorn app.main:app --reloadOr with pip:
pip install fastapi openai python-dotenv uvicorn
uvicorn app.main:app --reloadThe API will be available at http://localhost:8000.
cd frontend
pnpm install --ignore-workspace
pnpm generate
pnpm devOpen http://localhost:5173.
A FastAPI endpoint that:
- Receives
{ messages }as JSON (OpenAI Chat Completions messages) - Calls OpenUI Cloud's Chat Completions API (
POST /v1/embed/chat/completions) with a system prompt built fromfrontend/src/generated/spec.json(the Intelligent UI library, generated bypnpm generatein the frontend) - Yields each chunk as NDJSON — the same format the JavaScript SDK's
toReadableStream()produces
The prompt stays in Cloud mode. Python reads the generated schema, root and component groups
into chatLibrary, forwards the library's examples and additional rules in the sibling
systemPromptOptions field, and appends rules for form submission and conditional fields using
the current Button and RadioGroup arguments.
Uses fetchLLM with openAIReadableStreamAdapter() and openAIMessageFormat to parse the NDJSON stream from FastAPI.
src/library.ts re-exports library and promptOptions from
@openuidev/intelligent-ui-library (pinned to 0.0.2). Before development, builds and
verification, pnpm generate runs
openui generate src/library.ts --spec --out src/generated/spec.json so the backend and
renderer use the same components: Col, Title, Text, Chart and the rest of the new set.
The frontend keeps AgentInterface, the streaming adapters and styles from react-ui. The new
library's ThemeProvider wraps the chat and receives the same useSystemThemeMode() value as
AgentInterface, so answers follow the system's light/dark preference. Threads and messages
persist in browser local storage. Previously saved answers using the old components cannot
render with this library; start a new chat to generate answers with the current components.
- OpenUI Lang overview — core building blocks: Library, Prompt Generator, Parser, Renderer
@openuidev/react-langpackage@openuidev/react-headlesspackage — streaming adapters and message format converters
From frontend/, the verification script builds the client and syntax-checks the Python backend:
pnpm verify