Import
Signature
Configuration
useGatelit accepts a GatelitClientConfig object — the same configuration used by the core JS SDK.
string
required
Base URL of your deployed Gatelit gateway, e.g.
"https://gateway.yourapp.com".() => Promise<{ token: string; scheme: TokenScheme }>
required
Called before each request to obtain a fresh auth token. Return the token string and the authentication scheme:
Implement token caching inside this function to avoid a fetch on every message.
Returned values
Reactive state
All state properties arereadonly refs — mutate them only through the provided functions.
Readonly<Ref<ChatMessageWithId[]>>
The full conversation history in chronological order. Each entry is a
ChatMessageWithId:Readonly<Ref<boolean>>
true while an assistant response is being streamed. send() is a no-op when this is true.Readonly<Ref<GatelitError | null>>
The last error, or
null if no error has occurred (or after clear() is called). A GatelitError has three properties:Functions
(userMessage: string, model: string, options?: Partial<ChatOptions>) => Promise<void>
Appends the user message to
messages, opens a streaming request, and appends a live-updating assistant message.- Does nothing if
isStreamingis alreadytrue. - Clears
errorbefore each new request. - If the stream is aborted via
stop(), no error is set — the partial assistant message is kept if it contains any content; an empty assistant placeholder is removed. - If the stream fails with a
GatelitError,erroris populated.
() => void
Aborts the current stream by calling
AbortController.abort(). isStreaming returns to false. Any content streamed so far is kept in messages.() => void
Clears all messages and resets
error to null. If a stream is in progress, it is aborted first.Examples
Full chat interface
A complete Vue SFC with message history, a streaming indicator, error display, and stop button.The assistant message object is replaced in the array on every chunk (to
trigger Vue’s reactivity system), so
:key="msg.id" ensures the DOM node is
reused rather than recreated. Always bind id as the key.Usage with Nuxt
In a Nuxt application, use$fetch (provided by Nuxt’s runtime) inside getToken to call your server route:
server/api/ai-token.ts route signs and returns a short-lived token using signToken from @gatelit/sdk.