A full-stack example that demonstrates using @openuidev/react-ui with a FastAPI (Python) backend. The LLM streams responses in OpenUI Lang and the React frontend renders them as live components in real time.
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/
├── 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 # openuiLibrary re-export for `openui generate --spec`
├── main.jsx
├── App.jsx # AgentInterface + openuiLibrary
└── index.css
- Python 3.10+
- uv (or pip)
- Node.js 18+
- 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-...
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(openuiLibrary, generated bypnpm generatein the frontend) - Yields each chunk as NDJSON — the same format the JavaScript SDK's
toReadableStream()produces
Uses fetchLLM with openAIReadableStreamAdapter() and openAIMessageFormat to parse the NDJSON stream from FastAPI.
- 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