Universal.OpenAI.Realtime.Client 1.0.3

dotnet add package Universal.OpenAI.Realtime.Client --version 1.0.3
                    
NuGet\Install-Package Universal.OpenAI.Realtime.Client -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Universal.OpenAI.Realtime.Client" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Universal.OpenAI.Realtime.Client" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Universal.OpenAI.Realtime.Client" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Universal.OpenAI.Realtime.Client --version 1.0.3
                    
#r "nuget: Universal.OpenAI.Realtime.Client, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Universal.OpenAI.Realtime.Client@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Universal.OpenAI.Realtime.Client&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Universal.OpenAI.Realtime.Client&version=1.0.3
                    
Install as a Cake Tool

Universal.OpenAI.Realtime.Client

A .NET client for OpenAI's Realtime API WebSocket event protocol (wss://api.openai.com/v1/realtime) — typed client/server events, conversation items, and a ClientWebSocket-based session wrapper for voice and text conversations, function calling, and SIP call sidebands.

Session configuration, function tool schemas, and audio format types are shared with Universal.OpenAI.Client's Universal.OpenAI.Client.V1.Realtime namespace — use that package's RealtimeClient for the REST side (accepting/rejecting SIP calls, minting ephemeral client secrets) and this package for the live WebSocket connection.

Quick Start

using Universal.OpenAI.Realtime.Client;
using Universal.OpenAI.Client.V1.Realtime;

using RealtimeClient client = await RealtimeClient.ConnectAsync(apiKey, Models.GptRealtime2);

await client.SendAsync(new SessionUpdateEvent(new RealtimeSessionConfiguration
{
    Instructions = "You are a helpful assistant.",
    OutputModalities = new[] { RealtimeOutputModalities.Text }
}));
await client.SendAsync(new ConversationItemCreateEvent(new UserMessageItem("Say hello.")));
await client.SendAsync(new ResponseCreateEvent());

await foreach (RealtimeEvent evt in client.ReceiveEventsAsync())
{
    if (evt is ResponseOutputTextDeltaEvent delta)
    {
        Console.Write(delta.Delta);
    }
    if (evt is ResponseDoneEvent)
    {
        break;
    }
}

Features

Connecting

Three ways to open a connection, depending on how the session is being used:

// Direct, using your own API key (trusted server-side/console clients)
using RealtimeClient client = await RealtimeClient.ConnectAsync(apiKey, Models.GptRealtime2);

// As the WebSocket sideband for an already-accepted SIP call
using RealtimeClient client = await RealtimeClient.ConnectForCallAsync(apiKey, callId);

// Using an ephemeral client secret (untrusted/browser clients) minted via
// Universal.OpenAI.Client.V1.Realtime.RealtimeClient.CreateClientSecretAsync
using RealtimeClient client = await RealtimeClient.ConnectWithClientSecretAsync(clientSecretValue, Models.GptRealtime2);

Sending and Receiving Events

SendAsync takes any RealtimeClientEvent (SessionUpdateEvent, ConversationItemCreateEvent, ResponseCreateEvent, InputAudioBufferAppendEvent, etc.). ReceiveEventsAsync streams the full, typed server event set (SessionCreatedEvent, ResponseOutputTextDeltaEvent, ResponseFunctionCallArgumentsDoneEvent, RealtimeErrorEvent, and 35+ others) as an IAsyncEnumerable<RealtimeEvent>, dispatched on the wire type discriminator — pattern-match on the concrete type you care about:

await foreach (RealtimeEvent evt in client.ReceiveEventsAsync())
{
    switch (evt)
    {
        case ResponseOutputAudioDeltaEvent audio:
            PlaybackQueue.Enqueue(Convert.FromBase64String(audio.Delta));
            break;
        case ResponseFunctionCallArgumentsDoneEvent call:
            string result = await RunTool(call.Name, call.Arguments);
            await client.SendAsync(new ConversationItemCreateEvent(new FunctionCallOutputItem(call.CallId, result)));
            await client.SendAsync(new ResponseCreateEvent());
            break;
        case RealtimeErrorEvent error:
            Console.WriteLine($"Error: {error.Error.Message}");
            break;
    }
}

Function Calling

Define tools on the session (reusing Universal.OpenAI.Client.V1.Responses.Tool), force a specific tool when needed via tool_choice, and round-trip the result as a FunctionCallOutputItem:

await client.SendAsync(new SessionUpdateEvent(new RealtimeSessionConfiguration
{
    Tools = new[]
    {
        new Tool
        {
            Type = ToolTypes.Function,
            Name = "get_current_time",
            Description = "Returns the current time.",
            Parameters = new { type = "object", properties = new { }, required = Array.Empty<string>() }
        }
    }
}));

Conversation Items

ConversationItem covers messages (SystemMessageItem/UserMessageItem/AssistantMessageItem), function calls (FunctionCallItem/FunctionCallOutputItem), MCP tool interactions (McpToolCallItem, McpApprovalRequestItem, McpApprovalResponseItem, McpListToolsItem), and item references — each dispatched on its own type/role discriminators, mirroring how Universal.OpenAI.Client models the Responses API's polymorphic output items.

Disposal

RealtimeClient implements IDisposable, and CloseAsync initiates a clean WebSocket close handshake before disposal:

using RealtimeClient client = await RealtimeClient.ConnectAsync(apiKey, Models.GptRealtime2);
// ...
await client.CloseAsync();
// Client will be automatically disposed
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 97 7/20/2026
1.0.2 89 7/17/2026
1.0.1 88 7/17/2026
1.0.0 94 7/17/2026

Updated dependencies.