claudius-chat-widget
    Preparing search index...

    Class ChatApiClient

    Typed client for the Claudius Worker chat API. Handles debouncing, per-attempt timeouts, and automatic retries with backoff for transient failures (HTTP 429/503, network errors, timeouts).

    Conversations without inline attachment bytes are posted as JSON. When any message carries an attachment with data, the request is sent as multipart/form-data: a payload field holding the JSON body (attachment refs without their bytes) plus one file part per attachment, named after the attachment id.

    const client = new ChatApiClient("https://api.example.com");
    const { reply } = await client.sendMessage([
    { id: "1", role: "user", content: "Hello" },
    ]);
    Index

    Constructors

    Methods

    • Send the conversation to the streaming chat endpoint and resolve with the assistant's full reply once the stream completes. Text deltas are delivered through ChatStreamOptions.onChunk as they arrive.

      Falls back to sendMessage (non-streaming) when the browser can't read response streams or the Worker doesn't expose /api/chat/stream (HTTP 404/405), so callers never need their own feature detection.

      Failures before the first byte follow the same retry policy as sendMessage; once streaming has begun there are no automatic retries. Aborting via ChatStreamOptions.signal is not an error: the promise resolves with the partial reply and aborted: true.

      Parameters

      • messages: ChatMessage[]

        The full conversation so far, oldest message first.

      • options: ChatStreamOptions = {}

        Chunk callback and cancellation signal.

      Returns Promise<ChatStreamResult>

      DebounceError when called within the debounce window.

      ChatApiError when the request fails after all retries, or the stream errors or is interrupted mid-reply (code "STREAM_ERROR").