> ## 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.

# Streaming Events

> SSE event payloads and streaming parser utilities

The SDK exposes utilities and types for parsing SSE output from `/api/v1/chat`
when `Accept: text/event-stream` is set.

## Parser

```ts theme={null}
parseSSEStream(
  stream: ReadableStream<Uint8Array>,
  signal?: AbortSignal,
): AsyncGenerator<SSEStreamEvent>
```

`parseSSEStream` yields typed events as they arrive.

## Event union

`SSEStreamEvent` includes:

* `telemetry`
* `result`
* `error`
* `stream_end`

The SDK also exports:

* `TelemetryStreamEvent`
* `ResultStreamEvent`
* `ErrorStreamEvent`
* `SSEStreamEndEvent`

## Example

```ts theme={null}
const response = await fetch('https://api.illa.io/api/v1/chat', {
  method: 'POST',
  headers: {
    'content-type': 'application/json',
    accept: 'text/event-stream',
    'x-api-key': process.env.ILLA_API_KEY!,
  },
  body: JSON.stringify(body),
})

if (!response.body) throw new Error('No stream body')

for await (const event of parseSSEStream(response.body)) {
  if (event.type === 'telemetry' && event.data.type === 'text_delta') {
    process.stdout.write(event.data.data.delta)
  }

  if (event.type === 'result') {
    console.log('\nfinal text:', event.data.text)
  }
}
```

## Streaming errors

* `SSEParse`
* `StreamingHttpError`
* `StreamingResponseBodyNull`
* `StreamingServerError`

## Typical lifecycle

1. `telemetry` events (including `connected` and optional `text_delta`)
2. `result`
3. `stream_end`
4. `error` appears when the stream fails

`/api/v1/chat/stream` may still be available in compatibility deployments, but `/api/v1/chat` is the canonical SDK target.

## See also

* [ILLA SDK](/sdk/api/illa-sdk)
* [Chat](/sdk/api/chat)
