Skip to main content

Function: useChat()

@baleybots/react

React hooks for Baleybots. useChat is an adapter over AI SDK's useChat: the conversation is AI SDK UIMessages, streamed from a createChatRoute server or from a bot running in the browser.

Example​

import { useChat, useBaleybot } from '@baleybots/react';

// A bot in the browser (its model calls can go through a proxy)
const { messages, send } = useChat({ model: openai('gpt-5.6-luna') });

// A createChatRoute server
const chat = useChat({ api: '/chat', sessionId });

// One run with structured output
const { process, streamingResult } = useBaleybot({
name: 'analyzer',
analysisGoal: 'Analyze text',
outputSchema: { ... }
});

Call Signature​

useChat<TSchema>(options): UseChatReturn<InferSchemaOutput<TSchema>>

Defined in: react/src/hooks/useChat.ts:171

Chat over AI SDK's useChat. With api and sessionId it talks to a createChatRoute server; otherwise the bot runs here. Either way the turn streams through core's UI message projection, so messages are AI SDK UIMessages and the package's renderers draw their parts.

Tool approvals are AI SDK's: a gated call's part waits in approval-requested; respondToToolApprovals() answers them and the turn resumes once every pending call has a decision.

Type Parameters​

TSchema​

TSchema extends object

Parameters​

options​

LocalChatOptions<InferSchemaOutput<TSchema>> & object

Returns​

UseChatReturn<InferSchemaOutput<TSchema>>

Example​

const { messages, send, pendingApprovals, respondToToolApprovals } = useChat({
model: openai('gpt-5.6-luna'),
systemPrompt: 'You are a helpful assistant',
});

Call Signature​

useChat<TResponse>(options): UseChatReturn<TResponse>

Defined in: react/src/hooks/useChat.ts:174

Chat over AI SDK's useChat. With api and sessionId it talks to a createChatRoute server; otherwise the bot runs here. Either way the turn streams through core's UI message projection, so messages are AI SDK UIMessages and the package's renderers draw their parts.

Tool approvals are AI SDK's: a gated call's part waits in approval-requested; respondToToolApprovals() answers them and the turn resumes once every pending call has a decision.

Type Parameters​

TResponse​

TResponse = string

Parameters​

options​

UseChatOptions<TResponse>

Returns​

UseChatReturn<TResponse>

Example​

const { messages, send, pendingApprovals, respondToToolApprovals } = useChat({
model: openai('gpt-5.6-luna'),
systemPrompt: 'You are a helpful assistant',
});