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 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 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 JsonMapperjsonMapper
-
Method Summary
Modifier and Type Method Description final JsonMapperjsonMapper()StringbaseUrl()Gets the backend service's base URL identifying the network address of the service that will be accessed by this backend. final Optional<String>apiKey()final Optional<String>authToken()final UnitapplyCredentials(HttpClient httpClient, ClientOptions.Builder clientOptionsBuilder)HttpRequestauthorizeRequest(HttpRequest request)Adds the static credential header 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()-
Methods inherited from class com.anthropic.backends.Backend
openTelemetryPlatform, openTelemetryProviderName, prepareRequest, prepareResponse, supportsMessageThreads -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
jsonMapper
final JsonMapper jsonMapper()
-
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.
-
applyCredentials
final Unit applyCredentials(HttpClient httpClient, ClientOptions.Builder clientOptionsBuilder)
-
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.
-
builder
final static AnthropicBackend.Builder builder()
-
fromEnv
final static AnthropicBackend fromEnv()
-
-
-
-