Module: OpenAI::Helpers::Realtime::ClientExtension

Included in:
Client
Defined in:
lib/openai/helpers/realtime/client_extension.rb

Overview

Realtime request integration kept outside the generated client implementation.

Instance Method Summary collapse

Instance Method Details

#realtime_connection_request(path:, query:, websocket_base_url: nil, options: nil) ⇒ Hash{Symbol=>Object}

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.

Build a fully authenticated Realtime WebSocket handshake request. Realtime transports use this boundary so provider authentication and request options stay consistent with ordinary SDK requests.

Parameters:

  • path (String)
  • query (Hash{String=>String})
  • options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil) (defaults to: nil)

Returns:

  • (Hash{Symbol=>Object})


19
20
21
22
23
24
25
26
27
# File 'lib/openai/helpers/realtime/client_extension.rb', line 19

def realtime_connection_request(path:, query:, websocket_base_url: nil, options: nil)
  request, = build_realtime_connection_request(
    path: path,
    query: query,
    websocket_base_url: websocket_base_url,
    options: options
  )
  request
end

#with_realtime_connection_request(path:, query:, websocket_base_url: nil, options: nil) ⇒ Object

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.

Yield an authenticated WebSocket request, refreshing a rejected workload identity token exactly once after a definitive upgrade 401. The caller marks the handshake complete as soon as the transport yields a socket, before running application code; only pre-yield failures may retry.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/openai/helpers/realtime/client_extension.rb', line 35

def with_realtime_connection_request(path:, query:, websocket_base_url: nil, options: nil)
  request, deadline = build_realtime_connection_request(
    path: path,
    query: query,
    websocket_base_url: websocket_base_url,
    options: options
  )
  handshake_completed = false
  mark_handshake_completed = -> { handshake_completed = true }
  yield(request, mark_handshake_completed)
rescue OpenAI::Errors::RealtimeConnectionError => e
  raise if handshake_completed
  raise unless e.http_status == 401 && @workload_identity_auth

  @workload_identity_auth.invalidate_token
  refreshed, = build_realtime_connection_request(
    path: path,
    query: query,
    websocket_base_url: websocket_base_url,
    options: options,
    deadline: deadline
  )
  yield(refreshed, mark_handshake_completed)
end