Skip to content
For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Primary navigation

Realtime

Connect
realtime.connect(RealtimeConnectParams**kwargs)
Function
ModelsExpand Collapse
class AudioTranscription:
class ConversationCreatedEvent:

Returned when a conversation is created. Emitted right after session creation.

A single item within a Realtime conversation.

class ConversationItemAdded:

Sent by the server when an Item is added to the default Conversation. This can happen in several cases:

  • When the client sends a conversation.item.create event.
  • When the input audio buffer is committed. In this case the item will be a user message containing the audio from the buffer.
  • When the model is generating a Response. In this case the conversation.item.added event will be sent when the model starts generating a specific Item, and thus it will not yet have any content (and status will be in_progress).

The event will include the full content of the Item (except when model is generating a Response) except for audio data, which can be retrieved separately with a conversation.item.retrieve event if necessary.

class ConversationItemCreateEvent:

Add a new Item to the Conversation’s context, including messages, function calls, and function call responses. This event can be used both to populate a “history” of the conversation and to add new items mid-stream, but has the current limitation that it cannot populate assistant audio messages.

If successful, the server will respond with a conversation.item.created event, otherwise an error event will be sent.

class ConversationItemCreatedEvent:

Returned when a conversation item is created. There are several scenarios that produce this event:

  • The server is generating a Response, which if successful will produce either one or two Items, which will be of type message (role assistant) or type function_call.
  • The input audio buffer has been committed, either by the client or the server (in server_vad mode). The server will take the content of the input audio buffer and add it to a new user message Item.
  • The client has sent a conversation.item.create event to add a new Item to the Conversation.
class ConversationItemDeleteEvent:

Send this event when you want to remove any item from the conversation history. The server will respond with a conversation.item.deleted event, unless the item does not exist in the conversation history, in which case the server will respond with an error.

class ConversationItemDeletedEvent:

Returned when an item in the conversation is deleted by the client with a conversation.item.delete event. This event is used to synchronize the server’s understanding of the conversation history with the client’s view.

class ConversationItemDone:

Returned when a conversation item is finalized.

The event will include the full content of the Item except for audio data, which can be retrieved separately with a conversation.item.retrieve event if needed.

class ConversationItemInputAudioTranscriptionCompletedEvent:

This event is the output of audio transcription for user audio written to the user audio buffer. Transcription begins when the input audio buffer is committed by the client or server (when VAD is enabled). Transcription runs asynchronously with Response creation, so this event may come before or after the Response events.

Realtime API models accept audio natively, and thus input transcription is a separate process run on a separate ASR (Automatic Speech Recognition) model. The transcript may diverge somewhat from the model’s interpretation, and should be treated as a rough guide.

class ConversationItemInputAudioTranscriptionDeltaEvent:

Returned when the text value of an input audio transcription content part is updated with incremental transcription results.

class ConversationItemInputAudioTranscriptionFailedEvent:

Returned when input audio transcription is configured, and a transcription request for a user message failed. These events are separate from other error events so that the client can identify the related Item.

class ConversationItemInputAudioTranscriptionSegment:

Returned when an input audio transcription segment is identified for an item.

class ConversationItemRetrieveEvent:

Send this event when you want to retrieve the server’s representation of a specific item in the conversation history. This is useful, for example, to inspect user audio after noise cancellation and VAD. The server will respond with a conversation.item.retrieved event, unless the item does not exist in the conversation history, in which case the server will respond with an error.

class ConversationItemTruncateEvent:

Send this event to truncate a previous assistant message’s audio. The server will produce audio faster than realtime, so this event is useful when the user interrupts to truncate audio that has already been sent to the client but not yet played. This will synchronize the server’s understanding of the audio with the client’s playback.

Truncating audio will delete the server-side text transcript to ensure there is not text in the context that hasn’t been heard by the user.

If successful, the server will respond with a conversation.item.truncated event.

class ConversationItemTruncatedEvent:

Returned when an earlier assistant audio message item is truncated by the client with a conversation.item.truncate event. This event is used to synchronize the server’s understanding of the audio with the client’s playback.

This action will truncate the audio and remove the server-side text transcript to ensure there is no text in the context that hasn’t been heard by the user.

class ConversationItemWithReference:

The item to add to the conversation.

class InputAudioBufferAppendEvent:

Send this event to append audio bytes to the input audio buffer. The audio buffer is temporary storage you can write to and later commit. A “commit” will create a new user message item in the conversation history from the buffer content and clear the buffer. Input audio transcription (if enabled) will be generated when the buffer is committed.

If VAD is enabled the audio buffer is used to detect speech and the server will decide when to commit. When Server VAD is disabled, you must commit the audio buffer manually. Input audio noise reduction operates on writes to the audio buffer.

The client may choose how much audio to place in each event up to a maximum of 15 MiB, for example streaming smaller chunks from the client may allow the VAD to be more responsive. Unlike most other client events, the server will not send a confirmation response to this event.

class InputAudioBufferClearEvent:

Send this event to clear the audio bytes in the buffer. The server will respond with an input_audio_buffer.cleared event.

class InputAudioBufferClearedEvent:

Returned when the input audio buffer is cleared by the client with a input_audio_buffer.clear event.

class InputAudioBufferCommitEvent:

Send this event to commit the user input audio buffer, which will create a new user message item in the conversation. This event will produce an error if the input audio buffer is empty. When in Server VAD mode, the client does not need to send this event, the server will commit the audio buffer automatically.

Committing the input audio buffer will trigger input audio transcription (if enabled in session configuration), but it will not create a response from the model. The server will respond with an input_audio_buffer.committed event.

class InputAudioBufferCommittedEvent:

Returned when an input audio buffer is committed, either by the client or automatically in server VAD mode. The item_id property is the ID of the user message item that will be created, thus a conversation.item.created event will also be sent to the client.

class InputAudioBufferDtmfEventReceivedEvent:

SIP Only: Returned when an DTMF event is received. A DTMF event is a message that represents a telephone keypad press (0–9, *, #, A–D). The event property is the keypad that the user press. The received_at is the UTC Unix Timestamp that the server received the event.

class InputAudioBufferSpeechStartedEvent:

Sent by the server when in server_vad mode to indicate that speech has been detected in the audio buffer. This can happen any time audio is added to the buffer (unless speech is already detected). The client may want to use this event to interrupt audio playback or provide visual feedback to the user.

The client should expect to receive a input_audio_buffer.speech_stopped event when speech stops. The item_id property is the ID of the user message item that will be created when speech stops and will also be included in the input_audio_buffer.speech_stopped event (unless the client manually commits the audio buffer during VAD activation).

class InputAudioBufferSpeechStoppedEvent:

Returned in server_vad mode when the server detects the end of speech in the audio buffer. The server will also send an conversation.item.created event with the user message item that is created from the audio buffer.

class InputAudioBufferTimeoutTriggered:

Returned when the Server VAD timeout is triggered for the input audio buffer. This is configured with idle_timeout_ms in the turn_detection settings of the session, and it indicates that there hasn’t been any speech detected for the configured duration.

The audio_start_ms and audio_end_ms fields indicate the segment of audio after the last model response up to the triggering time, as an offset from the beginning of audio written to the input audio buffer. This means it demarcates the segment of audio that was silent and the difference between the start and end values will roughly match the configured timeout.

The empty audio will be committed to the conversation as an input_audio item (there will be a input_audio_buffer.committed event) and a model response will be generated. There may be speech that didn’t trigger VAD but is still detected by the model, so the model may respond with something relevant to the conversation or a prompt to continue speaking.

class LogProbProperties:

A log probability object.

class McpListToolsCompleted:

Returned when listing MCP tools has completed for an item.

class McpListToolsFailed:

Returned when listing MCP tools has failed for an item.

class McpListToolsInProgress:

Returned when listing MCP tools is in progress for an item.

Literal["near_field", "far_field"]

Type of noise reduction. near_field is for close-talking microphones such as headphones, far_field is for far-field microphones such as laptop or conference room microphones.

class OutputAudioBufferClearEvent:

WebRTC/SIP Only: Emit to cut off the current audio response. This will trigger the server to stop generating audio and emit a output_audio_buffer.cleared event. This event should be preceded by a response.cancel client event to stop the generation of the current response. Learn more.

class RateLimitsUpdatedEvent:

Emitted at the beginning of a Response to indicate the updated rate limits. When a Response is created some tokens will be “reserved” for the output tokens, the rate limits shown here reflect that reservation, which is then adjusted accordingly once the Response is completed.

class RealtimeAudioConfig:

Configuration for input and output audio.

class RealtimeAudioConfigInput:
class RealtimeAudioConfigOutput:

The PCM audio format. Only a 24kHz sample rate is supported.

Optional[RealtimeAudioInputTurnDetection]

Configuration for turn detection, ether Server VAD or Semantic VAD. This can be set to null to turn off, in which case the client must manually trigger model response.

Server VAD means that the model will detect the start and end of speech based on audio volume and respond at the end of user speech.

Semantic VAD is more advanced and uses a turn detection model (in conjunction with VAD) to semantically estimate whether the user has finished speaking, then dynamically sets a timeout based on this probability. For example, if user audio trails off with “uhhm”, the model will score a low probability of turn end and wait longer for the user to continue speaking. This can be useful for more natural conversations, but may have a higher latency.

For gpt-realtime-whisper transcription sessions, turn detection must be set to null; VAD is not supported.

class RealtimeConversationItemAssistantMessage:

An assistant message item in a Realtime conversation.

class RealtimeConversationItemFunctionCall:

A function call item in a Realtime conversation.

class RealtimeConversationItemFunctionCallOutput:

A function call output item in a Realtime conversation.

class RealtimeConversationItemSystemMessage:

A system message in a Realtime conversation can be used to provide additional context or instructions to the model. This is similar but distinct from the instruction prompt provided at the start of a conversation, as system messages can be added at any point in the conversation. For major changes to the conversation’s behavior, use instructions, but for smaller updates (e.g. “the user is now asking about a different topic”), use system messages.

class RealtimeConversationItemUserMessage:

A user message item in a Realtime conversation.

class RealtimeError:

Details of the error.

class RealtimeErrorEvent:

Returned when an error occurs, which could be a client problem or a server problem. Most errors are recoverable and the session will stay open, we recommend to implementors to monitor and log error messages by default.

class RealtimeFunctionTool:
class RealtimeMcpApprovalRequest:

A Realtime item requesting human approval of a tool invocation.

class RealtimeMcpApprovalResponse:

A Realtime item responding to an MCP approval request.

class RealtimeMcpListTools:

A Realtime item listing tools available on an MCP server.

class RealtimeMcpProtocolError:
class RealtimeMcpToolCall:

A Realtime item representing an invocation of a tool on an MCP server.

class RealtimeMcpToolExecutionError:
class RealtimeMcphttpError:
class RealtimeReasoning:

Configuration for reasoning-capable Realtime models such as gpt-realtime-2.

Literal["minimal", "low", "medium", 2 more]

Constrains effort on reasoning for reasoning-capable Realtime models such as gpt-realtime-2.

class RealtimeResponse:

The response resource.

class RealtimeResponseCreateAudioOutput:

Configuration for audio input and output.

class RealtimeResponseCreateMcpTool:

Give the model access to additional tools via remote Model Context Protocol (MCP) servers. Learn more about MCP.

class RealtimeResponseCreateParams:

Create a new Realtime response with these parameters

class RealtimeResponseStatus:

Additional details about the status.

class RealtimeResponseUsage:

Usage statistics for the Response, this will correspond to billing. A Realtime API session will maintain a conversation context and append new Items to the Conversation, thus output from previous turns (text and audio tokens) will become the input for later turns.

class RealtimeResponseUsageInputTokenDetails:

Details about the input tokens used in the Response. Cached tokens are tokens from previous turns in the conversation that are included as context for the current response. Cached tokens here are counted as a subset of input tokens, meaning input tokens will include cached and uncached tokens.

class RealtimeResponseUsageOutputTokenDetails:

Details about the output tokens used in the Response.

class RealtimeSession:

Realtime session object for the beta interface.

class RealtimeSessionCreateRequest:

Realtime session object configuration.

How the model chooses tools. Provide one of the string modes or force a specific function/MCP tool.

Tools available to the model.

Give the model access to additional tools via remote Model Context Protocol (MCP) servers. Learn more about MCP.

Optional[RealtimeTracingConfig]

Realtime API can write session traces to the Traces Dashboard. Set to null to disable tracing. Once tracing is enabled for a session, the configuration cannot be modified.

auto will create a trace for the session with default values for the workflow name, group id, and metadata.

class RealtimeTranscriptionSessionAudio:

Configuration for input and output audio.

class RealtimeTranscriptionSessionAudioInput:
Optional[RealtimeTranscriptionSessionAudioInputTurnDetection]

Configuration for turn detection, ether Server VAD or Semantic VAD. This can be set to null to turn off, in which case the client must manually trigger model response.

Server VAD means that the model will detect the start and end of speech based on audio volume and respond at the end of user speech.

Semantic VAD is more advanced and uses a turn detection model (in conjunction with VAD) to semantically estimate whether the user has finished speaking, then dynamically sets a timeout based on this probability. For example, if user audio trails off with “uhhm”, the model will score a low probability of turn end and wait longer for the user to continue speaking. This can be useful for more natural conversations, but may have a higher latency.

For gpt-realtime-whisper transcription sessions, turn detection must be set to null; VAD is not supported.

class RealtimeTranscriptionSessionCreateRequest:

Realtime transcription session object configuration.

A Realtime translation client event.

class RealtimeTranslationClientSecretCreateRequest:

Create a translation session and client secret for the Realtime API.

class RealtimeTranslationClientSecretCreateResponse:

Response from creating a translation session and client secret for the Realtime API.

class RealtimeTranslationInputAudioBufferAppendEvent:

Send this event to append audio bytes to the translation session input audio buffer.

WebSocket translation sessions accept base64-encoded 24 kHz PCM16 mono little-endian raw audio bytes. Unsupported websocket audio formats return a validation error because lower-quality audio materially degrades translation quality.

Translation consumes 200 ms engine frames. For best realtime behavior, append audio in 200 ms chunks. If a chunk is shorter, the server buffers it until it has enough audio for one frame. If a chunk is longer, the server splits it into 200 ms frames and enqueues them back-to-back.

Keep appending silence while the session is active. If a client stops sending audio and later resumes, model time treats the resumed audio as contiguous with the previous audio rather than as a real-world pause.

class RealtimeTranslationInputTranscriptDeltaEvent:

Returned when optional source-language transcript text is available. This event is emitted only when audio.input.transcription is configured.

Transcript deltas are append-only text fragments. Clients should not insert unconditional spaces between deltas.

class RealtimeTranslationOutputAudioDeltaEvent:

Returned when translated output audio is available. Output audio deltas are 200 ms frames of PCM16 audio.

class RealtimeTranslationOutputTranscriptDeltaEvent:

Returned when translated transcript text is available.

Transcript deltas are append-only text fragments. Clients should not insert unconditional spaces between deltas.

A Realtime translation server event.

class RealtimeTranslationSession:

A Realtime translation session. Translation sessions continuously translate input audio into the configured output language.

class RealtimeTranslationSessionCloseEvent:

Gracefully close the realtime translation session. The server flushes pending input audio and emits any remaining translated output before closing the session.

class RealtimeTranslationSessionClosedEvent:

Returned when a realtime translation session is closed.

class RealtimeTranslationSessionCreateRequest:

Realtime translation session configuration. Translation sessions stream source audio in and translated audio plus transcript deltas out continuously.

class RealtimeTranslationSessionCreatedEvent:

Returned when a translation session is created. Emitted automatically when a new connection is established as the first server event. This event contains the default translation session configuration.

class RealtimeTranslationSessionUpdateEvent:

Send this event to update the translation session configuration. Translation sessions support updates to audio.output.language, audio.input.transcription, and audio.input.noise_reduction.

class RealtimeTranslationSessionUpdateRequest:

Realtime translation session fields that can be updated with session.update.

class RealtimeTranslationSessionUpdatedEvent:

Returned when a translation session is updated with a session.update event, unless there is an error.

When the number of tokens in a conversation exceeds the model’s input token limit, the conversation be truncated, meaning messages (starting from the oldest) will not be included in the model’s context. A 32k context model with 4,096 max output tokens can only include 28,224 tokens in the context before truncation occurs.

Clients can configure truncation behavior to truncate with a lower max token limit, which is an effective way to control token usage and cost.

Truncation will reduce the number of cached tokens on the next turn (busting the cache), since messages are dropped from the beginning of the context. However, clients can also configure truncation to retain messages up to a fraction of the maximum context size, which will reduce the need for future truncations and thus improve the cache rate.

Truncation can be disabled entirely, which means the server will never truncate but would instead return an error if the conversation exceeds the model’s input token limit.

class RealtimeTruncationRetentionRatio:

Retain a fraction of the conversation tokens when the conversation exceeds the input token limit. This allows you to amortize truncations across multiple turns, which can help improve cached token usage.

class ResponseAudioDeltaEvent:

Returned when the model-generated audio is updated.

class ResponseAudioDoneEvent:

Returned when the model-generated audio is done. Also emitted when a Response is interrupted, incomplete, or cancelled.

class ResponseAudioTranscriptDeltaEvent:

Returned when the model-generated transcription of audio output is updated.

class ResponseAudioTranscriptDoneEvent:

Returned when the model-generated transcription of audio output is done streaming. Also emitted when a Response is interrupted, incomplete, or cancelled.

class ResponseCancelEvent:

Send this event to cancel an in-progress response. The server will respond with a response.done event with a status of response.status=cancelled. If there is no response to cancel, the server will respond with an error. It’s safe to call response.cancel even if no response is in progress, an error will be returned the session will remain unaffected.

class ResponseContentPartAddedEvent:

Returned when a new content part is added to an assistant message item during response generation.

class ResponseContentPartDoneEvent:

Returned when a content part is done streaming in an assistant message item. Also emitted when a Response is interrupted, incomplete, or cancelled.

class ResponseCreateEvent:

This event instructs the server to create a Response, which means triggering model inference. When in Server VAD mode, the server will create Responses automatically.

A Response will include at least one Item, and may have two, in which case the second will be a function call. These Items will be appended to the conversation history by default.

The server will respond with a response.created event, events for Items and content created, and finally a response.done event to indicate the Response is complete.

The response.create event includes inference configuration like instructions and tools. If these are set, they will override the Session’s configuration for this Response only.

Responses can be created out-of-band of the default Conversation, meaning that they can have arbitrary input, and it’s possible to disable writing the output to the Conversation. Only one Response can write to the default Conversation at a time, but otherwise multiple Responses can be created in parallel. The metadata field is a good way to disambiguate multiple simultaneous Responses.

Clients can set conversation to none to create a Response that does not write to the default Conversation. Arbitrary input can be provided with the input field, which is an array accepting raw Items and references to existing Items.

class ResponseCreatedEvent:

Returned when a new Response is created. The first event of response creation, where the response is in an initial state of in_progress.

class ResponseDoneEvent:

Returned when a Response is done streaming. Always emitted, no matter the final state. The Response object included in the response.done event will include all output Items in the Response but will omit the raw audio data.

Clients should check the status field of the Response to determine if it was successful (completed) or if there was another outcome: cancelled, failed, or incomplete.

A response will contain all output items that were generated during the response, excluding any audio content.

class ResponseFunctionCallArgumentsDeltaEvent:

Returned when the model-generated function call arguments are updated.

class ResponseFunctionCallArgumentsDoneEvent:

Returned when the model-generated function call arguments are done streaming. Also emitted when a Response is interrupted, incomplete, or cancelled.

class ResponseMcpCallArgumentsDelta:

Returned when MCP tool call arguments are updated during response generation.

class ResponseMcpCallArgumentsDone:

Returned when MCP tool call arguments are finalized during response generation.

class ResponseMcpCallCompleted:

Returned when an MCP tool call has completed successfully.

class ResponseMcpCallFailed:

Returned when an MCP tool call has failed.

class ResponseMcpCallInProgress:

Returned when an MCP tool call has started and is in progress.

class ResponseOutputItemAddedEvent:

Returned when a new Item is created during Response generation.

class ResponseOutputItemDoneEvent:

Returned when an Item is done streaming. Also emitted when a Response is interrupted, incomplete, or cancelled.

class ResponseTextDeltaEvent:

Returned when the text value of an “output_text” content part is updated.

class ResponseTextDoneEvent:

Returned when the text value of an “output_text” content part is done streaming. Also emitted when a Response is interrupted, incomplete, or cancelled.

class SessionCreatedEvent:

Returned when a Session is created. Emitted automatically when a new connection is established as the first server event. This event will contain the default Session configuration.

class SessionUpdateEvent:

Send this event to update the session’s configuration. The client may send this event at any time to update any field except for voice and model. voice can be updated only if there have been no other audio outputs yet.

When the server receives a session.update, it will respond with a session.updated event showing the full, effective configuration. Only the fields that are present in the session.update are updated. To clear a field like instructions, pass an empty string. To clear a field like tools, pass an empty array. To clear a field like turn_detection, pass null.

class SessionUpdatedEvent:

Returned when a session is updated with a session.update event, unless there is an error.

class TranscriptionSessionUpdate:

Send this event to update a transcription session.

class TranscriptionSessionUpdatedEvent:

Returned when a transcription session is updated with a transcription_session.update event, unless there is an error.

RealtimeCalls

Accept call
realtime.calls.accept(strcall_id, CallAcceptParams**kwargs)
POST/realtime/calls/{call_id}/accept
Create call
realtime.calls.create(CallCreateParams**kwargs) -> BinaryResponseContent
POST/realtime/calls
Hang up call
realtime.calls.hangup(strcall_id)
POST/realtime/calls/{call_id}/hangup
Refer call
realtime.calls.refer(strcall_id, CallReferParams**kwargs)
POST/realtime/calls/{call_id}/refer
Reject call
realtime.calls.reject(strcall_id, CallRejectParams**kwargs)
POST/realtime/calls/{call_id}/reject

RealtimeClient Secrets

Create client secret
realtime.client_secrets.create(ClientSecretCreateParams**kwargs) -> ClientSecretCreateResponse
POST/realtime/client_secrets
ModelsExpand Collapse
class ClientSecretCreateResponse:

Response from creating a session and client secret for the Realtime API.

class RealtimeSessionCreateResponse:

A Realtime session configuration object.

class RealtimeTranscriptionSessionCreateResponse:

A Realtime transcription session configuration object.

class RealtimeTranscriptionSessionTurnDetection:

Configuration for turn detection. Can be set to null to turn off. Server VAD means that the model will detect the start and end of speech based on audio volume and respond at the end of user speech. For gpt-realtime-whisper, this must be null; VAD is not supported.

RealtimeSessions

RealtimeTranscription Sessions

RealtimeTranslations

RealtimeTranslationsClient Secrets