Azure OpenAI Chat Models
Azure OpenAI is a managed service provided by Microsoft that gives developers access to OpenAI’s Large Language Models (LLMs) via the Azure cloud platform.
It supports multiple chat models—specialized LLMs designed for conversational tasks such as virtual assistants, interactive applications, and customer-facing chatbots.
Azure OpenAI uses the same REST-compatible API as OpenAI itself. This means the same Quarkus LangChain4j code can target either OpenAI or Azure OpenAI. The main difference lies in the configuration: Azure requires additional parameters related to its deployment structure and authentication model.
Prerequisites
Azure OpenAI Account and API Key
To use Azure OpenAI models in your Quarkus application, configure your Azure credentials and endpoint.
-
Obtain your Azure OpenAI endpoint, resource name, deployment name, and either an api-key or an Azure AD access token from the Azure Portal.
-
Configure your application.properties with the necessary details:
quarkus.langchain4j.azure-openai.resource-name=
quarkus.langchain4j.azure-openai.deployment-name=
# And one of the below depending on your scenario
quarkus.langchain4j.azure-openai.api-key=
quarkus.langchain4j.azure-openai.ad-token=
Azure OpenAI Quarkus Extension
Add the quarkus-langchain4j-azure-openai
extension to your project:
<dependency>
<groupId>io.quarkiverse.langchain4j</groupId>
<artifactId>quarkus-langchain4j-azure-openai</artifactId>
<version>1.0.2</version>
</dependency>
If no other LLM extension is present, AI Services will automatically use the configured Azure OpenAI chat model.
This extension also includes:
Unlike the OpenAI extension, Azure OpenAI does not currently support moderation models. |
Configuration
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Configuration property |
Type |
Default |
---|---|---|
Whether the model should be enabled Environment variable: |
boolean |
|
Whether the model should be enabled Environment variable: |
boolean |
|
Whether the model should be enabled Environment variable: |
boolean |
|
Whether the model should be enabled Environment variable: |
boolean |
|
The name of your Azure OpenAI Resource. You’re required to first deploy a model before you can make calls. This and Environment variable: |
string |
|
The domain name of your Azure OpenAI Resource. You’re required to first deploy a model before you can make calls. This and Environment variable: |
string |
|
The name of your model deployment. You’re required to first deploy a model before you can make calls. This and Environment variable: |
string |
|
The endpoint for the Azure OpenAI resource. If not specified, then Environment variable: |
string |
|
The Azure AD token to use for this operation. If present, then the requests towards OpenAI will include this in the Authorization header. Note that this property overrides the functionality of Environment variable: |
string |
|
The API version to use for this operation. This follows the YYYY-MM-DD format Environment variable: |
string |
|
Azure OpenAI API key Environment variable: |
string |
|
Timeout for OpenAI calls Environment variable: |
|
|
The maximum number of times to retry. 1 means exactly one attempt, with retrying disabled. Environment variable: |
int |
|
Whether the OpenAI client should log requests Environment variable: |
boolean |
|
Whether the OpenAI client should log responses Environment variable: |
boolean |
|
Whether to enable the integration. Defaults to Environment variable: |
boolean |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
The Azure AD token to use for this operation. If present, then the requests towards OpenAI will include this in the Authorization header. Note that this property overrides the functionality of Environment variable: |
string |
|
The API version to use for this operation. This follows the YYYY-MM-DD format Environment variable: |
string |
|
Azure OpenAI API key Environment variable: |
string |
|
What sampling temperature to use, with values between 0 and 2. Higher values means the model will take more risks. A value of 0.9 is good for more creative applications, while 0 (argmax sampling) is good for ones with a well-defined answer. It is recommended to alter this or topP, but not both. Environment variable: |
double |
|
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with topP probability mass. 0.1 means only the tokens comprising the top 10% probability mass are considered. It is recommended to alter this or temperature, but not both. Environment variable: |
double |
|
The maximum number of tokens to generate in the completion. The token count of your prompt plus max_tokens can’t exceed the model’s context length. Most models have a context length of 2048 tokens (except for the newest models, which support 4096). Environment variable: |
int |
|
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model’s likelihood to talk about new topics. Environment variable: |
double |
|
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model’s likelihood to repeat the same line verbatim. Environment variable: |
double |
|
Whether chat model requests should be logged Environment variable: |
boolean |
|
Whether chat model responses should be logged Environment variable: |
boolean |
|
The response format the model should use. Some models are not compatible with some response formats, make sure to review OpenAI documentation. Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
The Azure AD token to use for this operation. If present, then the requests towards OpenAI will include this in the Authorization header. Note that this property overrides the functionality of Environment variable: |
string |
|
The API version to use for this operation. This follows the YYYY-MM-DD format Environment variable: |
string |
|
Azure OpenAI API key Environment variable: |
string |
|
Whether embedding model requests should be logged Environment variable: |
boolean |
|
Whether embedding model responses should be logged Environment variable: |
boolean |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
The Azure AD token to use for this operation. If present, then the requests towards OpenAI will include this in the Authorization header. Note that this property overrides the functionality of Environment variable: |
string |
|
The API version to use for this operation. This follows the YYYY-MM-DD format Environment variable: |
string |
|
Azure OpenAI API key Environment variable: |
string |
|
Model name to use Environment variable: |
string |
|
Configure whether the generated images will be saved to disk. By default, persisting is disabled, but it is implicitly enabled when Environment variable: |
boolean |
|
The path where the generated images will be persisted to disk. This only applies of Environment variable: |
path |
|
The format in which the generated images are returned. Must be one of Environment variable: |
string |
|
The size of the generated images. Must be one of Must be one of Environment variable: |
string |
|
The quality of the image that will be generated.
This param is only supported for when the model is Environment variable: |
string |
|
The number of images to generate. Must be between 1 and 10. When the model is dall-e-3, only n=1 is supported. Environment variable: |
int |
|
The style of the generated images. Must be one of This param is only supported for when the model is Environment variable: |
string |
|
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Environment variable: |
string |
|
Whether image model requests should be logged Environment variable: |
boolean |
|
Whether image model responses should be logged Environment variable: |
boolean |
|
Type |
Default |
|
The name of your Azure OpenAI Resource. You’re required to first deploy a model before you can make calls. This and Environment variable: |
string |
|
The domain name of your Azure OpenAI Resource. You’re required to first deploy a model before you can make calls. This and Environment variable: |
string |
|
The name of your model deployment. You’re required to first deploy a model before you can make calls. This and Environment variable: |
string |
|
The endpoint for the Azure OpenAI resource. If not specified, then Environment variable: |
string |
|
The Azure AD token to use for this operation. If present, then the requests towards OpenAI will include this in the Authorization header. Note that this property overrides the functionality of Environment variable: |
string |
|
The API version to use for this operation. This follows the YYYY-MM-DD format Environment variable: |
string |
|
Azure OpenAI API key Environment variable: |
string |
|
Timeout for OpenAI calls Environment variable: |
|
|
The maximum number of times to retry. 1 means exactly one attempt, with retrying disabled. Environment variable: |
int |
|
Whether the OpenAI client should log requests Environment variable: |
boolean |
|
Whether the OpenAI client should log responses Environment variable: |
boolean |
|
Whether to enable the integration. Defaults to Environment variable: |
boolean |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
The Azure AD token to use for this operation. If present, then the requests towards OpenAI will include this in the Authorization header. Note that this property overrides the functionality of Environment variable: |
string |
|
The API version to use for this operation. This follows the YYYY-MM-DD format Environment variable: |
string |
|
Azure OpenAI API key Environment variable: |
string |
|
What sampling temperature to use, with values between 0 and 2. Higher values means the model will take more risks. A value of 0.9 is good for more creative applications, while 0 (argmax sampling) is good for ones with a well-defined answer. It is recommended to alter this or topP, but not both. Environment variable: |
double |
|
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with topP probability mass. 0.1 means only the tokens comprising the top 10% probability mass are considered. It is recommended to alter this or temperature, but not both. Environment variable: |
double |
|
The maximum number of tokens to generate in the completion. The token count of your prompt plus max_tokens can’t exceed the model’s context length. Most models have a context length of 2048 tokens (except for the newest models, which support 4096). Environment variable: |
int |
|
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model’s likelihood to talk about new topics. Environment variable: |
double |
|
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model’s likelihood to repeat the same line verbatim. Environment variable: |
double |
|
Whether chat model requests should be logged Environment variable: |
boolean |
|
Whether chat model responses should be logged Environment variable: |
boolean |
|
The response format the model should use. Some models are not compatible with some response formats, make sure to review OpenAI documentation. Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
The Azure AD token to use for this operation. If present, then the requests towards OpenAI will include this in the Authorization header. Note that this property overrides the functionality of Environment variable: |
string |
|
The API version to use for this operation. This follows the YYYY-MM-DD format Environment variable: |
string |
|
Azure OpenAI API key Environment variable: |
string |
|
Whether embedding model requests should be logged Environment variable: |
boolean |
|
Whether embedding model responses should be logged Environment variable: |
boolean |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
This property will override the Environment variable: |
string |
|
The Azure AD token to use for this operation. If present, then the requests towards OpenAI will include this in the Authorization header. Note that this property overrides the functionality of Environment variable: |
string |
|
The API version to use for this operation. This follows the YYYY-MM-DD format Environment variable: |
string |
|
Azure OpenAI API key Environment variable: |
string |
|
Model name to use Environment variable: |
string |
|
Configure whether the generated images will be saved to disk. By default, persisting is disabled, but it is implicitly enabled when Environment variable: |
boolean |
|
The path where the generated images will be persisted to disk. This only applies of Environment variable: |
path |
|
The format in which the generated images are returned. Must be one of Environment variable: |
string |
|
The size of the generated images. Must be one of Must be one of Environment variable: |
string |
|
The quality of the image that will be generated.
This param is only supported for when the model is Environment variable: |
string |
|
The number of images to generate. Must be between 1 and 10. When the model is dall-e-3, only n=1 is supported. Environment variable: |
int |
|
The style of the generated images. Must be one of This param is only supported for when the model is Environment variable: |
string |
|
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Environment variable: |
string |
|
Whether image model requests should be logged Environment variable: |
boolean |
|
Whether image model responses should be logged Environment variable: |
boolean |
|
About the Duration format
To write duration values, use the standard You can also use a simplified format, starting with a number:
In other cases, the simplified format is translated to the
|
You can define multiple Azure OpenAI model configurations by using different prefixes:
# Default Azure OpenAI model configuration
quarkus.langchain4j.azure-openai.chat-model.temperature=0
# Custom Azure OpenAI model configuration
quarkus.langchain4j.azure-openai.some-name.chat-model.temperature=0.8
To use a specific model in an AI service, set the modelName
in the @RegisterAiService
annotation:
import io.quarkiverse.langchain4j.RegisterAiService;
@RegisterAiService(modelName = "some-name")
public interface MyService {
// ...
}
If modelName
is omitted, the default configuration is used.
You can also select a model programmatically using the @ModelName
qualifier:
import dev.langchain4j.model.chat.ChatModel;
import io.quarkiverse.langchain4j.ModelName;
import jakarta.inject.Inject;
// ...
@Inject @ModelName("some-name") ChatModel chatModel;