Implementation:Openai Openai python Realtime Calls Override
| Knowledge Sources | |
|---|---|
| Domains | Realtime_API |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete tool for Realtime API call creation with SDP/multipart handling provided by the openai-python SDK.
Description
The _realtime module provides _Calls and _AsyncCalls classes that override the generated Calls and AsyncCalls resource classes to implement correct behavior for the POST /realtime/calls endpoint. The create() method accepts an sdp string (Session Description Protocol offer) and an optional session parameter of type RealtimeSessionCreateRequestParam. When session is omitted, the method sends a plain application/sdp request with the SDP payload as raw bytes. When session is provided, it sends a multipart/form-data request containing two parts: the SDP data (as application/sdp) and the session configuration serialized as application/json. Both variants set the Accept header to application/sdp and return an HttpxBinaryResponseContent containing the SDP answer. This is custom code intended to eventually be replaced by auto-generated code from the OpenAPI spec.
Usage
Use these classes when initiating WebRTC-based Realtime API sessions that require SDP offer/answer negotiation, optionally with session configuration parameters.
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/lib/_realtime.py
- Lines: 1-92
Signature
class _Calls(Calls):
@override
def create(
self,
*,
sdp: str,
session: RealtimeSessionCreateRequestParam | Omit = omit,
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> HttpxBinaryResponseContent: ...
class _AsyncCalls(AsyncCalls):
@override
async def create(
self,
*,
sdp: str,
session: RealtimeSessionCreateRequestParam | Omit = omit,
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> HttpxBinaryResponseContent: ...
Import
from openai.lib._realtime import _Calls, _AsyncCalls
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| sdp | str | Yes | The SDP (Session Description Protocol) offer string |
| session | RealtimeSessionCreateRequestParam or Omit | No | Optional session configuration; omit for SDP-only requests |
| extra_headers | Headers or None | No | Additional HTTP headers |
| extra_query | Query or None | No | Additional query parameters |
| extra_body | Body or None | No | Additional JSON body properties |
| timeout | float / httpx.Timeout / None / NotGiven | No | Request timeout override |
Outputs
| Name | Type | Description |
|---|---|---|
| create() result | HttpxBinaryResponseContent | The SDP answer from the Realtime API as binary content |
Usage Examples
Basic Usage
from openai import OpenAI
client = OpenAI()
# Simple SDP-only call
sdp_offer = "v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\n..."
response = client.realtime.calls.create(sdp=sdp_offer)
sdp_answer = response.content.decode("utf-8")
# Call with session configuration
response = client.realtime.calls.create(
sdp=sdp_offer,
session={
"model": "gpt-4o-realtime-preview",
"voice": "alloy",
},
)