Class BedrockBackend.Builder

  • All Implemented Interfaces:

    
    public final class BedrockBackend.Builder
    
                        

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

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final BedrockBackend.Builder fromEnv(AwsCredentialsProvider awsCredentialsProvider) Resolves the AWS credentials from the environment, or other sources configured by the credentials provider.
      final BedrockBackend.Builder fromEnv() Resolves the AWS credentials from the environment, or other sources configured by the credentials provider.
      final BedrockBackend.Builder awsCredentialsProvider(AwsCredentialsProvider awsCredentialsProvider) Sets the AWS credentials provider that will be used to resolve credentials.
      final BedrockBackend.Builder awsCredentials(AwsCredentials awsCredentials) Creates and sets an AWS credentials provider that provides only the given credentials.
      final BedrockBackend.Builder apiKey(String apiKey) Sets the API key to used as the Bedrock "bearer token".
      final BedrockBackend.Builder region(Region region) Sets the region to use when constructing the base URL for requests.
      final BedrockBackend build()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • fromEnv

        @JvmOverloads() final BedrockBackend.Builder fromEnv(AwsCredentialsProvider awsCredentialsProvider)

        Resolves the AWS credentials from the environment, or other sources configured by the credentials provider. If no provider is given, the AWS DefaultCredentialsProvider is used, which is suitable for many use cases. The configuration of that provider follows its usual defaults, so asynchronous refreshing is not enabled. See the AWS documentation for details. For other use cases, pass a credentials provider configured as required. The provider, whether given explicitly or by default, overrides any provider set via awsCredentialsProvider or awsCredentials.

        If an API key is set via the AWS_BEARER_TOKEN_BEDROCK environment variable and no credentials provider is given, the API key will be used instead of the default credentials provider.

        The region is also resolved immediately using the default AWS region provider chain. Once resolved here, the region will not be changed again.

        When called, this method will immediately attempt to resolve the AWS credentials (or API key) and region. An error will occur if they cannot be resolved.

        Parameters:
        awsCredentialsProvider - The AWS credentials provider to use.
      • fromEnv

        @JvmOverloads() final BedrockBackend.Builder fromEnv()

        Resolves the AWS credentials from the environment, or other sources configured by the credentials provider. If no provider is given, the AWS DefaultCredentialsProvider is used, which is suitable for many use cases. The configuration of that provider follows its usual defaults, so asynchronous refreshing is not enabled. See the AWS documentation for details. For other use cases, pass a credentials provider configured as required. The provider, whether given explicitly or by default, overrides any provider set via awsCredentialsProvider or awsCredentials.

        If an API key is set via the AWS_BEARER_TOKEN_BEDROCK environment variable and no credentials provider is given, the API key will be used instead of the default credentials provider.

        The region is also resolved immediately using the default AWS region provider chain. Once resolved here, the region will not be changed again.

        When called, this method will immediately attempt to resolve the AWS credentials (or API key) and region. An error will occur if they cannot be resolved.

      • awsCredentialsProvider

         final BedrockBackend.Builder awsCredentialsProvider(AwsCredentialsProvider awsCredentialsProvider)

        Sets the AWS credentials provider that will be used to resolve credentials. Credentials will not be resolved immediately. If misconfigured, an error may not be reported until the first client request is made. To set a credentials provider and confirm that it can resolve credentials, call fromEnv. If called after fromEnv, this overrides the credentials provider configured by fromEnv.

      • awsCredentials

         final BedrockBackend.Builder awsCredentials(AwsCredentials awsCredentials)

        Creates and sets an AWS credentials provider that provides only the given credentials. This is a convenience for simple use cases, such as when testing. The provider overrides any provider previously set by awsCredentialsProvider or fromEnv.

      • apiKey

         final BedrockBackend.Builder apiKey(String apiKey)

        Sets the API key to used as the Bedrock "bearer token". This will be set automatically from the AWS_BEARER_TOKEN_BEDROCK environment variable if that variable is set when fromEnv is called.

      • region

         final BedrockBackend.Builder region(Region region)

        Sets the region to use when constructing the base URL for requests. Alternatively, this may be resolved from the environment by calling fromEnv. If called after fromEnv, this overrides the region resolved by fromEnv.