Production server
dyui run is for development: it reloads on every save. In production, serve the ASGI app with Uvicorn:
pip install dyuiuvicorn app:app --host 0.0.0.0 --port 8000 --proxy-headersThe compiled chat app ships inside the wheel, so there’s nothing to build. The same process serves the web app (/), its assets and the API (/api/*).
Run one process per app
Section titled “Run one process per app”chat.ask() waits in memory for the user’s answer, and in-flight streams belong to the process that started them. Run one worker (Uvicorn’s default) and scale by giving each instance its own data. If you must run several workers or replicas, use sticky sessions so that a browser always reaches the same process, and share the store.
A single async worker handles many concurrent chats, because handlers spend most of their time awaiting the model.
Storage
Section titled “Storage”- Conversations go to SQLite at
./.dyui/dyui.db, and uploads to./.dyui/uploads/. Mount.dyuion a persistent volume, or setApp(data_dir="/var/lib/my-bot"). - For a managed database, implement a
Storeand pass it aspersist=. persist=Falsekeeps everything in memory, which suits demos and stateless bots.
Secrets
Section titled “Secrets”- Keep model API keys in environment variables (
OPENAI_API_KEY,ANTHROPIC_API_KEY…). DyUI never sends them to the browser. - Uvicorn doesn’t read
.envthe waydyui rundoes. Set the variables in your platform’s secret store, or pass--env-file .envto Uvicorn. API keys & environment lists every option. - With
password=, setDYUI_SECRETto a long random value so the auth cookie survives redeploys and works on every instance:
export DYUI_SECRET="$(python -c 'import secrets; print(secrets.token_hex(32))')"Security headers
Section titled “Security headers”DyUI sends a hardened set of headers by default, so a production deployment needs no extra configuration:
- a strict Content-Security-Policy on the web app (
script-src 'self'plus a per-page nonce, nounsafe-eval,object-src 'none',form-action 'self', frames only from the app and the YouTube/Vimeo privacy embeds); X-Frame-Options: SAMEORIGIN/frame-ancestors 'self'against clickjacking,X-Content-Type-Options: nosniff,Referrer-Policy: same-origin,Cross-Origin-Opener-Policy: same-origin, a restrictivePermissions-Policy, andCache-Control: no-storeon/api;- cross-origin protection on every state-changing API call: requests from another origin (including another port on
localhost) get403, and JSON routes requireContent-Type: application/json(415otherwise). The bundled web app always satisfies both; see the protocol.
Two App options adjust this:
app = dyui.App( title="Support", embed_origins=["https://www.example.com"], # sites allowed to show the app in an <iframe> csp=True, # DyUI's policy (default) | "your policy" | False)embed_origins— by default only the app itself may frame it. List full origins (https://host[:port]) to embed the chat in another site; they’re added toframe-ancestors.csp—Truesends DyUI’s policy; a string replaces it with your own (single line);Falsesends none (not recommended). Developerui.Htmlcomponents run inside the app’s policy: DyUI stamps the page nonce onto their<script>tags, so scripts work, but inline event handlers (onclick="…") don’t — attach listeners from a script instead.
Read the security policy for the threat model and how to report a vulnerability.
Checklist
Section titled “Checklist”- Serve over HTTPS, terminated at your proxy or platform; see Behind a reverse proxy.
- Disable response buffering for
/api/so replies stream. DyUI sendsX-Accel-Buffering: noand a 15-second heartbeat, but some proxies need explicit configuration. - Put
.dyui/(or yourdata_dir) on persistent storage, and back it up. - Set
DYUI_SECRETif you usepassword=. - Set
max_upload_mb, oruploads=Falseif you don’t need attachments. Oversized uploads, and JSON bodies over 1 MB, are refused with413before they’re buffered. - Behind a proxy, pass
--proxy-headers --forwarded-allow-ips <proxy ip>, so HTTPS is detected (Securecookies) and the login throttle sees real client addresses. - Log at
INFO: DyUI logs handler exceptions on thedyuilogger, and users only see a generic error.
Health check
Section titled “Health check”GET /api/config returns the app’s public configuration with a 200, which makes a cheap readiness probe.