OpenAI Chat Models

OpenAI is a leading AI research organization known for its groundbreaking Large Language Models (LLMs) like GPT-4.

It provides various chat models, which are specialized LLMs designed for conversational tasks such as chatbots, virtual assistants, and interactive applications. These models also support advanced capabilities like reasoning and function calling.

This extension can be used with any provider that supports OpenAI-compatible APIs, including OpenAI itself, OpenShift AI, and others. If you’re using a provider other than OpenAI, ensure that the authentication and endpoint configuration are set up accordingly.

Prerequisites

OpenAI Account and API Key

To use OpenAI models in your Quarkus application:

  1. Create an OpenAI account.

  2. Generate an API key from the API Keys page.

  3. Add the following to your application.properties:

    quarkus.langchain4j.openai.api-key=sk-...
Use environment variables

You can use the environment variable QUARKUS_LANGCHAIN4J_OPENAI_API_KEY instead of hardcoding the key in your properties file.

Using configuration placeholders

You can also reference an environment variable directly in your properties file:

quarkus.langchain4j.openai.api-key=${OPENAI_API_KEY}

OpenAI Quarkus Extension

To enable OpenAI chat model support, add the following dependency to your pom.xml:

<dependency>
  <groupId>io.quarkiverse.langchain4j</groupId>
  <artifactId>quarkus-langchain4j-openai</artifactId>
  <version>1.15.0.CR2</version>
</dependency>

Even better, if you use the Quarkus platform BOM (default for projects generated), add the Quarkus Langchain4J BOM and all dependency versions will align:

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>${quarkus.platform.group-id}</groupId>
                <artifactId>${quarkus.platform.artifact-id}</artifactId>
                <version>${quarkus.platform.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>${quarkus.platform.group-id}</groupId>
                <artifactId>quarkus-langchain4j-bom</artifactId> (1)
                <version>${quarkus.platform.version}</version> (2)
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
      <dependency>
        <groupId>io.quarkiverse.langchain4j</groupId>
        <artifactId>quarkus-langchain4j-openai</artifactId>
        (3)
      </dependency>
    </dependencies>
1 In your dependencyManagement section, add the quarkus-langchain4j-bom
2 Inherit the version from your platform version
3 Voilà, no need for version alignment anymore

This extension also provides:

  • EmbeddingModel support for computing document embeddings

  • ModerationModel for content filtering

  • ImageModel for image generation

These are enabled by default and can be configured separately.

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: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_ENABLED

boolean

true

Whether the model should be enabled

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_EMBEDDING_MODEL_ENABLED

boolean

true

Whether the model should be enabled

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_MODERATION_MODEL_ENABLED

boolean

true

Whether the model should be enabled

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_IMAGE_MODEL_ENABLED

boolean

true

Whether the model should be enabled

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_AUDIO_TRANSCRIPTION_MODEL_ENABLED

boolean

true

Whether the model should be enabled

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_DECISION_MODEL_ENABLED

boolean

true

Base URL of OpenAI API

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_BASE_URL

string

https://api.openai.com/v1/

If set, the named TLS configuration with the configured name will be applied to the REST Client

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_TLS_CONFIGURATION_NAME

string

OpenAI API key

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_API_KEY

string

dummy

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_ORGANIZATION_ID

string

Timeout for OpenAI calls

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_TIMEOUT

Duration 

10s

The maximum number of times to retry. 1 means exactly one attempt, with retrying disabled.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_MAX_RETRIES

int

1

Whether the OpenAI client should log requests

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_LOG_REQUESTS

boolean

false

Whether the OpenAI client should log responses

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_LOG_RESPONSES

boolean

false

Whether the OpenAI client should log requests as cURL commands

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_LOG_REQUESTS_CURL

boolean

false

Whether to enable the integration. Defaults to true, which means requests are made to the OpenAI provider. Set to false to disable all requests.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_ENABLE_INTEGRATION

boolean

true

Proxy configuration name.

There are some rules for using Quarkus Proxy Registry configuration:

  • If quarkus.langchain4j.openai.proxy-configuration-name is set, it takes precedence over proxy-host configuration.

  • If not set and the default proxy configuration is configured (quarkus.proxy.*) then that will be used.

  • If the proxy configuration name is set, the configuration from quarkus.proxy.<name>.* will be used.

  • If the proxy configuration name is set, but no proxy configuration is found with that name, then an error will be thrown at runtime.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_PROXY_CONFIGURATION_NAME

string

Which OpenAI API the chat model should target.

chat-completion uses the /v1/chat/completions endpoint, while responses uses the newer /v1/responses endpoint. The responses mode is required for models that are only available through the Responses API, is the only way to use tools (function calling) with GPT-6 models when reasoning is enabled, and unlocks Responses-specific settings under quarkus.langchain4j.openai.chat-model.responses.*.

When not set, the mode is selected automatically: responses if the base URL is the OpenAI API (https://api.openai.com/v1/), otherwise chat-completion, which is what OpenAI-compatible endpoints (Ollama, vLLM, LM Studio, …​) implement. The resolved mode is logged at startup.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_MODE

chat-completion, responses

auto

Model name to use

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_MODEL_NAME

string

gpt-6-luna

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.

If not set, the parameter is omitted from the request and the model’s own default applies.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_TEMPERATURE

double

the model's default

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.

If not set, the parameter is omitted from the request and the model’s own default applies.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_TOP_P

double

the model's default

An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_MAX_COMPLETION_TOKENS

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: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_PRESENCE_PENALTY

double

0

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: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_FREQUENCY_PENALTY

double

0

Whether chat model requests should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_LOG_REQUESTS

boolean

false

Whether chat model responses should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_LOG_RESPONSES

boolean

false

The response format the model should use. Some models are not compatible with some response formats, make sure to review OpenAI documentation.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_RESPONSE_FORMAT

string

Whether responses follow JSON Schema for Structured Outputs

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_STRICT_JSON_SCHEMA

boolean

The list of stop words to use.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_STOP

list of string

Constrains effort on reasoning for reasoning models. Currently supported values are minimal, low, medium, and high. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.

Note: The gpt-5-pro model defaults to (and only supports) high reasoning effort.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_REASONING_EFFORT

string

Specifies the processing type used for serving the request.

If set to auto, then the request will be processed with the service tier configured in the Project settings. If set to default, then the request will be processed with the standard pricing and performance for the selected model. If set to flex or priority, then the request will be processed with the corresponding service tier. When not set, the default behavior is auto.

When the service tier parameter is set, the response body will include the service_tier value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_SERVICE_TIER

string

default

Whether to store the generated model response for later retrieval via the Responses API.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_RESPONSES_STORE

boolean

The unique ID of the previous response to the model, used to create multi-turn conversations.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_RESPONSES_PREVIOUS_RESPONSE_ID

string

A summary of the reasoning performed by the model, for reasoning models. Supported values are auto, concise, and detailed.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_RESPONSES_REASONING_SUMMARY

string

An upper bound for the number of tokens that can be generated for a response, including visible output tokens and reasoning tokens.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_RESPONSES_MAX_OUTPUT_TOKENS

int

The maximum number of total calls to built-in tools that can be processed in a response.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_RESPONSES_MAX_TOOL_CALLS

int

Whether to allow the model to run tool calls in parallel.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_RESPONSES_PARALLEL_TOOL_CALLS

boolean

Additional output data to include in the model response.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_RESPONSES_INCLUDE

list of string

The truncation strategy to use for the model response. Supported values are auto and disabled.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_RESPONSES_TRUNCATION

string

Constrains the verbosity of the model’s response. Supported values are low, medium, and high.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_RESPONSES_TEXT_VERBOSITY

string

Used by OpenAI to cache responses for similar requests to optimize your cache hit rates.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_RESPONSES_PROMPT_CACHE_KEY

string

The retention policy for the prompt cache.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_RESPONSES_PROMPT_CACHE_RETENTION

string

A stable identifier used to help detect users of your application that may be violating OpenAI’s usage policies.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_RESPONSES_SAFETY_IDENTIFIER

string

The number of most likely tokens to return at each token position, each with an associated log probability.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_RESPONSES_TOP_LOGPROBS

int

Whether to enforce strict schema validation on tool/function definitions.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_RESPONSES_STRICT_TOOLS

boolean

Whether obfuscation fields should be included in streaming events. Only applies to the streaming chat model.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_RESPONSES_STREAM_INCLUDE_OBFUSCATION

boolean

Model name to use

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_EMBEDDING_MODEL_MODEL_NAME

string

text-embedding-ada-002

Whether embedding model requests should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_EMBEDDING_MODEL_LOG_REQUESTS

boolean

false

Whether embedding model responses should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_EMBEDDING_MODEL_LOG_RESPONSES

boolean

false

A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_EMBEDDING_MODEL_USER

string

Model name to use

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_MODERATION_MODEL_MODEL_NAME

string

omni-moderation-latest

Whether moderation model requests should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_MODERATION_MODEL_LOG_REQUESTS

boolean

false

Whether moderation model responses should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_MODERATION_MODEL_LOG_RESPONSES

boolean

false

Model name to use

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_IMAGE_MODEL_MODEL_NAME

string

gpt-image-1

Configure whether the generated images will be saved to disk. By default, persisting is disabled, but it is implicitly enabled when quarkus.langchain4j.openai.image-mode.directory is set and this property is not to false

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_IMAGE_MODEL_PERSIST

boolean

false

The path where the generated images will be persisted to disk. This only applies of quarkus.langchain4j.openai.image-mode.persist is not set to false.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_IMAGE_MODEL_PERSIST_DIRECTORY

path

${java.io.tmpdir}/openai-images

The size of the generated images.

Supported values: 1024x1024, 1536x1024, 1024x1536, or auto.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_IMAGE_MODEL_SIZE

string

1024x1024

The quality of the image that will be generated.

Supported values: auto, low, medium, or high.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_IMAGE_MODEL_QUALITY

string

auto

The number of images to generate.

Must be between 1 and 10.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_IMAGE_MODEL_NUMBER

int

1

A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_IMAGE_MODEL_USER

string

The output format of the generated image.

Supported values: png, jpeg, webp.

Only supported for gpt-image-1 and newer models.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_IMAGE_MODEL_OUTPUT_FORMAT

string

The background type for the generated image.

Supported values: transparent, opaque, auto.

Only supported for gpt-image-1 and newer models. Transparent backgrounds require output-format set to png or webp.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_IMAGE_MODEL_BACKGROUND

string

The compression level for the generated image (0-100).

Only supported for gpt-image-1 and newer models with jpeg or webp output formats.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_IMAGE_MODEL_OUTPUT_COMPRESSION

int

The moderation level for the image generation request.

Supported values: low, auto.

Only supported for gpt-image-1 and newer models.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_IMAGE_MODEL_MODERATION

string

Whether image model requests should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_IMAGE_MODEL_LOG_REQUESTS

boolean

false

Whether image model responses should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_IMAGE_MODEL_LOG_RESPONSES

boolean

false

Model name to use

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_AUDIO_TRANSCRIPTION_MODEL_MODEL_NAME

string

whisper-1

Whether audio transcription model requests should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_AUDIO_TRANSCRIPTION_MODEL_LOG_REQUESTS

boolean

false

Whether audio transcription model responses should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_AUDIO_TRANSCRIPTION_MODEL_LOG_RESPONSES

boolean

false

Model name to use

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_DECISION_MODEL_MODEL_NAME

string

gpt-6-luna

Whether decision model requests should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_DECISION_MODEL_LOG_REQUESTS

boolean

false

Whether decision model responses should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_DECISION_MODEL_LOG_RESPONSES

boolean

false

This property is deprecated: Use quarkus.langchain4j.openai.proxy-configuration-name instead.

The Proxy type

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_PROXY_TYPE

string

HTTP

This property is deprecated: Use quarkus.langchain4j.openai.proxy-configuration-name instead.

The Proxy host

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_PROXY_HOST

string

This property is deprecated: Use quarkus.langchain4j.openai.proxy-configuration-name instead.

The Proxy port

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI_PROXY_PORT

int

3128

This property is deprecated: For newer OpenAI models, use maxCompletionTokens instead.

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: QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_MAX_TOKENS

int

Named model config

Type

Default

Whether the model should be enabled

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_ENABLED

boolean

true

Whether the model should be enabled

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__EMBEDDING_MODEL_ENABLED

boolean

true

Whether the model should be enabled

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__MODERATION_MODEL_ENABLED

boolean

true

Whether the model should be enabled

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__IMAGE_MODEL_ENABLED

boolean

true

Whether the model should be enabled

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__AUDIO_TRANSCRIPTION_MODEL_ENABLED

boolean

true

Whether the model should be enabled

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__DECISION_MODEL_ENABLED

boolean

true

Base URL of OpenAI API

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__BASE_URL

string

https://api.openai.com/v1/

If set, the named TLS configuration with the configured name will be applied to the REST Client

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__TLS_CONFIGURATION_NAME

string

OpenAI API key

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__API_KEY

string

dummy

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__ORGANIZATION_ID

string

Timeout for OpenAI calls

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__TIMEOUT

Duration 

10s

The maximum number of times to retry. 1 means exactly one attempt, with retrying disabled.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__MAX_RETRIES

int

1

Whether the OpenAI client should log requests

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__LOG_REQUESTS

boolean

false

Whether the OpenAI client should log responses

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__LOG_RESPONSES

boolean

false

Whether the OpenAI client should log requests as cURL commands

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__LOG_REQUESTS_CURL

boolean

false

Whether to enable the integration. Defaults to true, which means requests are made to the OpenAI provider. Set to false to disable all requests.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__ENABLE_INTEGRATION

boolean

true

Proxy configuration name.

There are some rules for using Quarkus Proxy Registry configuration:

  • If quarkus.langchain4j.openai.proxy-configuration-name is set, it takes precedence over proxy-host configuration.

  • If not set and the default proxy configuration is configured (quarkus.proxy.*) then that will be used.

  • If the proxy configuration name is set, the configuration from quarkus.proxy.<name>.* will be used.

  • If the proxy configuration name is set, but no proxy configuration is found with that name, then an error will be thrown at runtime.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__PROXY_CONFIGURATION_NAME

string

Which OpenAI API the chat model should target.

chat-completion uses the /v1/chat/completions endpoint, while responses uses the newer /v1/responses endpoint. The responses mode is required for models that are only available through the Responses API, is the only way to use tools (function calling) with GPT-6 models when reasoning is enabled, and unlocks Responses-specific settings under quarkus.langchain4j.openai.chat-model.responses.*.

When not set, the mode is selected automatically: responses if the base URL is the OpenAI API (https://api.openai.com/v1/), otherwise chat-completion, which is what OpenAI-compatible endpoints (Ollama, vLLM, LM Studio, …​) implement. The resolved mode is logged at startup.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_MODE

chat-completion, responses

auto

Model name to use

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_MODEL_NAME

string

gpt-6-luna

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.

If not set, the parameter is omitted from the request and the model’s own default applies.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_TEMPERATURE

double

the model's default

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.

If not set, the parameter is omitted from the request and the model’s own default applies.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_TOP_P

double

the model's default

An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_MAX_COMPLETION_TOKENS

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: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_PRESENCE_PENALTY

double

0

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: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_FREQUENCY_PENALTY

double

0

Whether chat model requests should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_LOG_REQUESTS

boolean

false

Whether chat model responses should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_LOG_RESPONSES

boolean

false

The response format the model should use. Some models are not compatible with some response formats, make sure to review OpenAI documentation.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_RESPONSE_FORMAT

string

Whether responses follow JSON Schema for Structured Outputs

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_STRICT_JSON_SCHEMA

boolean

The list of stop words to use.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_STOP

list of string

Constrains effort on reasoning for reasoning models. Currently supported values are minimal, low, medium, and high. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.

Note: The gpt-5-pro model defaults to (and only supports) high reasoning effort.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_REASONING_EFFORT

string

Specifies the processing type used for serving the request.

If set to auto, then the request will be processed with the service tier configured in the Project settings. If set to default, then the request will be processed with the standard pricing and performance for the selected model. If set to flex or priority, then the request will be processed with the corresponding service tier. When not set, the default behavior is auto.

When the service tier parameter is set, the response body will include the service_tier value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_SERVICE_TIER

string

default

Whether to store the generated model response for later retrieval via the Responses API.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_RESPONSES_STORE

boolean

The unique ID of the previous response to the model, used to create multi-turn conversations.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_RESPONSES_PREVIOUS_RESPONSE_ID

string

A summary of the reasoning performed by the model, for reasoning models. Supported values are auto, concise, and detailed.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_RESPONSES_REASONING_SUMMARY

string

An upper bound for the number of tokens that can be generated for a response, including visible output tokens and reasoning tokens.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_RESPONSES_MAX_OUTPUT_TOKENS

int

The maximum number of total calls to built-in tools that can be processed in a response.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_RESPONSES_MAX_TOOL_CALLS

int

Whether to allow the model to run tool calls in parallel.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_RESPONSES_PARALLEL_TOOL_CALLS

boolean

Additional output data to include in the model response.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_RESPONSES_INCLUDE

list of string

The truncation strategy to use for the model response. Supported values are auto and disabled.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_RESPONSES_TRUNCATION

string

Constrains the verbosity of the model’s response. Supported values are low, medium, and high.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_RESPONSES_TEXT_VERBOSITY

string

Used by OpenAI to cache responses for similar requests to optimize your cache hit rates.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_RESPONSES_PROMPT_CACHE_KEY

string

The retention policy for the prompt cache.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_RESPONSES_PROMPT_CACHE_RETENTION

string

A stable identifier used to help detect users of your application that may be violating OpenAI’s usage policies.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_RESPONSES_SAFETY_IDENTIFIER

string

The number of most likely tokens to return at each token position, each with an associated log probability.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_RESPONSES_TOP_LOGPROBS

int

Whether to enforce strict schema validation on tool/function definitions.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_RESPONSES_STRICT_TOOLS

boolean

Whether obfuscation fields should be included in streaming events. Only applies to the streaming chat model.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_RESPONSES_STREAM_INCLUDE_OBFUSCATION

boolean

Model name to use

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__EMBEDDING_MODEL_MODEL_NAME

string

text-embedding-ada-002

Whether embedding model requests should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__EMBEDDING_MODEL_LOG_REQUESTS

boolean

false

Whether embedding model responses should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__EMBEDDING_MODEL_LOG_RESPONSES

boolean

false

A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__EMBEDDING_MODEL_USER

string

Model name to use

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__MODERATION_MODEL_MODEL_NAME

string

omni-moderation-latest

Whether moderation model requests should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__MODERATION_MODEL_LOG_REQUESTS

boolean

false

Whether moderation model responses should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__MODERATION_MODEL_LOG_RESPONSES

boolean

false

Model name to use

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__IMAGE_MODEL_MODEL_NAME

string

gpt-image-1

Configure whether the generated images will be saved to disk. By default, persisting is disabled, but it is implicitly enabled when quarkus.langchain4j.openai.image-mode.directory is set and this property is not to false

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__IMAGE_MODEL_PERSIST

boolean

false

The path where the generated images will be persisted to disk. This only applies of quarkus.langchain4j.openai.image-mode.persist is not set to false.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__IMAGE_MODEL_PERSIST_DIRECTORY

path

${java.io.tmpdir}/openai-images

The size of the generated images.

Supported values: 1024x1024, 1536x1024, 1024x1536, or auto.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__IMAGE_MODEL_SIZE

string

1024x1024

The quality of the image that will be generated.

Supported values: auto, low, medium, or high.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__IMAGE_MODEL_QUALITY

string

auto

The number of images to generate.

Must be between 1 and 10.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__IMAGE_MODEL_NUMBER

int

1

A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__IMAGE_MODEL_USER

string

The output format of the generated image.

Supported values: png, jpeg, webp.

Only supported for gpt-image-1 and newer models.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__IMAGE_MODEL_OUTPUT_FORMAT

string

The background type for the generated image.

Supported values: transparent, opaque, auto.

Only supported for gpt-image-1 and newer models. Transparent backgrounds require output-format set to png or webp.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__IMAGE_MODEL_BACKGROUND

string

The compression level for the generated image (0-100).

Only supported for gpt-image-1 and newer models with jpeg or webp output formats.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__IMAGE_MODEL_OUTPUT_COMPRESSION

int

The moderation level for the image generation request.

Supported values: low, auto.

Only supported for gpt-image-1 and newer models.

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__IMAGE_MODEL_MODERATION

string

Whether image model requests should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__IMAGE_MODEL_LOG_REQUESTS

boolean

false

Whether image model responses should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__IMAGE_MODEL_LOG_RESPONSES

boolean

false

Model name to use

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__AUDIO_TRANSCRIPTION_MODEL_MODEL_NAME

string

whisper-1

Whether audio transcription model requests should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__AUDIO_TRANSCRIPTION_MODEL_LOG_REQUESTS

boolean

false

Whether audio transcription model responses should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__AUDIO_TRANSCRIPTION_MODEL_LOG_RESPONSES

boolean

false

Model name to use

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__DECISION_MODEL_MODEL_NAME

string

gpt-6-luna

Whether decision model requests should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__DECISION_MODEL_LOG_REQUESTS

boolean

false

Whether decision model responses should be logged

Environment variable: QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__DECISION_MODEL_LOG_RESPONSES

boolean

false

About the Duration format

To write duration values, use the standard java.time.Duration format. See the Duration#parse() Java API documentation for more information.

You can also use a simplified format, starting with a number:

  • If the value is only a number, it represents time in seconds.

  • If the value is a number followed by ms, it represents time in milliseconds.

In other cases, the simplified format is translated to the java.time.Duration format for parsing:

  • If the value is a number followed by h, m, or s, it is prefixed with PT.

  • If the value is a number followed by d, it is prefixed with P.

You can define multiple configurations to support different OpenAI models:

# Default OpenAI model configuration
quarkus.langchain4j.openai.chat-model.model-name=gpt-6-luna
quarkus.langchain4j.openai.api-key=sk-...
# Custom OpenAI model configuration
quarkus.langchain4j.openai.some-name.chat-model.model-name=o3
quarkus.langchain4j.openai.some-name.api-key=sk-...
quarkus.langchain4j.openai.some-name.chat-model.temperature=0.8

You can then select the model to use in your application by using the @RegisterAiService annotation with the modelName attribute:

import io.quarkiverse.langchain4j.RegisterAiService;

@RegisterAiService(modelName = "some-name")
public interface MyService {
    // ...
}

Or use the @ModelName annotation for programmatic injection:

import dev.langchain4j.model.chat.ChatModel;
import io.quarkiverse.langchain4j.ModelName;
import jakarta.inject.Inject;

// ...

@Inject @ModelName("some-name") ChatModel chatModel;

If no model name is specified, the default configuration is used.

Responses API

OpenAI offers two chat APIs: the classic /v1/chat/completions endpoint and the newer Responses API (/v1/responses). The Responses API is required for models that are only exposed through it (for example gpt-5-pro, o1-pro), is the only way to use tools (function calling, including skills) with GPT-6 models when reasoning is enabled (see Using GPT-6 models), and unlocks Responses-specific settings.

Which API the chat model targets is controlled by the quarkus.langchain4j.openai.chat-model.mode property (chat-completion or responses). When it is not set, the mode is selected automatically:

  • responses when the base URL is the OpenAI API (https://api.openai.com/v1/, the default);

  • chat-completion for any other base URL, which is what OpenAI-compatible endpoints such as Ollama, vLLM, llama.cpp or LM Studio implement.

The resolved mode is logged at startup. To pin a mode explicitly, for example to keep using Chat Completions against OpenAI or to use the Responses API against a compatible gateway, set the property:

quarkus.langchain4j.openai.chat-model.mode=chat-completion
quarkus.langchain4j.openai.api-key=sk-...

mode is a runtime property: it can be changed without rebuilding the application and can be set per named configuration (quarkus.langchain4j.openai.<name>.chat-model.mode).

Both the blocking ChatModel and the StreamingChatModel are supported in this mode, including tool/function calling and structured outputs. The injection points and AI service usage are unchanged — only the underlying API and endpoint differ.

Responses-specific options are configured under quarkus.langchain4j.openai.chat-model.responses.*, for example:

quarkus.langchain4j.openai.chat-model.responses.store=false
quarkus.langchain4j.openai.chat-model.responses.reasoning-summary=auto
quarkus.langchain4j.openai.chat-model.responses.max-output-tokens=1024

In responses mode the model communicates over a Quarkus REST Client-based HTTP client (the same engine used elsewhere, so native image, TLS registry configuration, proxy configuration and ModelAuthProvider implementations continue to work). Request/response logging works via the standard log-requests/log-responses settings, but quarkus.langchain4j.openai.log-requests-curl is not available on this path.

Migrating from Chat Completions

Because the Responses API is now selected automatically for https://api.openai.com/v1/, an existing configuration written for Chat Completions is affected as follows:

  • quarkus.langchain4j.openai.chat-model.max-completion-tokens and the deprecated max-tokens keep capping the output: when quarkus.langchain4j.openai.chat-model.responses.max-output-tokens is not set, max-completion-tokens is used as the Responses output limit, and max-tokens after that.

  • quarkus.langchain4j.openai.chat-model.presence-penalty, frequency-penalty and stop have no equivalent on the Responses API and are ignored.

  • quarkus.langchain4j.openai.max-retries is ignored, see the warning below.

  • quarkus.langchain4j.openai.log-requests-curl is ignored.

When the mode was selected automatically and one of the ignored settings is set explicitly, a warning listing them is logged at startup. Set quarkus.langchain4j.openai.chat-model.mode=chat-completion to keep the previous behavior.

Retries are not performed on the Responses API

quarkus.langchain4j.openai.max-retries is deprecated and is not honored on the Responses API: a request that fails with a rate limit, a server error or a timeout is not retried, and the exception reaches your code immediately. If you relied on this setting, your application loses its retries when the mode switches to responses, which happens automatically against https://api.openai.com/v1/.

Retries are not going to be added to the Responses path. Use MicroProfile Fault Tolerance instead, which works with both APIs and gives you control over delays, jitter and which exceptions are retried:

import java.time.temporal.ChronoUnit;

import org.eclipse.microprofile.faulttolerance.Retry;

import io.quarkiverse.langchain4j.RegisterAiService;

@RegisterAiService
public interface Assistant {

    @Retry(maxRetries = 3, delay = 1, delayUnit = ChronoUnit.SECONDS)
    String chat(String message);
}

This requires the quarkus-smallrye-fault-tolerance extension. Be careful with @Retry when the AI service uses tools or skills: max-retries retried a single HTTP call, whereas @Retry re-runs the whole method, so tools that already executed before the failure run again. Keep tools idempotent or scope the retry to a method without side effects. See Fault Tolerance for the full guide.

Using GPT-6 models

GPT-6 models are reasoning models, and OpenAI applies a server-side default reasoning effort of medium when quarkus.langchain4j.openai.chat-model.reasoning-effort is not set. On the Chat Completions endpoint, OpenAI rejects requests that combine tools with any reasoning effort other than none, and not every GPT-6 model accepts none:

Model Supports reasoning-effort=none Tools on Chat Completions

gpt-6-luna

yes

only with reasoning-effort=none

gpt-6-sol

yes

only with reasoning-effort=none

gpt-6-astra

no (lowest is low)

no, the Responses API is required

gpt-6.1-sol

no (defaults to medium)

no, the Responses API is required

With the automatic mode selection described above, models used against OpenAI target the Responses API, where tools work with any reasoning effort. If you force mode=chat-completion with a GPT-6 model, either avoid tools or set quarkus.langchain4j.openai.chat-model.reasoning-effort=none with a model that supports it.

Advanced usage

The OpenAI extension internally uses a Quarkus REST Client to make API calls. This client can also be used directly:

import java.net.URI;
import java.net.URISyntaxException;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

import org.jboss.resteasy.reactive.RestStreamElementType;

import dev.ai4j.openai4j.completion.CompletionChoice;
import io.quarkiverse.langchain4j.openai.common.OpenAiRestApi;
import io.quarkus.rest.client.reactive.QuarkusRestClientBuilder;
import io.smallrye.mutiny.Multi;


@Path("restApi")
@ApplicationScoped
public class QuarkusRestApiResource {

    private final OpenAiRestApi restApi;
    private final String token;

    public QuarkusRestApiResource() throws URISyntaxException {
        this.restApi = QuarkusRestClientBuilder.newBuilder()
                .baseUri(new URI("https://api.openai.com/v1/"))
                .build(OpenAiRestApi.class);
        this.token = "sometoken";

    }

    @GET
    @Path("language/streaming")
    @RestStreamElementType(MediaType.TEXT_PLAIN)
    public Multi<String> languageStreaming() {
        return restApi.streamingCompletion(
                createCompletionRequest("Write a short 1 paragraph funny poem about Enterprise Java"), token, null)
                .map(r -> {
                    if (r.choices() != null) {
                        if (r.choices().size() == 1) {
                            CompletionChoice choice = r.choices().get(0);
                            var text = choice.text();
                            if (text != null) {
                                return text;
                            }
                        }
                    }
                    return "";
                });
    }
}

In the example above, null is passed for the apiVersion parameter. This is valid for OpenAI’s standard API. For Azure OpenAI, you must provide the proper version string.

Dynamic Authorization Headers

In some scenarios, you may need to dynamically inject authorization headers into OpenAI requests.

There are two supported approaches:

Using a ContainerRequestFilter annotated with @Provider.

Create a filter implementing ResteasyReactiveClientRequestFilter:

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.ext.Provider;
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestContext;
import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestFilter;

@Provider
@ApplicationScoped
public class RequestFilter implements ResteasyReactiveClientRequestFilter {

    @Inject
    MyAuthorizationService myAuthorizationService;

    @Override
    public void filter(ResteasyReactiveClientRequestContext requestContext) {
        /*
         * All requests will be filtered here, therefore make sure that you make
         * the necessary checks to avoid putting the Authorization header in
         * requests that do not need it.
         */
        requestContext.getHeaders().putSingle("Authorization", ...);
    }
}

Ensure the filter is selective if other requests use the same HTTP client infrastructure.

Using AuthProvider

This method allows associating a custom token provider per model using @ModelName:

import io.quarkiverse.langchain4j.ModelName;
import io.quarkiverse.langchain4j.auth.ModelAuthProvider;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

@ApplicationScoped
@ModelName("my-model-name") //you can omit this if you have only one model or if you want to use the default model
public class TestClass implements ModelAuthProvider {
    @Inject MyTokenProviderService tokenProviderService;

    @Override
    public String getAuthorization(Input input) {
        /*
         * The `input` will contain some information about the request
         * about to be passed to the remote model endpoints
         */
        return "Bearer " + tokenProviderService.getToken();
    }
}

This approach is ideal for multi-tenant setups or dynamic token rotation.