Skip to content

Commit 9c2ac47

Browse files
feat(api): add support for realtime calls
1 parent a78c2b8 commit 9c2ac47

File tree

9 files changed

+335
-4
lines changed

9 files changed

+335
-4
lines changed

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 118
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-e205b1f2da6a1f2caa229efa9ede63f2d3d2fedeeb2dd6ed3d880bafdcb0ab88.yml
3-
openapi_spec_hash: c8aee2469a749f6a838b40c57e4b7b06
4-
config_hash: 45dcba51451ba532959c020a0ddbf23c
1+
configured_endpoints: 122
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-fadefdc7c7e30df47c09df323669b242ff90ee08e51f304175ace5274e0aab49.yml
3+
openapi_spec_hash: 6d20f639d9ff8a097a34962da6218231
4+
config_hash: 902654e60f5d659f2bfcfd903e17c46d

MIGRATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ client.example.list(undefined, { headers: { ... } });
133133
- `client.batches.list()`
134134
- `client.responses.retrieve()`
135135
- `client.responses.inputItems.list()`
136+
- `client.realtime.calls.reject()`
136137
- `client.conversations.create()`
137138
- `client.conversations.items.list()`
138139
- `client.evals.list()`

api.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,15 @@ Methods:
897897

898898
- <code title="post /realtime/client_secrets">client.realtime.clientSecrets.<a href="./src/resources/realtime/client-secrets.ts">create</a>({ ...params }) -> ClientSecretCreateResponse</code>
899899

900+
## Calls
901+
902+
Methods:
903+
904+
- <code title="post /realtime/calls/{call_id}/accept">client.realtime.calls.<a href="./src/resources/realtime/calls.ts">accept</a>(callID, { ...params }) -> void</code>
905+
- <code title="post /realtime/calls/{call_id}/hangup">client.realtime.calls.<a href="./src/resources/realtime/calls.ts">hangup</a>(callID) -> void</code>
906+
- <code title="post /realtime/calls/{call_id}/refer">client.realtime.calls.<a href="./src/resources/realtime/calls.ts">refer</a>(callID, { ...params }) -> void</code>
907+
- <code title="post /realtime/calls/{call_id}/reject">client.realtime.calls.<a href="./src/resources/realtime/calls.ts">reject</a>(callID, { ...params }) -> void</code>
908+
900909
# Conversations
901910

902911
Types:

scripts/detect-breaking-changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ TEST_PATHS=(
4646
tests/api-resources/responses/input-items.test.ts
4747
tests/api-resources/realtime/realtime.test.ts
4848
tests/api-resources/realtime/client-secrets.test.ts
49+
tests/api-resources/realtime/calls.test.ts
4950
tests/api-resources/conversations/conversations.test.ts
5051
tests/api-resources/conversations/items.test.ts
5152
tests/api-resources/evals/evals.test.ts

src/resources/realtime/calls.ts

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import { APIResource } from '../../core/resource';
4+
import * as RealtimeAPI from './realtime';
5+
import * as ResponsesAPI from '../responses/responses';
6+
import { APIPromise } from '../../core/api-promise';
7+
import { buildHeaders } from '../../internal/headers';
8+
import { RequestOptions } from '../../internal/request-options';
9+
import { path } from '../../internal/utils/path';
10+
11+
export class Calls extends APIResource {
12+
/**
13+
* Accept an incoming SIP call and configure the realtime session that will handle
14+
* it.
15+
*
16+
* @example
17+
* ```ts
18+
* await client.realtime.calls.accept('call_id', {
19+
* type: 'realtime',
20+
* });
21+
* ```
22+
*/
23+
accept(callID: string, body: CallAcceptParams, options?: RequestOptions): APIPromise<void> {
24+
return this._client.post(path`/realtime/calls/${callID}/accept`, {
25+
body,
26+
...options,
27+
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
28+
});
29+
}
30+
31+
/**
32+
* End an active Realtime API call, whether it was initiated over SIP or WebRTC.
33+
*
34+
* @example
35+
* ```ts
36+
* await client.realtime.calls.hangup('call_id');
37+
* ```
38+
*/
39+
hangup(callID: string, options?: RequestOptions): APIPromise<void> {
40+
return this._client.post(path`/realtime/calls/${callID}/hangup`, {
41+
...options,
42+
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
43+
});
44+
}
45+
46+
/**
47+
* Transfer an active SIP call to a new destination using the SIP REFER verb.
48+
*
49+
* @example
50+
* ```ts
51+
* await client.realtime.calls.refer('call_id', {
52+
* target_uri: 'tel:+14155550123',
53+
* });
54+
* ```
55+
*/
56+
refer(callID: string, body: CallReferParams, options?: RequestOptions): APIPromise<void> {
57+
return this._client.post(path`/realtime/calls/${callID}/refer`, {
58+
body,
59+
...options,
60+
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
61+
});
62+
}
63+
64+
/**
65+
* Decline an incoming SIP call by returning a SIP status code to the caller.
66+
*
67+
* @example
68+
* ```ts
69+
* await client.realtime.calls.reject('call_id');
70+
* ```
71+
*/
72+
reject(
73+
callID: string,
74+
body: CallRejectParams | null | undefined = {},
75+
options?: RequestOptions,
76+
): APIPromise<void> {
77+
return this._client.post(path`/realtime/calls/${callID}/reject`, {
78+
body,
79+
...options,
80+
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
81+
});
82+
}
83+
}
84+
85+
export interface CallAcceptParams {
86+
/**
87+
* The type of session to create. Always `realtime` for the Realtime API.
88+
*/
89+
type: 'realtime';
90+
91+
/**
92+
* Configuration for input and output audio.
93+
*/
94+
audio?: RealtimeAPI.RealtimeAudioConfig;
95+
96+
/**
97+
* Additional fields to include in server outputs.
98+
*
99+
* `item.input_audio_transcription.logprobs`: Include logprobs for input audio
100+
* transcription.
101+
*/
102+
include?: Array<'item.input_audio_transcription.logprobs'>;
103+
104+
/**
105+
* The default system instructions (i.e. system message) prepended to model calls.
106+
* This field allows the client to guide the model on desired responses. The model
107+
* can be instructed on response content and format, (e.g. "be extremely succinct",
108+
* "act friendly", "here are examples of good responses") and on audio behavior
109+
* (e.g. "talk quickly", "inject emotion into your voice", "laugh frequently"). The
110+
* instructions are not guaranteed to be followed by the model, but they provide
111+
* guidance to the model on the desired behavior.
112+
*
113+
* Note that the server sets default instructions which will be used if this field
114+
* is not set and are visible in the `session.created` event at the start of the
115+
* session.
116+
*/
117+
instructions?: string;
118+
119+
/**
120+
* Maximum number of output tokens for a single assistant response, inclusive of
121+
* tool calls. Provide an integer between 1 and 4096 to limit output tokens, or
122+
* `inf` for the maximum available tokens for a given model. Defaults to `inf`.
123+
*/
124+
max_output_tokens?: number | 'inf';
125+
126+
/**
127+
* The Realtime model used for this session.
128+
*/
129+
model?:
130+
| (string & {})
131+
| 'gpt-realtime'
132+
| 'gpt-realtime-2025-08-28'
133+
| 'gpt-4o-realtime-preview'
134+
| 'gpt-4o-realtime-preview-2024-10-01'
135+
| 'gpt-4o-realtime-preview-2024-12-17'
136+
| 'gpt-4o-realtime-preview-2025-06-03'
137+
| 'gpt-4o-mini-realtime-preview'
138+
| 'gpt-4o-mini-realtime-preview-2024-12-17';
139+
140+
/**
141+
* The set of modalities the model can respond with. It defaults to `["audio"]`,
142+
* indicating that the model will respond with audio plus a transcript. `["text"]`
143+
* can be used to make the model respond with text only. It is not possible to
144+
* request both `text` and `audio` at the same time.
145+
*/
146+
output_modalities?: Array<'text' | 'audio'>;
147+
148+
/**
149+
* Reference to a prompt template and its variables.
150+
* [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).
151+
*/
152+
prompt?: ResponsesAPI.ResponsePrompt | null;
153+
154+
/**
155+
* How the model chooses tools. Provide one of the string modes or force a specific
156+
* function/MCP tool.
157+
*/
158+
tool_choice?: RealtimeAPI.RealtimeToolChoiceConfig;
159+
160+
/**
161+
* Tools available to the model.
162+
*/
163+
tools?: RealtimeAPI.RealtimeToolsConfig;
164+
165+
/**
166+
* Realtime API can write session traces to the
167+
* [Traces Dashboard](/logs?api=traces). Set to null to disable tracing. Once
168+
* tracing is enabled for a session, the configuration cannot be modified.
169+
*
170+
* `auto` will create a trace for the session with default values for the workflow
171+
* name, group id, and metadata.
172+
*/
173+
tracing?: RealtimeAPI.RealtimeTracingConfig | null;
174+
175+
/**
176+
* Controls how the realtime conversation is truncated prior to model inference.
177+
* The default is `auto`.
178+
*/
179+
truncation?: RealtimeAPI.RealtimeTruncation;
180+
}
181+
182+
export interface CallReferParams {
183+
/**
184+
* URI that should appear in the SIP Refer-To header. Supports values like
185+
* `tel:+14155550123` or `sip:[email protected]`.
186+
*/
187+
target_uri: string;
188+
}
189+
190+
export interface CallRejectParams {
191+
/**
192+
* SIP response code to send back to the caller. Defaults to `603` (Decline) when
193+
* omitted.
194+
*/
195+
status_code?: number;
196+
}
197+
198+
export declare namespace Calls {
199+
export {
200+
type CallAcceptParams as CallAcceptParams,
201+
type CallReferParams as CallReferParams,
202+
type CallRejectParams as CallRejectParams,
203+
};
204+
}

src/resources/realtime/client-secrets.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import { RequestOptions } from '../../internal/request-options';
1010
export class ClientSecrets extends APIResource {
1111
/**
1212
* Create a Realtime client secret with an associated session configuration.
13+
*
14+
* @example
15+
* ```ts
16+
* const clientSecret =
17+
* await client.realtime.clientSecrets.create();
18+
* ```
1319
*/
1420
create(body: ClientSecretCreateParams, options?: RequestOptions): APIPromise<ClientSecretCreateResponse> {
1521
return this._client.post('/realtime/client_secrets', { body, ...options });

src/resources/realtime/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3+
export { Calls, type CallAcceptParams, type CallReferParams, type CallRejectParams } from './calls';
34
export {
45
ClientSecrets,
56
type RealtimeSessionClientSecret,

src/resources/realtime/realtime.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import { APIResource } from '../../core/resource';
44
import * as RealtimeAPI from './realtime';
55
import * as Shared from '../shared';
6+
import * as CallsAPI from './calls';
7+
import { CallAcceptParams, CallReferParams, CallRejectParams, Calls } from './calls';
68
import * as ClientSecretsAPI from './client-secrets';
79
import {
810
ClientSecretCreateParams,
@@ -17,6 +19,7 @@ import * as ResponsesAPI from '../responses/responses';
1719

1820
export class Realtime extends APIResource {
1921
clientSecrets: ClientSecretsAPI.ClientSecrets = new ClientSecretsAPI.ClientSecrets(this._client);
22+
calls: CallsAPI.Calls = new CallsAPI.Calls(this._client);
2023
}
2124

2225
export interface AudioTranscription {
@@ -4580,6 +4583,7 @@ export namespace TranscriptionSessionUpdatedEvent {
45804583
}
45814584

45824585
Realtime.ClientSecrets = ClientSecrets;
4586+
Realtime.Calls = Calls;
45834587

45844588
export declare namespace Realtime {
45854589
export {
@@ -4694,4 +4698,11 @@ export declare namespace Realtime {
46944698
type ClientSecretCreateResponse as ClientSecretCreateResponse,
46954699
type ClientSecretCreateParams as ClientSecretCreateParams,
46964700
};
4701+
4702+
export {
4703+
Calls as Calls,
4704+
type CallAcceptParams as CallAcceptParams,
4705+
type CallReferParams as CallReferParams,
4706+
type CallRejectParams as CallRejectParams,
4707+
};
46974708
}

0 commit comments

Comments
 (0)