> ## Documentation Index
> Fetch the complete documentation index at: https://docs.illa.io/llms.txt
> Use this file to discover all available pages before exploring further.

# TelemetryClient

> Browser SSE telemetry client for request-level orchestration tracking

`TelemetryClient` connects to a telemetry SSE endpoint and emits typed telemetry events.
Use it only when your deployment exposes a dedicated `${baseUrl}/telemetry/{requestId}` stream.

<Warning>
  The primary public API flow documented in this docs set uses single-request SSE via `sendMessageStreaming`.
  `TelemetryClient` is for deployments that separately expose request-scoped telemetry streams.
</Warning>

## Constructor

```ts theme={null}
new TelemetryClient({
  baseUrl: string,
  onEvent?: (event: TelemetryEvent) => void,
  onComplete?: () => void,
  onError?: (error: Error) => void,
})
```

## Methods

### `connect(requestId: string): void`

Connects to `${baseUrl}/telemetry/{requestId}`.

### `disconnect(): void`

Closes the active `EventSource` connection.

## State helpers

* `isConnected`
* `isComplete`
* `TelemetryClient.getPhaseFromEvent(event)`
* `TelemetryClient.getPhaseLabel(phase)`
* `TelemetryClient.isTerminalEvent(type)`

## Example

```ts theme={null}
import { TelemetryClient } from '@illalabs/sdk'

const telemetry = new TelemetryClient({
  baseUrl: 'https://api.illa.io/api/v1/chat',
  onEvent: (event) => console.log(event.type),
  onComplete: () => console.log('done'),
  onError: (error) => console.error(error),
})

telemetry.connect('request-id')
telemetry.disconnect()
```

## Environment note

`TelemetryClient` depends on `EventSource`. In Node.js, provide an `EventSource` polyfill before use.
