Skip to main content
For a complete working application — send, live cell streaming, and reload re-attach — see the chat-demo example.
Streaming is currently available in the TypeScript SDK (@textql/sdk v1.2.2+). All examples below are TypeScript. The TextQL API exposes several server-streaming endpoints that are not part of the REST surface documented elsewhere in this reference. They are consumed through the SDK’s streaming client, which speaks Connect-RPC to the same gateway with the same API key.

Quickstart

Streams are async iterables. Pass an AbortSignal to cancel:
serverURL defaults to https://app.textql.com — on-prem deployments pass their own host and the SDK routes RPCs correctly from there.

Streaming Methods

watchChat vs streamChat

Both deliver the same cell snapshots from the same event bus; they differ in what they tell you about run state.
  • watchChat is a chat-scoped subscription: it announces runStarted immediately when a run is live, delivers cells, signals runComplete / runError, and sends heartbeats every 20 seconds so idle connections survive proxies. It stays open across runs. Pass your last known cell id as latestCompleteCellId to replay anything you missed — this is how a UI re-attaches to a run after a page reload.
  • streamChat is a run-scoped firehose: cells only, ending when the run ends. Right for one-shot scripts (send → for await cells → exit) that don’t need lifecycle state.
Rule of thumb: UIs and long-lived consumers watch; one-shot scripts stream.

Driving a Chat End to End

The chat-demo example app implements this full flow (plus reload re-attach via latestCompleteCellId); the condensed version:
Each method above links to its TypeScript reference — signature, worked example, and request/event fields. Cell-emitting streams share the Cell message reference.

Notes

  • Runtime: browsers and Node 18+ (server-streaming rides on fetch response streams).
  • Types: streaming methods return fully typed objects — discriminated unions for event payloads, TypeScript enums for statuses. They differ slightly in shape from the REST models documented elsewhere in this reference.
  • Disconnecting vs cancelling: aborting the signal or breaking out of the loop closes your subscriptionthe run keeps executing server-side. To actually stop a chat run, call the Cancel Stream endpoint:
    You can watch the same chat again afterwards; watchChat reports the outcome via its lifecycle events.