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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classAnthropicBackend.BuilderA 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 the credentials explicitly via apiKey or authToken before calling build.
-
Method Summary
Modifier and Type Method Description final StringapiKey()final StringauthToken()final StringgetBaseUrl()StringbaseUrl()Gets the backend service's base URL identifying the network address of the service that will be accessed by this backend. HttpRequestprepareRequest(HttpRequest request)Prepares the request for use by the backend service. HttpRequestauthorizeRequest(HttpRequest request)Authorizes the given request and returns the new authorized request. Unitclose()Closes any streams and releases any resources used by this backend. final static AnthropicBackend.Builderbuilder()final static AnthropicBackendfromEnv()-
-
Method Detail
-
getBaseUrl
final String getBaseUrl()
-
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.
-
builder
final static AnthropicBackend.Builder builder()
-
fromEnv
final static AnthropicBackend fromEnv()
-
-
-
-