Skip to content

Bring your own SDK

Read this page when you already use an SDK or framework, or when your code has structured data to show directly.

Code on this page is fragments; the complete example is a whole file.

DyUI doesn’t need to own your model calls. It parses text, so anything that streams text can render components. Two steps:

  1. Add app.catalog.prompt() to your system prompt.
  2. Yield the raw text deltas. DyUI finds the dyui fences while they stream.
import os
from openai import AsyncOpenAI
client = AsyncOpenAI(base_url="https://integrate.api.nvidia.com/v1", api_key=os.environ["NVIDIA_API_KEY"])
@app.on_message
async def reply(msg: dyui.Message, chat: dyui.Chat):
system = "You are a data analyst.\n\n" + app.catalog.prompt()
stream = await client.chat.completions.create(
model="moonshotai/kimi-k2.6",
messages=[{"role": "system", "content": system}, *chat.history],
stream=True,
)
async for chunk in stream:
delta = chunk.choices[0].delta.content if chunk.choices else None
if delta:
yield delta

The same applies to any framework (LlamaIndex, Haystack, DSPy, your own HTTP client): put the prompt in, and stream the text out.

When your code already has structured data, skip the model and yield components directly:

rows = await db.fetch("select city, temp from weather")
yield ui.Table(["City", "Temp"], [[r.city, r.temp] for r in rows])

If your framework produces component objects (for example, from your own tool calls), yield the dict. DyUI validates it like model output:

yield {"ui": "stat", "label": "Revenue", "value": "$48.2k", "delta": "+12%"}

app.catalog.json_schema() returns {name: JSON schema}, and app.catalog.tool_schemas("openai" | "anthropic") returns ready-to-send render_<name> tool definitions if you want to run your own structured loop.

The raw openai client against NVIDIA’s endpoint, with app.catalog.prompt() in the system prompt and the raw text yielded.

bring_your_own_sdk.py
"""Use your own SDK client. DyUI only needs raw text: it parses ```dyui fences itself."""
import os
from functools import lru_cache
import dyui
from openai import AsyncOpenAI
@lru_cache(maxsize=1)
def client() -> AsyncOpenAI:
# Any OpenAI-compatible endpoint. Created on first use, so the app starts without a key.
return AsyncOpenAI(base_url=os.getenv("DYUI_BASE_URL", "https://integrate.api.nvidia.com/v1"),
api_key=os.environ["NVIDIA_API_KEY"])
MODEL = os.getenv("DYUI_MODEL", "moonshotai/kimi-k2.6") # the endpoint model id, no dyui provider prefix
app = dyui.App(title="BYO SDK", description="Raw OpenAI client, DyUI rendering.")
@app.on_message
async def reply(msg: dyui.Message, chat: dyui.Chat):
system = "You are a helpful assistant.\n\n" + app.catalog.prompt()
stream = await client().chat.completions.create(
model=MODEL,
messages=[{"role": "system", "content": system}, *chat.history],
stream=True,
)
async for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
yield chunk.choices[0].delta.content # raw text deltas; fences become components
  1. Save it as bring_your_own_sdk.py in a new, empty file, or download it.

  2. Put NVIDIA_API_KEY=nvapi-... in a .env file next to it (the example reads it with os.environ when the first message arrives).

  3. Run it:

    Terminal window
    pip install dyui openai
    dyui run bring_your_own_sdk.py
  4. Open http://localhost:8000 and send a message.

DyUI Docs assistant

Answers come from the DyUI docs. gpt-oss-120b via Groq. Press Escape or the close button to return to the page.