Class ClientOptions

  • All Implemented Interfaces:

    
    public final class ClientOptions
    
                        

    A class representing the SDK client configuration.

    • Constructor Detail

    • Method Detail

      • httpClient

         final HttpClient httpClient()

        The HTTP client to use in the SDK.

        Use the one published in anthropic-java-client-okhttp or implement your own.

        This class takes ownership of the client and closes it when closed.

      • interceptors

         final List<Interceptor> interceptors()

        Wraps the HTTP client using the given interceptors.

        The interceptors are applied to every request, including retries, in order.

        Each interceptor receives an HTTP client that delegates to the next interceptor, and the last interceptor receives the underlying HTTP client.

        Interceptors observe requests in the canonical Anthropic API shape, with the client's default headers and first-party credentials (X-Api-Key or Authorization) already applied, and they observe responses normalized to the Anthropic shape (e.g. Bedrock's binary event stream is decoded to SSE). Backend-specific adaptation — URL rewriting, request signing (e.g. AWS SigV4), and backend credentials — happens below the interceptors and is not visible to them.

        Because credentials are applied above the interceptors, an interceptor that wants to replace them must use replaceHeaders, not putHeader (which would append a duplicate header). Interceptors that forward request data to external systems must redact these headers.

      • checkJacksonVersionCompatibility

         final Boolean checkJacksonVersionCompatibility()

        Whether to throw an exception if any of the Jackson versions detected at runtime are incompatible with the SDK's minimum supported Jackson version (2.13.4).

        Defaults to true. Use extreme caution when disabling this option. There is no guarantee that the SDK will work correctly when using an incompatible Jackson version.

      • jsonMapper

         final JsonMapper jsonMapper()

        The Jackson JSON mapper to use for serializing and deserializing JSON.

        Defaults to com.anthropic.core.jsonMapper. The default is usually sufficient and rarely needs to be overridden.

      • sleeper

         final Sleeper sleeper()

        The interface to use for delaying execution, like during retries.

        This is primarily useful for using fake delays in tests.

        Defaults to real execution delays.

        This class takes ownership of the sleeper and closes it when closed.

      • clock

         final Clock clock()

        The clock to use for operations that require timing, like retries.

        This is primarily useful for using a fake clock in tests.

        Defaults to Clock.systemUTC.

      • responseValidation

         final Boolean responseValidation()

        Whether to call validate on every response before returning it.

        Setting this to true is not forwards compatible with new types from the API for existing fields.

        Defaults to false, which means the shape of the response will not be validated upfront. Instead, validation will only occur for the parts of the response that are accessed.

      • timeout

         final Timeout timeout()

        Sets the maximum time allowed for various parts of an HTTP call's lifecycle, excluding retries.

        Defaults to Timeout.default.

      • maxRetries

         final Integer maxRetries()

        The maximum number of times to retry failed requests, with a short exponential backoff between requests.

        Only the following error types are retried:

        • Connection errors (for example, due to a network connectivity problem)

        • 408 Request Timeout

        • 409 Conflict

        • 429 Rate Limit

        • 5xx Internal

        The API may also explicitly instruct the SDK to retry or not retry a request.

        Defaults to 2.

      • baseUrl

         final String baseUrl()

        The base URL to use for every request.

        Defaults to the production environment: https://api.anthropic.com.

      • close

         final Unit close()

        Closes these client options, relinquishing any underlying resources.

        This is purposefully not inherited from AutoCloseable because the client options are long-lived and usually should not be synchronously closed via try-with-resources.

        It's also usually not necessary to call this method at all. the default client automatically releases threads and connections if they remain idle, but if you are writing an application that needs to aggressively release unused resources, then you may call this method.