> For the complete documentation index, see [llms.txt](https://docs.wisej.com/ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wisej.com/ai/components/api/smartendpoint/wisej.ai.endpoints.openaiendpointrealtime.md).

# OpenAIEndpointRealtime

Namespace: **Wisej.AI.Endpoints**

Assembly: **Wisej.AI** (3.5.0.0)

* [SmartEndpoint](/ai/components/api/smartendpoint.md)
  * [SmartHttpEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.smarthttpendpoint.md)
    * [OpenAIEndpointRealtime](/ai/components/api/smartendpoint/wisej.ai.endpoints.openaiendpointrealtime.md)

Represents a component that manages communication with OpenAI's real-time API endpoints.

{% tabs %}
{% tab title="C#" %}

```csharp
public class OpenAIEndpointRealtime : SmartHttpEndpoint
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class OpenAIEndpointRealtime
    Inherits SmartHttpEndpoint
```

{% endtab %}
{% endtabs %}

[OpenAIEndpointRealtime](/ai/components/api/smartendpoint/wisej.ai.endpoints.openaiendpointrealtime.md) provides a convenient way to connect to and interact with OpenAI's real-time endpoints within a Wisej application. It extends [SmartHttpEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.smarthttpendpoint.md), inheriting HTTP communication capabilities and adding specialized logic for real-time data exchange with OpenAI services.\
This component can be used to send prompts, receive streaming responses, and manage session state with OpenAI's real-time APIs.

## Constructors

### ![](/files/ptrKjmmRoQB76pvrIqh0) OpenAIEndpointRealtime()

Initializes a new instance of the [OpenAIEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.openaiendpoint.md) class with default settings.

## Properties

### ![](/files/ptrKjmmRoQB76pvrIqh0) Model

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the model used for chat completions. (Default: `"gpt-4o-realtime-preview"`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) TranscriptionModel

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the model used for the audio transcription. (Default: `"gpt-4o-transcribe"`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) URL

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the base URL for the OpenAI API. (Default: `"https://api.openai.com/v1"`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) UseNativeTools

[Boolean](https://docs.microsoft.com/dotnet/api/system.boolean): (Default: `True`)

## Methods

### ![](/files/KL0Ik37djZRr8a07Wopd) AddOptions(message, session)

Adds options to the message payload.

| Parameter   | Type                                                          | Description                    |
| ----------- | ------------------------------------------------------------- | ------------------------------ |
| **message** | [Object](https://docs.microsoft.com/dotnet/api/system.object) | The message payload to modify. |
| **session** | [SmartSession](/ai/components/api/smartsession.md)            | The current session context.   |

Sets default values for temperature and max tokens in the message payload.

### ![](/files/KL0Ik37djZRr8a07Wopd) BuildInstructions(session)

Constructs the instruction string for the OpenAI real-time API endpoint based on the current session context.

| Parameter   | Type                                               | Description                                                                                                                                         |
| ----------- | -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| **session** | [SmartSession](/ai/components/api/smartsession.md) | The [SmartSession](/ai/components/api/smartsession.md) instance containing the session context and parameters used to build the instruction string. |

**Returns:** [String](https://docs.microsoft.com/dotnet/api/system.string). A string containing the fully constructed instructions for the OpenAI real-time API endpoint.

This method generates the instruction prompt by extracting the system message from the session, incorporating tool prompts, and replacing template placeholders such as `{{tools}}`, `{{today}}`, and `{{language}}` with their corresponding values. The resulting instruction string is then processed to replace any additional session parameters.\
Override this method to customize how instructions are built for the OpenAI endpoint.

### ![](/files/KL0Ik37djZRr8a07Wopd) BuildToolsPayload(session)

Builds the tools payload based on the session context.

| Parameter   | Type                                               | Description          |
| ----------- | -------------------------------------------------- | -------------------- |
| **session** | [SmartSession](/ai/components/api/smartsession.md) | The session context. |

**Returns:** [Object\[\]](https://docs.microsoft.com/dotnet/api/system.object). A JSON object representing the tools payload.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when the session is null.

### ![](/files/KL0Ik37djZRr8a07Wopd) CreateConfiguration(session)

Creates the configuration payload for the OpenAI real-time API session.

| Parameter   | Type                                               | Description                                                                                                       |
| ----------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| **session** | [SmartSession](/ai/components/api/smartsession.md) | The [SmartSession](/ai/components/api/smartsession.md) instance containing session-specific options and settings. |

**Returns:** [Object](https://docs.microsoft.com/dotnet/api/system.object). A dynamic object representing the configuration payload for the session.

This method builds a dynamic configuration object that includes options, tools, instructions, and modalities required by the OpenAI realtime API. If audio transcription is enabled, the configuration will also include the transcription model. The `transcription_enabled` property is removed from the final configuration payload.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Disable()

Disables the OpenAIEndpointRealtime component, stopping it from processing or sending further requests.

This method deactivates the component, preventing any further communication with the OpenAI Realtime API endpoint until [Enable](#enable) is called.

### ![](/files/KL0Ik37djZRr8a07Wopd) Dispose(disposing)

Releases the unmanaged resources used by the component and optionally releases the managed resources.

| Parameter     | Type                                                            | Description                                                                                      |
| ------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| **disposing** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) | true to release both managed and unmanaged resources; false to release only unmanaged resources. |

### ![](/files/ptrKjmmRoQB76pvrIqh0) Enable()

Enables the OpenAIEndpointRealtime component, allowing it to process and send requests.

This method activates the component, allowing it to resume communication with the OpenAI Realtime API endpoint after being disabled.

### ![](/files/KL0Ik37djZRr8a07Wopd) GetApiURL()

Constructs the API URL for the real time api.

**Returns:** [String](https://docs.microsoft.com/dotnet/api/system.string). The full API URL for the real time api..

### ![](/files/KL0Ik37djZRr8a07Wopd) GetEphemeralTokenAsync(session)

Asynchronously retrieves an ephemeral token for the specified session from the OpenAI realtime API endpoint.

| Parameter   | Type                                               | Description                                                                                                                                       |
| ----------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| **session** | [SmartSession](/ai/components/api/smartsession.md) | The [SmartSession](/ai/components/api/smartsession.md) instance representing the current user session for which the ephemeral token is requested. |

**Returns:** [Task\<Object>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task that represents the asynchronous operation. The task result contains a dynamic object representing the ephemeral token response from the API.

This method constructs a request to the OpenAI real-time API endpoint to obtain a temporary (ephemeral) token associated with the provided session. The token is typically used for short-lived authentication or authorization purposes during real-time communication.\
The method sends a POST request with the session configuration and parses the response as a dynamic object.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Mute()

Mutes the OpenAIEndpointRealtime component, suppressing any audio or notification output.

Use this method to temporarily silence the component without disabling its core functionality. To restore audio or notifications, call [Unmute](#unmute).

### ![](/files/KL0Ik37djZRr8a07Wopd) OnFunctionCall(e)

Raises the [FunctionCall](#functioncall) event.

| Parameter | Type                                                                                                                  | Description                                                                                                                                                 |
| --------- | --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **e**     | [FunctionCallEventArgs](https://docs.wisej.com/api?q=wisej.ai.endpoints.openaiendpointrealtime+functioncalleventargs) | A [FunctionCallEventArgs](https://docs.wisej.com/api?q=wisej.ai.endpoints.openaiendpointrealtime.functioncalleventargs) instance containing the event data. |

This method is called to notify subscribers that a function call has been detected in the AI's response. Override this method to provide custom handling for function calls.

### ![](/files/KL0Ik37djZRr8a07Wopd) OnResponseCreated(e)

Raises the [ResponseCreated](#responsecreated) event.

| Parameter | Type                                                                | Description                                                                                                |
| --------- | ------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| **e**     | [EventArgs](https://docs.microsoft.com/dotnet/api/system.eventargs) | An [EventArgs](https://docs.microsoft.com/dotnet/api/system.eventargs) instance containing the event data. |

### ![](/files/KL0Ik37djZRr8a07Wopd) OnResponseDone(e)

Raises the [ResponseDone](#responsedone) event.

| Parameter | Type                                                                                                                  | Description                                                                                                                                                                            |
| --------- | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **e**     | [ResponseDoneEventArgs](https://docs.wisej.com/api?q=wisej.ai.endpoints.openaiendpointrealtime+responsedoneeventargs) | A [ResponseDoneEventArgs](https://docs.wisej.com/api?q=wisej.ai.endpoints.openaiendpointrealtime.responsedoneeventargs) instance containing the event data for the completed response. |

### ![](/files/KL0Ik37djZRr8a07Wopd) OnTranscriptionCompleted(e)

Raises the [TranscriptionCompleted](#transcriptioncompleted) event.

| Parameter | Type                                                                                                                                      | Description                                                                                                                                                                                                     |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **e**     | [TranscriptionCompletedEventArgs](https://docs.wisej.com/api?q=wisej.ai.endpoints.openaiendpointrealtime+transcriptioncompletedeventargs) | A [TranscriptionCompletedEventArgs](https://docs.wisej.com/api?q=wisej.ai.endpoints.openaiendpointrealtime.transcriptioncompletedeventargs) instance containing the event data for the completed transcription. |

### ![](/files/KL0Ik37djZRr8a07Wopd) ReadUsage(message, reply)

Reads and updates the usage statistics from the OpenAI real-time API reply.

| Parameter   | Type                                                                        | Description                                                                                                        |
| ----------- | --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| **message** | [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md) | The message object to update with usage data.                                                                      |
| **reply**   | [Object](https://docs.microsoft.com/dotnet/api/system.object)               | The dynamic object containing the API response, expected to include `input_tokens` and `output_tokens` properties. |

### ![](/files/ptrKjmmRoQB76pvrIqh0) SendMessages(messages)

Sends an array of messages to the OpenAI Realtime API endpoint for processing.

| Parameter    | Type                                                              | Description                                                            |
| ------------ | ----------------------------------------------------------------- | ---------------------------------------------------------------------- |
| **messages** | [Object\[\]](https://docs.microsoft.com/dotnet/api/system.object) | An array of dynamic message objects to be sent to the OpenAI endpoint. |

Use this method to transmit one or more messages to the OpenAI Realtime API endpoint. Each message should conform to the expected structure required by the endpoint.

### ![](/files/ptrKjmmRoQB76pvrIqh0) StartListening(session)

Initiates listening for real-time events from the OpenAI endpoint using the specified session.

| Parameter   | Type                                               | Description                                                                                                                             |
| ----------- | -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| **session** | [SmartSession](/ai/components/api/smartsession.md) | The [SmartSession](/ai/components/api/smartsession.md) instance representing the current user session. This parameter cannot be `null`. |

This method establishes a connection to the OpenAI real-time API endpoint by obtaining an ephemeral token for the provided session and starting the listening process. It also triggers the `OnStart` event for the session and updates the associated component in the Wisej application.\
If *session* is `null`, an [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) is thrown.

### ![](/files/ptrKjmmRoQB76pvrIqh0) StopListening(session)

Stops listening for real-time events from the OpenAI endpoint for the specified session.

| Parameter   | Type                                               | Description                                                                                                                             |
| ----------- | -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| **session** | [SmartSession](/ai/components/api/smartsession.md) | The [SmartSession](/ai/components/api/smartsession.md) instance representing the current user session. This parameter cannot be `null`. |

This method terminates the connection to the OpenAI real-time API endpoint for the given session. It also triggers the `OnDone` event for the session to indicate that listening has stopped.\
If *session* is `null`, an [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) is thrown.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Unmute()

Unmutes the OpenAIEndpointRealtime component, restoring audio or notification output.

This method re-enables audio or notifications that were previously suppressed by [Mute](#mute).

## Events

### ![](/files/ptrKjmmRoQB76pvrIqh0) FunctionCall

[FunctionCallEventHandler](https://docs.wisej.com/api?q=wisej.ai.endpoints.openaiendpointrealtime+functioncalleventhandler) Occurs when a function call is detected in the response from the OpenAI Realtime API.

This event is triggered when the SmartRealtimeAdapter identifies a function call in the AI's response, allowing the application to handle or execute the function as needed.

### ![](/files/ptrKjmmRoQB76pvrIqh0) ResponseCreated

[EventHandler](https://docs.microsoft.com/dotnet/api/system.eventhandler) Occurs when a new response is created by the OpenAI real-time endpoint.

### ![](/files/ptrKjmmRoQB76pvrIqh0) ResponseDone

[ResponseDoneEventHandler](https://docs.wisej.com/api?q=wisej.ai.endpoints.openaiendpointrealtime+responsedoneeventhandler) Occurs when the response from the OpenAI real-time endpoint has been fully received and processing is complete.

### ![](/files/ptrKjmmRoQB76pvrIqh0) TranscriptionCompleted

[TranscriptionCompletedEventHandler](https://docs.wisej.com/api?q=wisej.ai.endpoints.openaiendpointrealtime+transcriptioncompletedeventhandler) Occurs when a transcription operation has completed.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/ai/components/api/smartendpoint/wisej.ai.endpoints.openaiendpointrealtime.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
