@@ -186,33 +186,39 @@ print(response.model_dump_json(indent=2))
186186# [ C#] ( #tab/csharp )
187187
188188``` c#
189- using Azure .AI .OpenAI ;
190- using Azure .AI .OpenAI .Chat ;
191189using Azure .Identity ;
190+ using OpenAI ;
192191using OpenAI .Chat ;
192+ using System .ClientModel .Primitives ;
193193
194- AzureOpenAIClient openAIClient = new (
195- new Uri (" https://YOUR-RESOURCE-NAME.openai.azure.com/" ),
196- new DefaultAzureCredential ());
197- ChatClient chatClient = openAIClient .GetChatClient (" o3-mini" ); // model deployment name
194+ #pragma warning disable OPENAI001 // currently required for token based authentication
195+
196+ BearerTokenPolicy tokenPolicy = new (
197+ new DefaultAzureCredential (),
198+ " https://cognitiveservices.azure.com/.default" );
199+
200+ ChatClient client = new (
201+ model : " o4-mini" ,
202+ authenticationPolicy : tokenPolicy ,
203+ options : new OpenAIClientOptions ()
204+ {
205+
206+ Endpoint = new Uri (" https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1" )
207+ }
208+ );
198209
199210ChatCompletionOptions options = new ChatCompletionOptions
200211{
201212 MaxOutputTokenCount = 100000
202213};
203214
204- #pragma warning disable AOAI001 // currently required to use MaxOutputTokenCount
215+ ChatCompletion completion = client .CompleteChat (
216+ new DeveloperChatMessage (" You are a helpful assistant" ),
217+ new UserChatMessage (" Tell me about the bitter lesson" )
218+ );
205219
206- options . SetNewMaxCompletionTokensPropertyEnabled ( true );
220+ Console . WriteLine ( $" [ASSISTANT]: { completion . Content [ 0 ]. Text } " );
207221
208- ChatCompletion completion = chatClient .CompleteChat (
209- [
210-
211- new UserChatMessage (" Testing 1,2,3" )
212- ],
213- options ); // Pass the options to the CompleteChat method
214-
215- Console .WriteLine ($" {completion .Role }: {completion .Content [0 ].Text }" );
216222```
217223
218224---
@@ -395,34 +401,41 @@ print(response.model_dump_json(indent=2))
395401# [ C#] ( #tab/csharp )
396402
397403``` csharp
398- using Azure .AI .OpenAI ;
399- using Azure .AI .OpenAI .Chat ;
404+
400405using Azure .Identity ;
406+ using OpenAI ;
401407using OpenAI .Chat ;
408+ using System .ClientModel .Primitives ;
402409
403- AzureOpenAIClient openAIClient = new (
404- new Uri (" https://YOUR-RESOURCE-NAME.openai.azure.com/" ),
405- new DefaultAzureCredential ());
406- ChatClient chatClient = openAIClient .GetChatClient (" o3-mini" ); // model deployment name
410+ #pragma warning disable OPENAI001 // currently required for token based authentication
411+
412+ BearerTokenPolicy tokenPolicy = new (
413+ new DefaultAzureCredential (),
414+ " https://cognitiveservices.azure.com/.default" );
415+
416+ ChatClient client = new (
417+ model : " o4-mini" ,
418+ authenticationPolicy : tokenPolicy ,
419+ options : new OpenAIClientOptions ()
420+ {
421+
422+ Endpoint = new Uri (" https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1" )
423+ }
424+ );
407425
408426ChatCompletionOptions options = new ChatCompletionOptions
409427{
410428 ReasoningEffortLevel = ChatReasoningEffortLevel .Low ,
411429 MaxOutputTokenCount = 100000
412430};
413431
414- #pragma warning disable AOAI001 // currently required to use MaxOutputTokenCount
415-
416- options .SetNewMaxCompletionTokensPropertyEnabled (true );
432+ ChatCompletion completion = client .CompleteChat (
433+ new DeveloperChatMessage (" You are a helpful assistant" ),
434+ new UserChatMessage (" Tell me about the bitter lesson" )
435+ );
417436
418- ChatCompletion completion = chatClient .CompleteChat (
419- [
420- new DeveloperChatMessage (" You are a helpful assistant." ),
421- new UserChatMessage (" Testing 1,2,3" )
422- ],
423- options ); // Pass the options to the CompleteChat method
437+ Console .WriteLine ($" [ASSISTANT]: {completion .Content [0 ].Text }" );
424438
425- Console .WriteLine ($" {completion .Role }: {completion .Content [0 ].Text }" );
426439```
427440
428441---
@@ -443,17 +456,12 @@ pip install openai --upgrade
443456```
444457
445458``` python
446- from openai import AzureOpenAI
447- from azure.identity import DefaultAzureCredential, get_bearer_token_provider
448-
449- token_provider = get_bearer_token_provider(
450- DefaultAzureCredential(), " https://cognitiveservices.azure.com/.default"
451- )
459+ import os
460+ from openai import OpenAI
452461
453- client = AzureOpenAI(
454- base_url = " https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/" ,
455- azure_ad_token_provider = token_provider,
456- api_version = " preview"
462+ client = OpenAI(
463+ base_url = " https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/" ,
464+ api_key = os.getenv(" AZURE_OPENAI_API_KEY" )
457465)
458466
459467response = client.responses.create(
@@ -474,7 +482,7 @@ print(response.model_dump_json(indent=2))
474482# [ REST] ( #tab/REST )
475483
476484``` bash
477- curl -X POST " https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/responses?api-version=preview " \
485+ curl -X POST " https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/responses" \
478486 -H " Content-Type: application/json" \
479487 -H " Authorization: Bearer $AZURE_OPENAI_AUTH_TOKEN " \
480488 -d ' {
@@ -589,17 +597,12 @@ GPT-5 series reasoning models have the ability to call a new `custom_tool` calle
589597```
590598
591599``` python
592- from openai import AzureOpenAI
593- from azure.identity import DefaultAzureCredential, get_bearer_token_provider
594-
595- token_provider = get_bearer_token_provider(
596- DefaultAzureCredential(), " https://cognitiveservices.azure.com/.default"
597- )
600+ import os
601+ from openai import OpenAI
598602
599- client = AzureOpenAI(
600- base_url = " https://YOUR-RESOURCE-NAME-HERE.openai.azure.com/openai/v1/" ,
601- azure_ad_token_provider = token_provider,
602- api_version = " preview"
603+ client = OpenAI(
604+ base_url = " https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/" ,
605+ api_key = os.getenv(" AZURE_OPENAI_API_KEY" )
603606)
604607
605608response = client.responses.create(
0 commit comments