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()final JsonMapperjsonMapper()final UnitapplyCredentials(HttpClient httpClient, ClientOptions.Builder clientOptionsBuilder)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)Adds the static credential headers if no auth headers are present. 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()
-
jsonMapper
final JsonMapper jsonMapper()
-
applyCredentials
final Unit applyCredentials(HttpClient httpClient, ClientOptions.Builder clientOptionsBuilder)
-
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)
Adds the static credential headers 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.
-
builder
final static AnthropicBackend.Builder builder()
-
fromEnv
final static AnthropicBackend fromEnv()
-
-
-
-