Class: OpenAI::Resources::Realtime::Calls

Inherits:
Object
  • Object
show all
Defined in:
lib/openai/resources/realtime/calls.rb,
sig/openai/resources/realtime/calls.rbs

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Calls

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Calls.

Parameters:



199
200
201
# File 'lib/openai/resources/realtime/calls.rb', line 199

def initialize(client:)
  @client = client
end

Instance Method Details

#accept(call_id, audio: nil, include: nil, instructions: nil, max_output_tokens: nil, model: nil, output_modalities: nil, parallel_tool_calls: nil, prompt: nil, reasoning: nil, tool_choice: nil, tools: nil, tracing: nil, truncation: nil, type: :realtime, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::Realtime::CallAcceptParams for more details.

Accept an incoming SIP call and configure the realtime session that will handle it.

Parameters:

Returns:

  • (nil)

See Also:



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/openai/resources/realtime/calls.rb', line 104

def accept(call_id, params)
  parsed, options = OpenAI::Realtime::CallAcceptParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["realtime/calls/%1$s/accept", call_id],
    body: parsed,
    model: NilClass,
    security: {bearer_auth: true},
    options: options
  )
end

#create(sdp:, session: nil, request_options: {}) ⇒ OpenAI::HTTPClient::Response

Create a new Realtime API call over WebRTC and receive the SDP answer needed to complete the peer connection.

Parameters:

Returns:

See Also:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/openai/resources/realtime/calls.rb', line 21

def create(params)
  parsed, options = OpenAI::Realtime::CallCreateParams.dump_request(params)
  normalize_keys = lambda do |value|
    case value
    when Hash
      value.to_h { |key, child| [key.to_s, normalize_keys.call(child)] }
    when Array
      value.map { |child| normalize_keys.call(child) }
    else
      value
    end
  end

  multipart_body = OpenAI::Internal::Util.deep_merge(
    normalize_keys.call(parsed),
    normalize_keys.call(options[:extra_body] || {})
  )
  options = options.except(:extra_body)
  if multipart_body.key?("sdp")
    multipart_body["sdp"] = OpenAI::FilePart.new(multipart_body["sdp"], content_type: "application/sdp")
  end

  if multipart_body.key?("session")
    multipart_body["session"] = OpenAI::FilePart.new(
      JSON.generate(multipart_body["session"]),
      content_type: "application/json"
    )
  end

  @client.request(
    method: :post,
    path: "realtime/calls",
    headers: {"content-type" => "multipart/form-data", "accept" => "application/sdp"},
    body: multipart_body,
    model: OpenAI::HTTPClient::Response,
    security: {bearer_auth: true},
    options: {**options, max_retries: options[:max_retries] || 0}
  )
end

#hangup(call_id, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::Realtime::CallHangupParams for more details.

End an active Realtime API call, whether it was initiated over SIP or WebRTC.

Parameters:

  • call_id (String)

    The identifier for the call. For SIP calls, use the value provided in the

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



130
131
132
133
134
135
136
137
138
# File 'lib/openai/resources/realtime/calls.rb', line 130

def hangup(call_id, params = {})
  @client.request(
    method: :post,
    path: ["realtime/calls/%1$s/hangup", call_id],
    model: NilClass,
    security: {bearer_auth: true},
    options: params[:request_options]
  )
end

#refer(call_id, target_uri:, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::Realtime::CallReferParams for more details.

Transfer an active SIP call to a new destination using the SIP REFER verb.

Parameters:

  • call_id (String)

    The identifier for the call provided in the

  • target_uri (String)

    URI that should appear in the SIP Refer-To header. Supports values like

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/openai/resources/realtime/calls.rb', line 156

def refer(call_id, params)
  parsed, options = OpenAI::Realtime::CallReferParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["realtime/calls/%1$s/refer", call_id],
    body: parsed,
    model: NilClass,
    security: {bearer_auth: true},
    options: options
  )
end

#reject(call_id, status_code: nil, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::Realtime::CallRejectParams for more details.

Decline an incoming SIP call by returning a SIP status code to the caller.

Parameters:

  • call_id (String)

    The identifier for the call provided in the

  • status_code (Integer)

    SIP response code to send back to the caller. Defaults to 603 (Decline)

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



184
185
186
187
188
189
190
191
192
193
194
# File 'lib/openai/resources/realtime/calls.rb', line 184

def reject(call_id, params = {})
  parsed, options = OpenAI::Realtime::CallRejectParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["realtime/calls/%1$s/reject", call_id],
    body: parsed,
    model: NilClass,
    security: {bearer_auth: true},
    options: options
  )
end