Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RealTime session create to retrieve Ephemeral Token #582

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ngelx
Copy link

@ngelx ngelx commented Mar 20, 2025

Following PR #545. Added a simple Ephemeral API token creation in order to be used to authenticate browser clients for the Realtime API. Useful to WebRTC integration.

Added Spec and basic documentation on how to use it.

response = client.real_time.create(parameters: { model: "gpt-4o-realtime-preview-2024-12-17" })
puts "ephemeral key: #{response.dig('client_secret', 'value')}"
# => "ephemeral key: ek_abc123"

Then in the client-side application, make a POST request to the Real-Time API with the ephemeral key and the SDP offer.

const OPENAI_REALTIME_URL = 'https://api.openai.com/v1/realtime/sessions'
const MODEL = 'gpt-4o-realtime-preview-2024-12-17'

const response = await fetch(`${OPENAI_REALTIME_URL}?model=${MODEL}`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/sdp',
    'Authorization': `Bearer ${ephemeralKey}`,
    'OpenAI-Beta': 'realtime=v1'
  },
  body: offer.sdp
})

API doc: https://platform.openai.com/docs/api-reference/realtime

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?

@joegaudet
Copy link

Awesome! I came her looking for this just now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants