Current section

Files

Jump to
oapi_open_ai lib operations realtime.ex
Raw

lib/operations/realtime.ex

defmodule OpenAi.Realtime do
@moduledoc """
Provides API endpoints related to realtime
"""
@default_client OpenAi.Client
@doc """
Create an ephemeral API token for use in client-side applications with the
Realtime API. Can be configured with the same session parameters as the
`session.update` client event.
It responds with a session object, plus a `client_secret` key which contains
a usable ephemeral API token that can be used to authenticate browser clients
for the Realtime API.
"""
@spec create_realtime_session(
body :: OpenAi.Realtime.Session.CreateRequest.t(),
opts :: keyword
) :: {:ok, OpenAi.Realtime.Session.CreateResponse.t()} | {:error, OpenAi.Error.error()}
def create_realtime_session(body, opts \\ []) do
client = opts[:client] || @default_client
client.request(%{
args: [body: body],
call: {OpenAi.Realtime, :create_realtime_session},
url: "/realtime/sessions",
body: body,
method: :post,
request: [{"application/json", {OpenAi.Realtime.Session.CreateRequest, :t}}],
response: [{200, {OpenAi.Realtime.Session.CreateResponse, :t}}],
opts: opts
})
end
@doc """
Create an ephemeral API token for use in client-side applications with the
Realtime API specifically for realtime transcriptions.
Can be configured with the same session parameters as the `transcription_session.update` client event.
It responds with a session object, plus a `client_secret` key which contains
a usable ephemeral API token that can be used to authenticate browser clients
for the Realtime API.
"""
@spec create_realtime_transcription_session(
body :: OpenAi.Realtime.TranscriptionSession.CreateRequest.t(),
opts :: keyword
) ::
{:ok, OpenAi.Realtime.TranscriptionSession.CreateResponse.t()}
| {:error, OpenAi.Error.error()}
def create_realtime_transcription_session(body, opts \\ []) do
client = opts[:client] || @default_client
client.request(%{
args: [body: body],
call: {OpenAi.Realtime, :create_realtime_transcription_session},
url: "/realtime/transcription_sessions",
body: body,
method: :post,
request: [{"application/json", {OpenAi.Realtime.TranscriptionSession.CreateRequest, :t}}],
response: [{200, {OpenAi.Realtime.TranscriptionSession.CreateResponse, :t}}],
opts: opts
})
end
end