EventSub stream

Use streamEventSub to connect to the unified SSE stream at /v1/eventsub/stream.

Usage example

eventsub.ts
const stream = client.streamEventSub({
  types: ['chat.message', 'ai.tts.generated'],
  autoReconnect: true,
  onOpen: () => console.log('EventSub connected'),
  onError: (err) => console.error('EventSub error', err),
  handlers: {
    'chat.message': (event) => {
      console.log(`[${event.payload.platform}] ${event.payload.username}: ${event.payload.message}`);
    }
  }
});

stream
  .on('ai.tts.generated', (event) => {
    console.log(`New TTS clip at ${event.payload.ttsStreamUrl}`);
  })
  .onAny((event) => console.log(`Received ${event.type}`));

// Stop streaming
stream.close();

Filters and options

OptionDescription
typesLimit to specific event keys (comma list on the wire).
channelIdTarget a specific channel when the API key controls multiple.
cursorOpaque resume token for future replay support.
handlersMap of per-event handlers, invoked on message receipt.
autoReconnectEnable automatic reconnects (default: true).
onReconnectAttemptCalled with { attempt, delayMs } before each retry.
onConnectionStateChangeNotifies connecting and reconnecting states.

Event names match the type field in the EventSub envelope. For full payload schemas, see EventSub docs.