Search documentation

Type to search.

Navigate · Enter to open · Esc to close

On this page

ChatWidget props

Props are generated from the installed repository source. streamResponse takes precedence over apiUrl and apiToken; no backend props selects demo mode.

ChatWidget props
NameTypeDefaultDescription
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.
apiTokenstring | undefined—Bearer token for API authentication. Browser-visible token. Use only a short-lived token scoped to your backend. Keep private provider credentials on the server; frontend environment variables do not conceal secrets.
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.

ChatStreamHandler Type

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

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

export interface ChatStreamContext {
  signal: AbortSignal;
}
export type ChatStreamHandler = (
  message: string,
  history: ChatMessage[],
  context?: ChatStreamContext,
) => ChatStreamResult;

Example Usage

import { ChatWidget, type ChatStreamHandler } from '@chitrank2050/ask-widget';

const streamResponse: ChatStreamHandler = async (message, history) => {
  const response = await fetch('/api/chat', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ message, history }),
  });
  if (!response.ok) throw new Error('Chat request failed');
  return response.text();
};

export function Assistant() {
  return <ChatWidget streamResponse={streamResponse} />;
}

This example expects a plain-text response from your own backend. For token streaming, use the SSE adapter or return an async iterable that decodes your backend’s stream.

Edit this page