ExBifrost.Api.Realtime (ex_bifrost v0.1.0)

Copy Markdown View Source

API calls for all endpoints tagged Realtime.

Summary

Functions

Realtime API WebSocket Opens a bidirectional WebSocket session to a realtime-capable provider (e.g. OpenAI Realtime, Azure Realtime preview). Bifrost proxies the upstream socket and applies governance, observability, and key selection on connect. The target model is provided via the model query parameter (or deployment for Azure-style routes). The OpenAI SDK sends the API key over the openai-insecure-api-key.<key> WebSocket subprotocol; Bifrost extracts it and treats it the same as a Bearer header. Inference auth applies — Bearer/Basic/Virtual Key/API Key headers are all accepted, plus the subprotocol form above.

Realtime WebRTC SDP exchange Negotiates a WebRTC peer connection with the realtime provider on behalf of the client. Implements the OpenAI GA /realtime/calls contract: the request body is multipart/form-data with sdp (client SDP offer) and session (JSON session description containing model). Bifrost forwards the offer to the upstream provider, returns the upstream SDP answer to the client, and pipes RTP media between the two peers for the lifetime of the session. Inference auth applies (Bearer/Basic/Virtual Key/API Key).

Mint a realtime ephemeral client secret Calls the upstream realtime provider's client_secrets endpoint to mint a short-lived ephemeral token (e.g. for browser-based WebRTC clients). Bifrost selects a provider key, evaluates governance, and proxies the response. The returned token is cached and mapped to the originating virtual key for downstream attribution. Request body must be JSON. session.model (or top-level model) must use provider/model form.

Mint a realtime session (legacy alias) Legacy alias for the realtime client-secret minting endpoint. Behaves identically to createRealtimeClientSecret but uses the sessions route shape; provided for compatibility with older OpenAI Realtime client libraries.

Functions

connect_realtime(connection, upgrade, opts \\ [])

@spec connect_realtime(Tesla.Env.client(), String.t(), keyword()) ::
  {:ok, nil} | {:error, Tesla.Env.t()}

Realtime API WebSocket Opens a bidirectional WebSocket session to a realtime-capable provider (e.g. OpenAI Realtime, Azure Realtime preview). Bifrost proxies the upstream socket and applies governance, observability, and key selection on connect. The target model is provided via the model query parameter (or deployment for Azure-style routes). The OpenAI SDK sends the API key over the openai-insecure-api-key.<key> WebSocket subprotocol; Bifrost extracts it and treats it the same as a Bearer header. Inference auth applies — Bearer/Basic/Virtual Key/API Key headers are all accepted, plus the subprotocol form above.

Parameters

  • connection (ExBifrost.Connection): Connection to server
  • upgrade (String.t): Must be websocket
  • opts (keyword): Optional parameters
    • :model (String.t): Provider model identifier in provider/model form (e.g. openai/gpt-4o-realtime-preview). Either model or deployment must be supplied; requests with neither (or both) are rejected with HTTP 400 before the WebSocket upgrade completes.
    • :deployment (String.t): Azure deployment name (for Azure-style routes).
    • :"Sec-WebSocket-Protocol" (String.t): Optional WebSocket subprotocol. Use openai-insecure-api-key.<key> to authenticate when headers cannot be supplied by the client.

Returns

  • {:ok, nil} on success
  • {:error, Tesla.Env.t} on failure

create_realtime_call(connection, sdp, session, opts \\ [])

@spec create_realtime_call(Tesla.Env.client(), String.t(), String.t(), keyword()) ::
  {:ok, nil}
  | {:ok, ExBifrost.Model.BifrostError.t()}
  | {:ok, String.t()}
  | {:error, Tesla.Env.t()}

Realtime WebRTC SDP exchange Negotiates a WebRTC peer connection with the realtime provider on behalf of the client. Implements the OpenAI GA /realtime/calls contract: the request body is multipart/form-data with sdp (client SDP offer) and session (JSON session description containing model). Bifrost forwards the offer to the upstream provider, returns the upstream SDP answer to the client, and pipes RTP media between the two peers for the lifetime of the session. Inference auth applies (Bearer/Basic/Virtual Key/API Key).

Parameters

  • connection (ExBifrost.Connection): Connection to server
  • sdp (String.t): Client-generated SDP offer
  • session (String.t): JSON-encoded session descriptor. session.model is required and must be in provider/model form.
  • opts (keyword): Optional parameters

Returns

  • {:ok, String.t} on success
  • {:error, Tesla.Env.t} on failure

create_realtime_client_secret(connection, body, opts \\ [])

@spec create_realtime_client_secret(
  Tesla.Env.client(),
  %{optional(String.t()) => any()},
  keyword()
) ::
  {:ok, map()}
  | {:ok, nil}
  | {:ok, ExBifrost.Model.BifrostError.t()}
  | {:error, Tesla.Env.t()}

Mint a realtime ephemeral client secret Calls the upstream realtime provider's client_secrets endpoint to mint a short-lived ephemeral token (e.g. for browser-based WebRTC clients). Bifrost selects a provider key, evaluates governance, and proxies the response. The returned token is cached and mapped to the originating virtual key for downstream attribution. Request body must be JSON. session.model (or top-level model) must use provider/model form.

Parameters

  • connection (ExBifrost.Connection): Connection to server
  • body (map()):
  • opts (keyword): Optional parameters

Returns

  • {:ok, map()} on success
  • {:error, Tesla.Env.t} on failure

create_realtime_session(connection, body, opts \\ [])

@spec create_realtime_session(
  Tesla.Env.client(),
  %{optional(String.t()) => any()},
  keyword()
) ::
  {:ok, map()}
  | {:ok, nil}
  | {:ok, ExBifrost.Model.BifrostError.t()}
  | {:error, Tesla.Env.t()}

Mint a realtime session (legacy alias) Legacy alias for the realtime client-secret minting endpoint. Behaves identically to createRealtimeClientSecret but uses the sessions route shape; provided for compatibility with older OpenAI Realtime client libraries.

Parameters

  • connection (ExBifrost.Connection): Connection to server
  • body (map()):
  • opts (keyword): Optional parameters

Returns

  • {:ok, map()} on success
  • {:error, Tesla.Env.t} on failure