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

Parser

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

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