varapiKey=Environment.GetEnvironmentVariable("XAI_API_KEY")is{Length:>0}apiKeyValue?apiKeyValue:thrownewAssertInconclusiveException("XAI_API_KEY environment variable is not found.");// Create a WebSocket client and connect to the xAI Realtime API.usingvarclient=newXaiRealtimeClient(apiKey);awaitclient.ConnectAsync();// Configure the session with voice, instructions, and turn detection.awaitclient.SendSessionUpdateAsync(newSessionUpdatePayload{Session=newSessionConfig{Voice=SessionConfigVoice.Eve,Instructions="You are a helpful assistant. Respond briefly.",Modalities=["text","audio"],TurnDetection=newTurnDetection{Type="server_vad",Threshold=0.85,SilenceDurationMs=500,},},});// Send a text message and request a text response.awaitclient.SendConversationItemCreateAsync(newConversationItemCreatePayload{Item=newConversationItem{Type="message",Role="user",Content=[newContentPart{Type="input_text",Text="Say hello!"}],},});awaitclient.SendResponseCreateAsync(newResponseCreatePayload{Response=newResponseConfig{Modalities=["text"],},});// Receive server events until the response is complete.usingvarcts=newCancellationTokenSource(TimeSpan.FromSeconds(30));varreceivedSessionUpdated=false;varreceivedResponseDone=false;string?transcriptText=null;awaitforeach(varserverEventinclient.ReceiveUpdatesAsync(cts.Token)){if(serverEvent.IsSessionUpdated){receivedSessionUpdated=true;}elseif(serverEvent.IsResponseOutputAudioTranscriptDelta){transcriptText=(transcriptText??"")+serverEvent.ResponseOutputAudioTranscriptDelta?.Delta;Console.Write(serverEvent.ResponseOutputAudioTranscriptDelta?.Delta);}elseif(serverEvent.IsResponseDone){receivedResponseDone=true;break;}elseif(serverEvent.IsError){}}