Skip to main content
Figranium exposes two Server-Sent Events endpoints, and the Kotlin SDK surfaces both as cold Flow<StreamEvent<JsonElement>> backed by OkHttp. You consume them with collect, and cancellation stops the underlying call immediately.

Streams

Both take an optional options argument (headers, timeoutMillis).

StreamEvent shape

Models.kt
The SDK parses the data: lines as JSON into JsonElement. If parsing fails, data falls back to a JsonPrimitive containing the raw payload, and raw still contains the original text.

Consume execution events

1

Create a client

Initialize the SDK with your API key.
Client.kt
2

Collect the stream

Use collect to consume events as they arrive inside a coroutine.
Client.kt
Collection ends when the server closes the connection or when the coroutine is cancelled. The Flow is cold, so collection starts the underlying request.

No read timeout

Streams set OkHttp readTimeout to 0 so they can run indefinitely. You do not need to pass a special timeoutMillis in RequestOptions for long-lived streams. Normal request timeouts apply only to API calls that are not streaming.
Client.kt

Cancel a stream

Cancel the coroutine that collects the Flow. The SDK uses callbackFlow with awaitClose { call.cancel() }, so the underlying OkHttp call is aborted as soon as collection stops.
Client.kt

Watch an execution with polling

executions.watch polls get at a configurable interval and yields Execution only when the status changes. It finishes automatically when the outcome or status reaches a terminal state (success, error, stopped, crashed, or anti_bot).
Client.kt
Cancelling the collecting coroutine also cancels the polling loop and any in-flight request.

Selector stream from a headful browser

The selector stream reports element highlights from a headful browser session. Use it to power visual inspectors:
Client.kt
See Browser resource for opening, inspecting, and stopping headful sessions.

Errors

Streams raise FigraniumException in the same conditions as regular requests:
  • NETWORK_ERROR: the stream could not reach the server.
  • Any non-2xx HTTP response from the server.
See Errors for the full error shape.
For long-running streams, prefer cancelling the collecting coroutine over setting a short timeoutMillis in RequestOptions so you can stop cleanly when your application state changes.

Errors

FigraniumException fields, codes, and retry guidance.

Browser resource

Open, inspect, and stream headful browser sessions.

Executions resource

List, stop, delete, and watch executions.