Universal.Operative.Sdk.Realtime.xAI
2.0.0
dotnet add package Universal.Operative.Sdk.Realtime.xAI --version 2.0.0
NuGet\Install-Package Universal.Operative.Sdk.Realtime.xAI -Version 2.0.0
<PackageReference Include="Universal.Operative.Sdk.Realtime.xAI" Version="2.0.0" />
<PackageVersion Include="Universal.Operative.Sdk.Realtime.xAI" Version="2.0.0" />
<PackageReference Include="Universal.Operative.Sdk.Realtime.xAI" />
paket add Universal.Operative.Sdk.Realtime.xAI --version 2.0.0
#r "nuget: Universal.Operative.Sdk.Realtime.xAI, 2.0.0"
#:package Universal.Operative.Sdk.Realtime.xAI@2.0.0
#addin nuget:?package=Universal.Operative.Sdk.Realtime.xAI&version=2.0.0
#tool nuget:?package=Universal.Operative.Sdk.Realtime.xAI&version=2.0.0
About
Universal.Operative.Sdk.Realtime.xAI adapts xAI's Grok Voice Agent API to Universal.Operative.Sdk.Realtime's provider-neutral IModel/IRealtimeSession/SessionEvent model. The wire protocol itself comes from Universal.xAI.Realtime.Client.
How to Use
Installation
dotnet add package Universal.Operative.Sdk
dotnet add package Universal.Operative.Sdk.Realtime
dotnet add package Universal.Operative.Sdk.Realtime.xAI
Quick start
using Universal.Operative.Sdk.Realtime;
using Universal.Operative.Sdk.Realtime.xAI;
var model = new Model(apiKey, modelId: Models.GrokVoiceLatest);
IRealtimeSession session = await model.ConnectAsync(new RealtimeSessionOptions
{
SystemPrompt = [new TextBlock("You are a helpful voice assistant.")],
Tools = [myTool],
});
await foreach (SessionOutputEvent e in session.Output)
{
switch (e)
{
case SessionReadyEvent: Console.WriteLine("connected"); break;
case TranscriptDeltaEvent t: Console.WriteLine($"{t.Role}: {t.Text}"); break;
case AudioOutputDeltaEvent a: /* play a.Audio (24kHz PCM16 by default) */ break;
case InterruptedEvent: /* stop playback */ break;
}
}
await session.SendAsync(new AppendAudioInputEvent { Audio = micChunk });
Provider-specific options
GrokRealtimeSessionOptions is a RealtimeSessionOptions subclass carrying the xAI-specific settings:
var options = new GrokRealtimeSessionOptions
{
SystemPrompt = [new TextBlock("You are a helpful voice assistant.")],
Voice = Voices.Eve,
OutputAudioFormat = RealtimeAudioFormat.Pcm(RealtimeAudioSampleRates.Hz16000),
OutputSpeed = 1.1,
TurnDetection = new TurnDetection(TurnDetectionTypes.ServerVad) { IdleTimeoutMilliseconds = 8000 },
InputTranscription = new RealtimeAudioTranscription { LanguageHint = LanguageHints.English, Keyterms = ["Grok"] },
ReasoningEffort = ReasoningEfforts.None,
Replace = new Dictionary<string, string> { ["Acme Mobile"] = "Acme Mobull" },
};
Setting InputAudioTransport/OutputAudioTransport to AudioTransports.Binary carries audio in WebSocket binary frames instead of base64 JSON. AppendAudioInputEvent and AudioOutputDeltaEvent are unchanged either way.
Behaviour notes
- Capabilities:
AudioInProcess | ToolCalling | Transcripts. - Turn detection:
server_vadis the default. A nullTurnDetectiondrives turns withCommitAudioInputEvent. - Transcripts: user transcripts arrive cumulatively as non-final
TranscriptDeltaEvents, each superseding the last, then once as final. Assistant transcripts arrive once per turn, as final. - Message roles:
SendTextInputEventacceptsuserandassistant.MessageRoles.Systemthrows; the system prompt belongs inRealtimeSessionOptions.SystemPrompt. - Tools:
RealtimeSessionOptions.Toolsmaps to xAI function tools. xAI's server-side tools (web_search,x_search,file_search,mcp) are reachable throughRawSendEventwith a constructedSessionUpdateEvent. - Tool results:
ToolResultcontent is flattened into xAI's single-stringfunction_call_output. RawSendEvent: resolves itsRawJsonagainst every client event this adapter can send by matching the"type"field, or sends a constructedRealtimeClientEventpassed asPayloadas-is.- Unmodelled server events: surface as
RawPassthroughEventwith their payload intact.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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 is compatible. 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. |
-
net10.0
- Universal.Operative.Sdk (>= 6.0.0)
- Universal.Operative.Sdk.Realtime (>= 2.0.0)
- Universal.xAI.Realtime.Client (>= 1.0.0)
-
net8.0
- Universal.Operative.Sdk (>= 6.0.0)
- Universal.Operative.Sdk.Realtime (>= 2.0.0)
- Universal.xAI.Realtime.Client (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Coordinated major release for Universal.Operative.Sdk 6 and the canonical provider-neutral tool-dispatch boundary.