Principle:Openai Openai node Realtime Event Handling
| Knowledge Sources | |
|---|---|
| Domains | Realtime, Event_Driven_Architecture |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
A principle for handling server-sent events from the Realtime API including response deltas, transcription updates, and error notifications via typed event listeners.
Description
Realtime Event Handling covers the consumption of server events during a Realtime session. The server sends typed events for: text deltas (response.text.delta), audio deltas (response.audio.delta), transcription chunks (response.audio_transcript.delta), function call arguments (response.function_call_arguments.delta), response completion (response.done), and errors.
The SDK provides a custom typed EventEmitter that maps event names to their payload types, providing type-safe event handling.
Usage
Use this principle to process server responses during a Realtime session. Register event listeners for the specific events your application needs.
Theoretical Basis
Event handling follows the Observer Pattern with typed dispatch:
// Register typed event listeners
rt.on('response.text.delta', (event) => {
// event is typed: { delta: string, ... }
display(event.delta)
})
rt.on('response.done', (event) => {
// event is typed: { response: Response, ... }
finalize(event.response)
})
rt.on('error', (event) => {
// event is typed: { error: { message: string, ... } }
handleError(event.error)
})