Class AnthropicBackend

  • All Implemented Interfaces:
    com.anthropic.backends.Backend

    
    public final class AnthropicBackend
     implements Backend
                        

    The Anthropic backend that manages the API key or authorization token credentials and base URL required to access an Anthropic AI model on the Anthropic service.

    The apiKey or the authToken should be set (or resolved from the environment), but not both. Either one is sent as Authorization: Bearer. The default value for the base URL is the normal Anthropic API service base URL, so it only needs to be set if a different base URL is required.

    The credentials can be resolved from environment variables by calling Builder.fromEnv. Alternatively, they can be supplied directly to the builder.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public final class AnthropicBackend.Builder

      A builder for a AnthropicBackend used to connect an Anthropic client to an Anthropic backend service.

      The authorization credentials can be extracted from the environment and set on the builder by calling fromEnv before calling build to create the AnthropicBackend. Alternatively, set one credential explicitly via apiKey, authToken or configurationProvider before calling build. A credential set explicitly is the only one used: nothing is taken from the environment, whichever kind it is.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final JsonMapper jsonMapper
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Constructor Detail

    • Method Detail

      • baseUrl

         String baseUrl()

        Gets the backend service's base URL identifying the network address of the service that will be accessed by this backend.

        The client builder adopts this as the client's base URL when the client is built; each request then carries its own base URL, which is what the transport uses.

      • authorizeRequest

         HttpRequest authorizeRequest(HttpRequest request)

        Adds the static credential header if no auth headers are present.

        When the client is built via AnthropicOkHttpClient/AnthropicOkHttpClientAsync, the credentials are already applied by a client-level auth layer that wraps the user's interceptors (see applyCredentials), making this a no-op. It remains as a fallback for hand-assembled clients where that layer was never installed.

      • close

         Unit close()

        Closes any streams and releases any resources used by this backend. For example, an implementation might use this to shut down a thread pool that will no longer be needed.