Class AnthropicChatModel.Builder

java.lang.Object
org.springframework.ai.anthropic.AnthropicChatModel.Builder
Enclosing class:
AnthropicChatModel

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

    • anthropicClient

      public AnthropicChatModel.Builder anthropicClient(com.anthropic.client.AnthropicClient anthropicClient)
      Sets the synchronous Anthropic client.
      Parameters:
      anthropicClient - the synchronous client
      Returns:
      this builder
    • anthropicClientAsync

      public AnthropicChatModel.Builder anthropicClientAsync(com.anthropic.client.AnthropicClientAsync anthropicClientAsync)
      Sets the asynchronous Anthropic client.
      Parameters:
      anthropicClientAsync - 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 AnthropicChatModel.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 AnthropicChatModel 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 AnthropicChatModel.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 AnthropicChatModel.Builder meterRegistry(@Nullable io.micrometer.core.instrument.MeterRegistry meterRegistry)
      Sets the meter registry used to bind OkHttp connection-pool gauges (active/idle connections). Optional; when omitted, no pool gauges are registered. Auto-configuration wires the application's MeterRegistry bean here automatically.
      Parameters:
      meterRegistry - the meter registry
      Returns:
      this builder
      Since:
      2.0.0
    • dispatcherExecutor

      public AnthropicChatModel.Builder dispatcherExecutor(@Nullable 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
    • httpClientBuilderCustomizer

      public AnthropicChatModel.Builder httpClientBuilderCustomizer(AnthropicHttpClientBuilderCustomizer customizer)
      Registers an AnthropicHttpClientBuilderCustomizer that mutates the underlying OkHttp client builder before the Anthropic 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.
      Parameters:
      customizer - the customizer to add
      Returns:
      this builder
      Since:
      2.0.0
    • httpClientBuilderCustomizers

      public AnthropicChatModel.Builder httpClientBuilderCustomizers(List<AnthropicHttpClientBuilderCustomizer> customizers)
      Sets the full list of customizers to apply, replacing any customizers registered earlier on this builder. The order of the list is preserved when invoking the customizers.
      Parameters:
      customizers - the list of customizers
      Returns:
      this builder
      Since:
      2.0.0
    • build

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