Skip to content

API References

The ChatWidget component is the main entry point to add chat functionality to your site.

ChatWidget Props

Below is the list of props accepted by the ChatWidget component. All are optional except if you want real API connectivity (require apiUrl).

PropTypeDefaultDescription
apiUrlstring | undefined-Base URL of your chat API. When provided (without a custom `streamResponse`), the widget will automatically use `useSSEStream` to connect to `<apiUrl>/v1/chat` with an OpenAI-compatible payload. @example "https://your-api.railway.app"
apiTokenstring | undefined-Bearer token for API authentication. Never commit this - pass via environment variable. @example process.env.CHAT_API_TOKEN
positionChatPosition | undefinedbottom-rightPosition of the floating button and chat panel.
themeChatTheme | undefineddarkColor theme preset.
colorsChatColors | undefined-Custom color overrides - merged with theme defaults.
titlestring | undefinedAsk AITitle shown in the chat panel header.
placeholderstring | undefinedAsk me anything...Placeholder text in the message input.
initialMessagestring | undefinedHello! How can I help you today?First message displayed when the panel opens.
defaultOpenboolean | undefinedfalseWhether the chat panel starts open.
labelsChatLabels | undefined-Custom text labels for technical indicators in the UI.
persistenceKeystring | undefinedask_widget_sessionThe localStorage key used to persist chat history.
streamResponseChatStreamHandler | undefined-Custom response handler - takes full control of streaming. Use this when you need custom fetch logic, auth flows, or a non-SSE backend. When provided, `apiUrl` and `apiToken` are ignored. @example ```ts const streamResponse: ChatStreamHandler = async function* (message, history) { const res = await fetch('/api/chat', { method: 'POST', body: JSON.stringify({ message }) }) const reader = res.body!.getReader() // ... yield decoded tokens } ```

ChatStreamHandler Type

If you have a non-standard API or require custom fetch logic, you can pass a streamResponse handler:

ts
export type ChatStreamResult =
  | string
  | AsyncIterable<string>
  | Promise<string | AsyncIterable<string>>;

export type ChatStreamHandler = (message: string, history: ChatMessage[]) => ChatStreamResult;

Example Usage

tsx
const streamResponse: ChatStreamHandler = async function* (message, history) {
  const res = await fetch('/api/chat', {
    method: 'POST',
    body: JSON.stringify({ message, history })
  })

  if (!res.ok) throw new Error('API request failed')

  const reader = res.body!.getReader()
  // decode and yield tokens...
}

<ChatWidget streamResponse={streamResponse} />

Released under the MIT License.