Wire an InworldJwtCache into InworldClient so the realtime (WebSocket)
streaming path pulls a fresh JWT from the cache on every connect. This
keeps long-lived backends correct across token rotations without
reconstructing the client.
This example assumes using Inworld; is in scope and apiKey contains your Inworld API key.
varapiKey=Environment.GetEnvironmentVariable("INWORLD_JWT_KEY")is{Length:>0}k?k:DecodeKeyPair(Environment.GetEnvironmentVariable("INWORLD_API_KEY")).key;varapiSecret=Environment.GetEnvironmentVariable("INWORLD_JWT_SECRET")is{Length:>0}s?s:DecodeKeyPair(Environment.GetEnvironmentVariable("INWORLD_API_KEY")).secret;if(string.IsNullOrEmpty(apiKey)||string.IsNullOrEmpty(apiSecret)){thrownewAssertInconclusiveException("INWORLD_API_KEY (or INWORLD_JWT_KEY + INWORLD_JWT_SECRET) is required.");}// Build a JwtCache once — in production it would be a singleton.usingvarjwtCache=newInworldJwtCache(apiKey,apiSecret);// Construct InworldClient directly from the cache: REST uses the// token active at construction, streaming fetches a fresh JWT per// connect via RealtimeTokenProvider.usingvarclient=newInworldClient(jwtCache);// Prove the provider hook is wired up.varpreview=awaitclient.RealtimeTokenProvider!(CancellationToken.None);// Synthesize a short phrase so we have something for STT to hear.conststringphrase="JWT cache is wired into streaming.";vartts=awaitclient.TextToSpeech.SynthesizeSpeechAsync(text:phrase,voiceId:"Dennis",modelId:"inworld-tts-1.5-max",audioConfig:newAudioConfig{AudioEncoding=AudioEncoding.Linear16,SampleRateHertz=16000,});varaudio=StripWavHeader(tts.AudioContent!);// Stream it back through MEAI. The WebSocket connect pulls a fresh// token from the cache under the hood.Meai.ISpeechToTextClientspeech=client;usingvaraudioStream=newMemoryStream(audio);vartranscriptBuilder=newSystem.Text.StringBuilder();awaitforeach(varupdateinspeech.GetStreamingTextAsync(audioStream,newMeai.SpeechToTextOptions{ModelId="assemblyai/universal-streaming-multilingual",SpeechLanguage="en-US",},CancellationToken.None)){if(update.Kind==Meai.SpeechToTextResponseUpdateKind.TextUpdated){transcriptBuilder.Append(update.Text);}if(update.Kind==Meai.SpeechToTextResponseUpdateKind.SessionClose){break;}}because:"streaming STT via JwtCache-backed auth should still return a transcript");