Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Openai Openai node Beta Realtime Resource

From Leeroopedia
Knowledge Sources
Domains SDK, Realtime, Beta
Last Updated 2026-02-15 12:00 GMT

Overview

The Beta Realtime resource class serves as the deprecated beta namespace for the Realtime API, organizing sub-resources for sessions and transcription sessions, and defining the comprehensive set of Realtime client and server event types.

Description

The Realtime class extends APIResource and is marked @deprecated because the Realtime API has graduated from beta to general availability. The class itself contains no direct API methods but instead instantiates two sub-resources: sessions (of type Sessions) and transcriptionSessions (of type TranscriptionSessions), which provide the actual API call methods.

The bulk of this 2829-line file defines the TypeScript interfaces for all Realtime API events. Client events (sent from the client to the server) are aggregated in the RealtimeClientEvent union type and include events such as SessionUpdateEvent, InputAudioBufferAppendEvent, InputAudioBufferCommitEvent, ConversationItemCreateEvent, ConversationItemDeleteEvent, ConversationItemTruncateEvent, ResponseCreateEvent, and ResponseCancelEvent. Server events (received from the server) are aggregated in the RealtimeServerEvent union type and include events such as SessionCreatedEvent, SessionUpdatedEvent, ConversationCreatedEvent, ConversationItemCreatedEvent, ResponseCreatedEvent, ResponseDoneEvent, ResponseAudioDeltaEvent, ResponseTextDeltaEvent, and many more.

Key data structures include ConversationItem (representing messages, function calls, and function call outputs), ConversationItemContent (with types like input_text, input_audio, text, and audio), RealtimeResponse (with status, output, and usage details), and TranscriptionSessionUpdate (for configuring transcription sessions over WebSocket).

Usage

Use this resource namespace to access the deprecated beta Realtime sessions and transcription sessions. Access it via client.beta.realtime. The event types defined here are used when working with Realtime WebSocket connections. For new code, prefer the general-availability Realtime API.

Code Reference

Source Location

Signature

/** @deprecated */
export class Realtime extends APIResource {
  sessions: SessionsAPI.Sessions;
  transcriptionSessions: TranscriptionSessionsAPI.TranscriptionSessions;
}

// Key union types
export type RealtimeClientEvent =
  | ConversationItemCreateEvent
  | ConversationItemDeleteEvent
  | ConversationItemRetrieveEvent
  | ConversationItemTruncateEvent
  | InputAudioBufferAppendEvent
  | InputAudioBufferClearEvent
  | InputAudioBufferCommitEvent
  | ResponseCancelEvent
  | ResponseCreateEvent
  | SessionUpdateEvent
  | TranscriptionSessionUpdate;

export type RealtimeServerEvent =
  | ConversationCreatedEvent
  | ConversationItemCreatedEvent
  | ConversationItemDeletedEvent
  | ConversationItemInputAudioTranscriptionCompletedEvent
  | ConversationItemInputAudioTranscriptionDeltaEvent
  | ConversationItemInputAudioTranscriptionFailedEvent
  | ConversationItemTruncatedEvent
  | ErrorEvent
  | InputAudioBufferClearedEvent
  | InputAudioBufferCommittedEvent
  | InputAudioBufferSpeechStartedEvent
  | InputAudioBufferSpeechStoppedEvent
  | RateLimitsUpdatedEvent
  | ResponseAudioDeltaEvent
  | ResponseAudioDoneEvent
  | ResponseAudioTranscriptDeltaEvent
  | ResponseAudioTranscriptDoneEvent
  | ResponseContentPartAddedEvent
  | ResponseContentPartDoneEvent
  | ResponseCreatedEvent
  | ResponseDoneEvent
  | ResponseFunctionCallArgumentsDeltaEvent
  | ResponseFunctionCallArgumentsDoneEvent
  | ResponseOutputItemAddedEvent
  | ResponseOutputItemDoneEvent
  | ResponseTextDeltaEvent
  | ResponseTextDoneEvent
  | SessionCreatedEvent
  | SessionUpdatedEvent
  | TranscriptionSessionUpdatedEvent;

Import

import OpenAI from 'openai';
// Access via client.beta.realtime
// Sub-resources: client.beta.realtime.sessions, client.beta.realtime.transcriptionSessions

I/O Contract

Inputs

Name Type Required Description
(none) -- -- The Realtime class itself has no direct methods; inputs are on sub-resources

Outputs

Name Type Description
RealtimeClientEvent RealtimeClientEvent Union of 11 client-to-server event types for WebSocket communication
RealtimeServerEvent RealtimeServerEvent Union of 28 server-to-client event types for WebSocket communication
ConversationItem ConversationItem Represents a message, function_call, or function_call_output item
RealtimeResponse RealtimeResponse Represents a Realtime API response with status, output, and usage

Usage Examples

Basic Usage

import OpenAI from 'openai';

const client = new OpenAI();

// Access sub-resources through the beta realtime namespace
const session = await client.beta.realtime.sessions.create({
  model: 'gpt-4o-realtime-preview',
  voice: 'alloy',
});

// The event types are used when working with WebSocket connections
// Type imports for Realtime events:
import type {
  RealtimeClientEvent,
  RealtimeServerEvent,
  ConversationItem,
  SessionUpdateEvent,
} from 'openai/resources/beta/realtime/realtime';

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment