@@ -270,6 +270,46 @@ This library throws exceptions in a single hierarchy for easy handling:
270270    -  We failed to serialize the request body
271271    -  We failed to parse the response body (has access to response code and body)
272272
273+ ## Microsoft Azure OpenAI  
274+ 
275+ To use this library with [ Azure OpenAI] ( https://learn.microsoft.com/azure/ai-services/openai/overview ) , use the same 
276+ OpenAI client builder but with the Azure-specific configuration. 
277+ 
278+ ``` java 
279+ OpenAIOkHttpClient . Builder  clientBuilder =  OpenAIOkHttpClient . builder();
280+ 
281+ /*  Azure-specific code starts here */ 
282+ //  You can either set 'endpoint' directly in the builder.
283+ //  or set the env var "AZURE_OPENAI_ENDPOINT" and use fromEnv() method instead
284+ clientBuilder
285+     .baseUrl(System . getenv(" AZURE_OPENAI_ENDPOINT"  ))
286+     .credential(BearerTokenCredential . create(
287+         AuthenticationUtil . getBearerTokenSupplier(
288+             new  DefaultAzureCredentialBuilder (). build(), " https://cognitiveservices.azure.com/.default"  )
289+     ));
290+ /*  Azure-specific code ends here */ 
291+ 
292+ OpenAIClient  client =  clientBuilder. build();
293+ 
294+ ChatCompletionCreateParams  params =  ChatCompletionCreateParams . builder()
295+     .addMessage(ChatCompletionMessageParam . ofChatCompletionUserMessageParam(
296+         ChatCompletionUserMessageParam . builder()
297+             .role(ChatCompletionUserMessageParam . Role . USER )
298+             .content(ChatCompletionUserMessageParam . Content . ofTextContent(" Who won the world series in 2020?"  ))
299+             .build()))
300+     .model(" gpt-4o"  )
301+     .build();
302+ 
303+ ChatCompletion  chatCompletion =  client. chat(). completions(). create(params);
304+ 
305+ List<ChatCompletion . Choice >  choices =  chatCompletion. choices();
306+ for  (ChatCompletion . Choice  choice :  choices) {
307+     System . out. println(" Choice content: "   +  choice. message(). content(). get());
308+ }
309+ ``` 
310+ 
311+ See the complete Azure OpenAI examples in the [ Azure OpenAI example] ( https://github.com/openai/openai-java/tree/next/openai-azure-java-example/src/main/java/com.openai.azure.examples ) .
312+ 
273313## Network options  
274314
275315### Retries  
0 commit comments