Quick setup
The fastest path: one component, one hook, one API route.Chat component renders a full chat interface with input, message list, loading indicators, and scroll management.
useChat hook
For custom UIs, use the hook directly:useChat options
| Property | Type | Description |
|---|---|---|
api | string | URL of the chat API route |
initialMessages | UIMessage[] | Pre-populate the conversation |
body | Record<string, unknown> | Extra data sent with each request |
headers | Record<string, string> | Custom request headers |
onFinish | (message) => void | Called when the assistant finishes responding |
onError | (error) => void | Called on stream errors |
onToolCall | (toolCall) => void | Called when the agent calls a tool |
Rendering tool calls
When an agent calls a tool, the message contains a tool part. Render it withrenderTool:
state property:
| State | Description |
|---|---|
"input-streaming" | Model is generating the tool call arguments |
"input-available" | Arguments ready, tool executing |
"output-streaming" | Tool result streaming back |
"output-available" | Tool call complete |
"output-error" | Tool execution failed |
useAgent hook
For direct agent invocation (without the chat protocol), useuseAgent:
useCompletion hook
For simple text completion without conversation context:Theming
Customize theChat component with a theme object:
Next
- Workflows: orchestrate multi-step agent tasks
- Multi-Agent: compose agents together
Related
veryfront/chat: chat API referenceveryfront/agent: agent API reference