Implementation:Openai Openai node Realtime Calls
| Knowledge Sources | |
|---|---|
| Domains | SDK, Realtime, Telephony |
| Last Updated | 2026-02-15 12:00 GMT |
Overview
The Calls class provides API resource methods for managing Realtime API calls, including accepting, rejecting, hanging up, and transferring SIP/WebRTC calls.
Description
The Calls class extends APIResource and exposes four methods for telephony call lifecycle management through the OpenAI Realtime API. The accept method accepts an incoming SIP call and configures the realtime session that will handle it, supporting a rich set of session configuration options including model selection, audio configuration, instructions, tools, and truncation behavior. The hangup method terminates an active call regardless of whether it was initiated via SIP or WebRTC.
The refer method transfers an active SIP call to a new destination using the SIP REFER verb, accepting a target_uri that supports tel: and sip: URI schemes. The reject method declines an incoming SIP call by sending a configurable SIP status code back to the caller, defaulting to 603 (Decline) if no code is specified.
All four methods return APIPromise<void> since they perform actions without returning response bodies. The module exports three parameter interfaces: CallAcceptParams (with extensive session configuration), CallReferParams (with a required target_uri), and CallRejectParams (with an optional status_code).
Usage
Use this resource when building telephony integrations with the OpenAI Realtime API. It is the programmatic interface for controlling SIP call flows: accepting incoming calls with a configured AI session, transferring calls to other endpoints, or rejecting unwanted calls.
Code Reference
Source Location
- Repository: openai-node
- File: src/resources/realtime/calls.ts
Signature
export class Calls extends APIResource {
accept(callID: string, body: CallAcceptParams, options?: RequestOptions): APIPromise<void>;
hangup(callID: string, options?: RequestOptions): APIPromise<void>;
refer(callID: string, body: CallReferParams, options?: RequestOptions): APIPromise<void>;
reject(callID: string, body?: CallRejectParams | null, options?: RequestOptions): APIPromise<void>;
}
export interface CallAcceptParams {
type: 'realtime';
audio?: RealtimeAudioConfig;
include?: Array<'item.input_audio_transcription.logprobs'>;
instructions?: string;
max_output_tokens?: number | 'inf';
model?: string | 'gpt-realtime' | ...;
output_modalities?: Array<'text' | 'audio'>;
prompt?: ResponsePrompt | null;
tool_choice?: RealtimeToolChoiceConfig;
tools?: RealtimeToolsConfig;
tracing?: RealtimeTracingConfig | null;
truncation?: RealtimeTruncation;
}
export interface CallReferParams {
target_uri: string;
}
export interface CallRejectParams {
status_code?: number;
}
Import
import OpenAI from 'openai';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| callID | string |
Yes | The identifier of the realtime call to act upon. |
| body.type | 'realtime' |
Yes (accept) | Session type; always 'realtime'.
|
| body.model | string |
No (accept) | The Realtime model to use for the session. |
| body.instructions | string |
No (accept) | System instructions prepended to model calls. |
| body.max_output_tokens | 'inf' | No (accept) | Maximum output tokens for assistant responses. |
| body.output_modalities | 'audio'> | No (accept) | Modalities the model can respond with. |
| body.tools | RealtimeToolsConfig |
No (accept) | Tools available to the model during the session. |
| body.target_uri | string |
Yes (refer) | SIP Refer-To URI (e.g., tel:+14155550123).
|
| body.status_code | number |
No (reject) | SIP response code; defaults to 603 (Decline). |
| options | RequestOptions |
No | Additional request configuration. |
Outputs
| Name | Type | Description |
|---|---|---|
| (void) | void |
All four methods return void on success. |
Usage Examples
import OpenAI from 'openai';
const client = new OpenAI();
// Accept an incoming SIP call with a configured session
await client.realtime.calls.accept('call_abc123', {
type: 'realtime',
model: 'gpt-realtime',
instructions: 'You are a helpful customer support agent.',
output_modalities: ['audio'],
});
// Transfer a call to another number
await client.realtime.calls.refer('call_abc123', {
target_uri: 'tel:+14155550123',
});
// Reject an incoming call with a custom status code
await client.realtime.calls.reject('call_def456', {
status_code: 486, // Busy Here
});
// Hang up an active call
await client.realtime.calls.hangup('call_abc123');