Skip to content

Anthropic

Use anthropic/<model id> to stream Claude models through the Anthropic SDK. This page covers what is specific to Anthropic; every argument of dyui.llm.stream is on Models & providers.

Terminal window
pip install "dyui[anthropic]"

The key goes in ANTHROPIC_API_KEY, for example in a .env file next to app.py; see API keys & environment. Inside your handler:

async for part in dyui.llm.stream("anthropic/claude-sonnet-5-5", chat.history,
system="You are a careful research assistant.", components=app.catalog):
yield part

DyUI uses the Messages streaming API. The system prompt (yours plus the catalog section) is sent as system. max_tokens defaults to 4096; pass max_tokens= to change it. Other keyword arguments go to client.messages.stream(...).

Thinking deltas become a collapsible reasoning block automatically. Turn thinking on with the SDK’s own parameter:

async for part in dyui.llm.stream(
"anthropic/claude-opus-5-5",
chat.history,
components=app.catalog,
max_tokens=16000,
thinking={"type": "enabled", "budget_tokens": 8000},
):
yield part

ui_mode="tools" registers a strict render_<name> tool per component and runs the tool loop, keeping text and tool calls in order:

async for part in dyui.llm.stream("anthropic/claude-sonnet-5-5", chat.history,
components=app.catalog, ui_mode="tools"):
yield part

ANTHROPIC_BASE_URL or base_url= points DyUI at a proxy or gateway. Pass client= with a pre-built anthropic.AsyncAnthropic for full control. With a custom base URL, DyUI doesn’t insist on ANTHROPIC_API_KEY, because gateways may authenticate differently; on the default endpoint a missing key is reported before any request.

app.py
"""A Claude model that answers with DyUI components, with optional extended thinking.
Needs: pip install "dyui[anthropic]" and ANTHROPIC_API_KEY in a .env file next to this one.
Save as app.py, then run: dyui run app.py
Stream Claude's thinking with: DYUI_THINKING=1 dyui run app.py
"""
import os
import dyui
MODEL = os.getenv("DYUI_MODEL", "anthropic/claude-sonnet-5-5")
THINKING = os.getenv("DYUI_THINKING") == "1"
app = dyui.App(title="Research Assistant", starters=["Summarise the trade-offs of SQLite vs Postgres"])
@app.on_message
async def reply(msg: dyui.Message, chat: dyui.Chat):
extra = {"max_tokens": 16000, "thinking": {"type": "enabled", "budget_tokens": 8000}} if THINKING else {}
async for part in dyui.llm.stream(
MODEL,
chat.history,
system="You are a careful research assistant.",
components=app.catalog,
**extra, # anything else goes to client.messages.stream(...)
):
yield part
  1. Save it as app.py in a new, empty file, or download app.py.

  2. Put ANTHROPIC_API_KEY=sk-ant-... in a .env file next to it.

  3. Run it:

    Terminal window
    pip install "dyui[anthropic]"
    dyui run app.py
  4. Open http://localhost:8000 and send the starter. Add DYUI_THINKING=1 to .env and restart to stream Claude’s thinking.

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.