|
| 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 | +} |
0 commit comments