@@ -36,7 +36,7 @@ var messages = new Chat()
3636 { " user" , " What is 101*3?" },
3737};
3838
39- var grok = new GrokChatClient (Env . Get (" XAI_API_KEY" )! , " grok-3-mini" );
39+ var grok = new GrokChatClient (Environment . GetEnvironmentVariable (" XAI_API_KEY" )! , " grok-3-mini" );
4040
4141var options = new GrokChatOptions
4242{
@@ -49,12 +49,6 @@ var options = new GrokChatOptions
4949var response = await grok .GetResponseAsync (messages , options );
5050```
5151
52- > [ !TIP]
53- > ` Env ` is a helper class from [ Smith] ( https://www.nuget.org/packages/Smith ) ,
54- > a higher level package typically used for ` dotnet run program.cs ` scenarios in
55- > .NET 10. You will typically use ` IConfiguration ` for reading API keys.
56- > This package does not depend on Smith.
57-
5852Search can alternatively be configured using a regular ` ChatOptions `
5953and adding the ` HostedWebSearchTool ` to the tools collection, which
6054sets the live search mode to ` auto ` like above:
@@ -66,7 +60,7 @@ var messages = new Chat()
6660 { " user" , " What's Tesla stock worth today? Search X and the news for latest info." },
6761};
6862
69- var grok = new GrokChatClient (Env . Get (" XAI_API_KEY" )! , " grok-3" );
63+ var grok = new GrokChatClient (Environment . GetEnvironmentVariable (" XAI_API_KEY" )! , " grok-3" );
7064
7165var options = new ChatOptions
7266{
@@ -151,7 +145,7 @@ var messages = new Chat()
151145 { " user" , " What is 101*3?" },
152146};
153147
154- IChatClient chat = new OpenAIChatClient (Env . Get (" OPENAI_API_KEY" )! , " gpt-5" );
148+ IChatClient chat = new OpenAIChatClient (Environment . GetEnvironmentVariable (" OPENAI_API_KEY" )! , " gpt-5" );
155149
156150var options = new ChatOptions
157151{
@@ -204,7 +198,7 @@ This is added to the `OpenAIClientOptions` (or more properly, any
204198
205199``` csharp
206200var openai = new OpenAIClient (
207- Env . Get (" OPENAI_API_KEY" )! ,
201+ Environment . GetEnvironmentVariable (" OPENAI_API_KEY" )! ,
208202 new OpenAIClientOptions ().Observe (
209203 onRequest : request => Console .WriteLine ($" Request: {request }" ),
210204 onResponse : response => Console .WriteLine ($" Response: {response }" ),
@@ -218,7 +212,7 @@ payload analysis in tests as follows:
218212var requests = new List <JsonNode >();
219213var responses = new List <JsonNode >();
220214var openai = new OpenAIClient (
221- Env . Get (" OPENAI_API_KEY" )! ,
215+ Environment . GetEnvironmentVariable (" OPENAI_API_KEY" )! ,
222216 new OpenAIClientOptions ().Observe (requests .Add , responses .Add ));
223217```
224218
@@ -229,7 +223,7 @@ and observes is in a single call:
229223var requests = new List <JsonNode >();
230224var responses = new List <JsonNode >();
231225var openai = new OpenAIClient (
232- Env . Get (" OPENAI_API_KEY" )! ,
226+ Environment . GetEnvironmentVariable (" OPENAI_API_KEY" )! ,
233227 OpenAIClientOptions .Observable (requests .Add , responses .Add ));
234228```
235229
@@ -306,7 +300,7 @@ client options passed to the client constructor:
306300
307301``` csharp
308302var openai = new OpenAIClient (
309- Env . Get (" OPENAI_API_KEY" )! ,
303+ Environment . GetEnvironmentVariable (" OPENAI_API_KEY" )! ,
310304 new OpenAIClientOptions ().UseJsonConsoleLogging ());
311305```
312306
@@ -321,7 +315,7 @@ and more.
321315The chat pipeline logging is added similar to other pipeline extensions:
322316
323317``` csharp
324- IChatClient client = new GrokChatClient (Env . Get (" XAI_API_KEY" )! , " grok-3-mini" )
318+ IChatClient client = new GrokChatClient (Environment . GetEnvironmentVariable (" XAI_API_KEY" )! , " grok-3-mini" )
325319 .AsBuilder ()
326320 .UseOpenTelemetry ()
327321 // other extensions...
0 commit comments