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.
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 partDyUI 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(...).
Extended thinking
Section titled “Extended thinking”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 partStructured mode
Section titled “Structured mode”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 partCustom endpoints
Section titled “Custom endpoints”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.
Complete example
Section titled “Complete example”"""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.pyStream 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_messageasync 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-
Save it as
app.pyin a new, empty file, or download app.py. -
Put
ANTHROPIC_API_KEY=sk-ant-...in a.envfile next to it. -
Run it:
Terminal window pip install "dyui[anthropic]"dyui run app.py -
Open http://localhost:8000 and send the starter. Add
DYUI_THINKING=1to.envand restart to stream Claude’s thinking.
See also
Section titled “See also”- Models & providers: every argument, rate limits.
- Steps & reasoning: how the thinking block is shown.