The Realtime API enables low-latency, bidirectional voice and audio conversations with OpenAI models. It supports WebRTC for browser-based apps and SIP for telephony integrations.
Client secrets are short-lived tokens that grant access to the Realtime API without exposing your main API key. Use these for client-side applications.
# In your webhook handler for incoming callspost '/webhooks/sip/inbound' do call_id = params[:call_id] from_number = params[:from] # Accept the call with a configured session client.realtime.calls.accept( call_id, model: "gpt-4o-realtime-preview", instructions: "You are a customer support agent for Acme Corp. Be helpful and professional.", audio: { voice: "shimmer", format: "g711_ulaw", sample_rate: 8000 }, tools: [ { type: "function", function: { name: "lookup_order", description: "Look up customer order status", parameters: { type: "object", properties: { order_id: { type: "string" } } } } } ] ) status 200end# Transfer call to human agentpost '/transfer/:call_id' do client.realtime.calls.refer( params[:call_id], target_uri: "sip:[email protected]" ) status 200end