Connect
Attach to an existing Live session. Do not send session.start again.
WebSocket wss://api.openai.com/v1/live/sessions/{session_id}/attach
Connect
require "openai"
require "async"
# Use an eligible existing Live session ID owned by your project.
client = OpenAI::Client.new
Sync do |task|
# Stop waiting if the peer never sends the expected events.
task.with_timeout(60) do
# This block releases only the observer, not the owner's session.
client.live.sideband.connect('sess_123') do |connection|
complete = false
connection.each do |event|
case event
when OpenAI::Live::ErrorEvent
raise "Live reported a session error."
when OpenAI::Live::SessionUsageUpdatedEvent
puts "Current cumulative usage: #{event.usage}"
complete = true
break
when OpenAI::Live::SessionClosedEvent
puts "Final usage: #{event.usage}"
complete = true
break
end
end
raise "Observer disconnected before a usage update or session.closed" unless complete
end
end
end