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). 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.

    • 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.

      • prepareRequest

         HttpRequest prepareRequest(HttpRequest request)

        Prepares the request for use by the backend service. Changes may be made to the request to adapt it for backends other than the default Anthropic backend.

        Changes may be made to the headers, path segments, query parameters, and body content to suit the requirements of the backend where they differ from the default Anthropic backend. All changes that may affect the resolution of the full URL for the request must be made by this method.

        Changes specifically related to request authorization or signing should be performed by the implementation of authorizeRequest.

        If no changes are required, the given request can be returned unchanged. This is the behavior of the default implementation.

      • authorizeRequest

         HttpRequest authorizeRequest(HttpRequest request)

        Authorizes the given request and returns the new authorized request. The URL of the request will be resolved fully before this method is called.

        Changes will typically include the addition of authorization headers or signature headers. Other changes not directly related to authorization should be performed by prepareRequest.

        Where a backend does not require request authorization or other related changes to the request, the given HttpRequest may be returned unchanged. This is the behavior of the default implementation.

      • 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.