Implementation:Openai Openai node Realtime Send Session Update
| Knowledge Sources | |
|---|---|
| Domains | Realtime, Configuration |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete pattern for configuring Realtime API sessions via session.update events provided by the openai-node SDK.
Description
The rt.send() method with type: 'session.update' configures the active session. The session payload accepts modalities, instructions, voice, audio formats, turn detection settings, and tool definitions. This is a Pattern Doc — the send() method accepts any RealtimeClientEvent; the session.update usage is a specific pattern.
Usage
Call rt.send({ type: 'session.update', session: {...} }) after connection to configure the session. Listen for session.updated to confirm.
Code Reference
Source Location
- Repository: openai-node
- File: src/realtime/ws.ts (send implementation), src/resources/realtime/realtime.ts (SessionUpdateEvent type)
- Lines: ws.ts:L98-104, realtime.ts:L4446-4465
Signature
// send method (on OpenAIRealtimeWS / OpenAIRealtimeWebSocket)
send(event: RealtimeClientEvent): void;
// SessionUpdateEvent type
interface SessionUpdateEvent {
type: 'session.update';
event_id?: string;
session: {
modalities?: Array<'text' | 'audio'>;
instructions?: string;
voice?: string; // 'alloy', 'ash', 'coral', 'echo', 'sage', 'shimmer', ...
input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';
output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';
turn_detection?: { type: 'server_vad' | 'semantic_vad'; ... } | null;
tools?: Array<{ type: 'function'; name: string; description?: string; parameters?: object }>;
};
}
Import
// No separate import needed — use rt.send() on the connection instance
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| type | 'session.update' | Yes | Event type discriminator |
| session.modalities | 'audio'> | No | Supported modalities |
| session.instructions | string | No | System prompt for the session |
| session.voice | string | No | Voice selection for audio output |
| session.input_audio_format | string | No | Input audio encoding format |
| session.output_audio_format | string | No | Output audio encoding format |
| session.turn_detection | null | No | VAD/turn detection configuration |
| session.tools | Array | No | Tool definitions for function calling |
Outputs
| Name | Type | Description |
|---|---|---|
| (event) | session.updated | Server acknowledgment with updated session config |
Usage Examples
import { OpenAIRealtimeWS } from 'openai/realtime/ws';
const rt = await OpenAIRealtimeWS.create(client, {
model: 'gpt-4o-realtime-preview',
});
// Configure session after connection
rt.on('session.created', () => {
rt.send({
type: 'session.update',
session: {
modalities: ['text', 'audio'],
instructions: 'You are a friendly voice assistant.',
voice: 'shimmer',
input_audio_format: 'pcm16',
output_audio_format: 'pcm16',
turn_detection: { type: 'server_vad' },
},
});
});
rt.on('session.updated', (event) => {
console.log('Session configured:', event.session);
});