Package org.springframework.ai.openai
Class OpenAiChatModel.Builder
java.lang.Object
org.springframework.ai.openai.OpenAiChatModel.Builder
- Enclosing class:
- OpenAiChatModel
Builder for creating
OpenAiChatModel instances.-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds a newOpenAiChatModelinstance.Registers anOpenAiHttpClientBuilderCustomizerthat mutates the underlying OkHttp client builder before the OpenAI clients are constructed.Sets the full list ofcustomizersto apply, replacing any customizers registered earlier on this builder.meterRegistry(@Nullable io.micrometer.core.instrument.MeterRegistry meterRegistry) observationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry) Sets the observation registry for metrics and tracing.openAiClient(com.openai.client.OpenAIClient openAiClient) Sets the synchronous OpenAI client.openAiClientAsync(com.openai.client.OpenAIClientAsync openAiClientAsync) Sets the asynchronous OpenAI client.options(OpenAiChatOptions options) Sets the chat options.toolCallingManager(ToolCallingManager toolCallingManager) Deprecated, for removal: This API element is subject to removal in a future version.
-
Method Details
-
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
Sets the chat options.- Parameters:
options- the chat options- Returns:
- this builder
-
toolCallingManager
@Deprecated(since="2.0.0", forRemoval=true) public OpenAiChatModel.Builder toolCallingManager(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 inOpenAiChatModelis superseded byToolCallingAdvisorused viaChatClient.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) -
httpClientBuilderCustomizer
public OpenAiChatModel.Builder httpClientBuilderCustomizer(OpenAiHttpClientBuilderCustomizer customizer) Registers anOpenAiHttpClientBuilderCustomizerthat mutates the underlying OkHttp client builder before the OpenAI clients are constructed. Use this to attach OkHttp interceptors (e.g. OAuth2 bearer-token injection), swap the dispatcher executor, or tweak any other OkHttp setting. Customizers are applied in the order they are registered, after Spring AI's own defaults, so user code wins. -
httpClientBuilderCustomizers
public OpenAiChatModel.Builder httpClientBuilderCustomizers(List<OpenAiHttpClientBuilderCustomizer> customizers) Sets the full list ofcustomizersto apply, replacing any customizers registered earlier on this builder. The order of the list is preserved when invoking the customizers. -
build
Builds a newOpenAiChatModelinstance.- Returns:
- the configured chat model
-
OpenAiChatModelis superseded byToolCallingAdvisorused viaChatClient.