Class BedrockBackend
-
- All Implemented Interfaces:
-
com.anthropic.backends.Backend
public final class BedrockBackend implements Backend
The Amazon Bedrock backend that manages the AWS credentials or API key required to access an Anthropic AI model on the Bedrock service and adapts requests and responses to Bedrock's requirements.
Unless using an API key, Amazon Bedrock requires cryptographically-signed requests using credentials issued by AWS. These can be provided via system properties, environment variables, or other AWS facilities. They can be resolved automatically by the default AWS provider chain by calling Builder.fromEnv. Alternatively, a custom AWS credentials provider can be configured on the builder and used to resolve the credentials.
If using an API key, the key can be set directly, or provided via the
AWS_BEARER_TOKEN_BEDROCKenvironment variable. If that variable is set, it will be resolved by Builder.fromEnv unless an AWS credentials provider is specified explicitly to that method.Both the credentials (or API key) and the region can be resolved independently and passed to Builder.awsCredentials (or Builder.apiKey) and Builder.region should an alternative method of resolution be required.
See the Amazon Bedrock and AWS documentation for details on how to configure AWS credentials.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classBedrockBackend.BuilderA builder for a BedrockBackend used to connect an Anthropic client to an Amazon Bedrock backend service.
The AWS credentials and region can be extracted from the environment and set on the builder by calling fromEnv before calling build to create the BedrockBackend. Alternatively, set the AWS credentials and region explicitly via awsCredentials and region before calling build. A custom AWS credentials provider can be passed to fromEnv or awsCredentialsProvider.
You should set either the AWS credentials provider or the API key, but not both. If both are set, an error will occur.
-
Field Summary
Fields Modifier and Type Field Description private final AwsCredentialsawsCredentialsprivate final AwsCredentialsProviderawsCredentialsProviderprivate final StringapiKeyprivate final Regionregion
-
Method Summary
Modifier and Type Method Description final AwsCredentialsawsCredentials()final AwsCredentialsProviderawsCredentialsProvider()final StringapiKey()final Regionregion()StringbaseUrl()HttpRequestprepareRequest(HttpRequest request)HttpRequestauthorizeRequest(HttpRequest request)HttpResponseprepareResponse(HttpResponse response)Unitclose()final static BedrockBackend.Builderbuilder()final static BedrockBackendfromEnv()Creates a Bedrock Backend configured to use the default AWS credentials provider. -
-
Method Detail
-
awsCredentials
final AwsCredentials awsCredentials()
-
awsCredentialsProvider
final AwsCredentialsProvider awsCredentialsProvider()
-
region
final Region region()
-
prepareRequest
HttpRequest prepareRequest(HttpRequest request)
-
authorizeRequest
HttpRequest authorizeRequest(HttpRequest request)
-
prepareResponse
HttpResponse prepareResponse(HttpResponse response)
-
builder
final static BedrockBackend.Builder builder()
-
fromEnv
final static BedrockBackend fromEnv()
Creates a Bedrock Backend configured to use the default AWS credentials provider. See Builder.fromEnv for more details, or to configure a different provider.
-
-
-
-