Skip to content

RealTime session create to retrieve Ephemeral Token#582

Merged
alexrudall merged 9 commits into
alexrudall:mainfrom
ngelx:main
Aug 10, 2025
Merged

RealTime session create to retrieve Ephemeral Token#582
alexrudall merged 9 commits into
alexrudall:mainfrom
ngelx:main

Conversation

@ngelx

@ngelx ngelx commented Mar 20, 2025

Copy link
Copy Markdown
Contributor

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
Copy Markdown

Awesome! I came her looking for this just now!

@pankaj-awake

Copy link
Copy Markdown

Wow, just what i needed, looking forward to this.

@ngelx

ngelx commented Jun 3, 2025

Copy link
Copy Markdown
Contributor Author

@alexrudall Any idea when this can be merged? There is anything that need to be changed or fixed?

@alexrudall

Copy link
Copy Markdown
Owner

@ngelx thanks for this - will try and test & merge ASAP.

@nekapoor

Copy link
Copy Markdown

@alexrudall certainly don't want to be pushy! Very grateful for all you've done with this library! But any chance you had time to test? Would love to have this feature merged

@alexrudall alexrudall merged commit 90d5c90 into alexrudall:main Aug 10, 2025
0 of 7 checks passed
@alexrudall

Copy link
Copy Markdown
Owner

Released in v8.2.0 - thank you @ngelx! @nekapoor

@nekapoor

Copy link
Copy Markdown

amazing, thanks so much @alexrudall! and of course, thank you @ngelx for this PR!

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.

5 participants