Create a chat client for the given Worker base URL.
Base URL of the Worker. Requests post to ${baseUrl}/api/chat.
Optionaloptions: ChatApiClientOptionsOptional retry, debounce, and timeout settings.
Send the conversation to the chat endpoint and return the assistant's reply, retrying transient failures with backoff up to ChatApiClientOptions.maxRetries times.
The full conversation so far, oldest message first.
The assistant's reply and any cited sources.
DebounceError when called within the debounce window.
ChatApiError when the request fails after all retries.
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.
The full conversation so far, oldest message first.
Chunk callback and cancellation signal.
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").
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 asmultipart/form-data: apayloadfield holding the JSON body (attachment refs without their bytes) plus one file part per attachment, named after the attachment id.Example