Class OpenAiChatModel.Builder

java.lang.Object
org.springframework.ai.openai.OpenAiChatModel.Builder
Enclosing class:
OpenAiChatModel

public static final class OpenAiChatModel.Builder extends Object
Builder for creating OpenAiChatModel instances.
  • Method Details

    • openAiClient

      public OpenAiChatModel.Builder openAiClient(com.openai.client.OpenAIClient openAiClient)
      Sets the synchronous OpenAI client.
      Parameters:
      openAiClient - the synchronous client
      Returns:
      this builder
    • openAiClientAsync

      public OpenAiChatModel.Builder openAiClientAsync(com.openai.client.OpenAIClientAsync openAiClientAsync)
      Sets the asynchronous OpenAI client.
      Parameters:
      openAiClientAsync - the asynchronous client
      Returns:
      this builder
    • options

      public OpenAiChatModel.Builder options(OpenAiChatOptions options)
      Sets the chat options.
      Parameters:
      options - the chat options
      Returns:
      this builder
    • toolCallingManager

      @Deprecated(since="2.0.0", forRemoval=true) public OpenAiChatModel.Builder toolCallingManager(org.springframework.ai.model.tool.ToolCallingManager toolCallingManager)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 2.0.0 for removal in 3.0.0 — internal tool execution in OpenAiChatModel is superseded by ToolCallingAdvisor used via ChatClient.
      Sets the tool calling manager used for internal tool execution.
      Parameters:
      toolCallingManager - the tool calling manager
      Returns:
      this builder
    • observationRegistry

      public OpenAiChatModel.Builder observationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry)
      Sets the observation registry for metrics and tracing.
      Parameters:
      observationRegistry - the observation registry
      Returns:
      this builder
    • meterRegistry

      public OpenAiChatModel.Builder meterRegistry(@Nullable io.micrometer.core.instrument.MeterRegistry meterRegistry)
    • dispatcherExecutor

      public OpenAiChatModel.Builder dispatcherExecutor(ExecutorService dispatcherExecutor)
      Sets the executor used by the underlying OkHttp dispatcher for both the sync and async clients. The caller owns the executor's lifecycle — Spring AI will not shut it down. Typical use: pass Executors.newVirtualThreadPerTaskExecutor() on Java 21+ to back HTTP dispatch with virtual threads. When omitted, an internal platform-thread executor is created and managed by the HTTP client.
      Parameters:
      dispatcherExecutor - the dispatcher executor; null restores the default
      Returns:
      this builder
      Since:
      2.0.0
    • build

      public OpenAiChatModel build()
      Builds a new OpenAiChatModel instance.
      Returns:
      the configured chat model