Universal.Operative.Sdk.Realtime.xAI
1.2.0
See the version list below for details.
dotnet add package Universal.Operative.Sdk.Realtime.xAI --version 1.2.0
NuGet\Install-Package Universal.Operative.Sdk.Realtime.xAI -Version 1.2.0
<PackageReference Include="Universal.Operative.Sdk.Realtime.xAI" Version="1.2.0" />
<PackageVersion Include="Universal.Operative.Sdk.Realtime.xAI" Version="1.2.0" />
<PackageReference Include="Universal.Operative.Sdk.Realtime.xAI" />
paket add Universal.Operative.Sdk.Realtime.xAI --version 1.2.0
#r "nuget: Universal.Operative.Sdk.Realtime.xAI, 1.2.0"
#:package Universal.Operative.Sdk.Realtime.xAI@1.2.0
#addin nuget:?package=Universal.Operative.Sdk.Realtime.xAI&version=1.2.0
#tool nuget:?package=Universal.Operative.Sdk.Realtime.xAI&version=1.2.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 | 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 (>= 5.0.0)
- Universal.Operative.Sdk.Realtime (>= 1.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.
xAI Grok Voice Agent adapter for Universal.Operative.Sdk.Realtime, built on Universal.xAI.Realtime.Client.