Skip to main content
Users expect chat apps to show text as it’s generated — not after a 10-second pause. kenpachi supports streaming out of the box with both Anthropic and OpenAI providers.
Just want streaming text in your UI? Use the onText callback on agent.run() — no async generators required.

Option 1: onText (simplest)

If you only need to print or append text chunks, pass onText to run():
run() still returns the full AgentRunResult when finished — streaming is additive, not a separate API shape.

Option 2: agent.stream() (full events)

Use stream() when you need visibility into tool calls, repair attempts, rollbacks, or handoffs — not just text.
When the generator completes, it returns the same AgentRunResult that run() would:

Event types

Use onEvent on run() if you want these callbacks without managing an async generator:

Provider support

Both createAnthropicProvider and createOpenAIProvider implement streamTurn() automatically. No extra config — if the provider supports streaming, kenpachi uses it. Providers that only implement createTurn() (e.g. test fakes) still work: text arrives as a single text_delta so your event handlers stay consistent.

Building a chat UI

A typical React pattern:
Show streaming while the run is in progress; commit result.text when done.