Class AwsBackend.Builder

  • All Implemented Interfaces:

    
    public final class AwsBackend.Builder
    
                        

    A builder for an AwsBackend used to connect an Anthropic client to the AWS API gateway 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 AwsBackend. 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.

    • Constructor Detail

    • Method Detail

      • fromEnv

        @JvmOverloads() final AwsBackend.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. 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.

        Auth resolution follows a 5-level precedence order:

        • apiKey set directly on the builder → API key mode

        • awsAccessKey + awsSecretAccessKey set on the builder → SigV4 with explicit creds

        • awsProfile set on the builder → SigV4 with named profile

        • ANTHROPIC_AWS_API_KEY environment variable → API key mode (only when no explicit auth constructor args were provided)

        • Default AWS credential chain → SigV4

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

        The workspace ID is resolved from the ANTHROPIC_AWS_WORKSPACE_ID environment variable if set. The base URL is resolved from the ANTHROPIC_AWS_BASE_URL environment variable if set.

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

        Auth resolution follows a 5-level precedence order:

        • apiKey set directly on the builder → API key mode

        • awsAccessKey + awsSecretAccessKey set on the builder → SigV4 with explicit creds

        • awsProfile set on the builder → SigV4 with named profile

        • ANTHROPIC_AWS_API_KEY environment variable → API key mode (only when no explicit auth constructor args were provided)

        • Default AWS credential chain → SigV4

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

        The workspace ID is resolved from the ANTHROPIC_AWS_WORKSPACE_ID environment variable if set. The base URL is resolved from the ANTHROPIC_AWS_BASE_URL environment variable if set.

        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 AwsBackend.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 AwsBackend.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 AwsBackend.Builder apiKey(String apiKey)

        Sets the API key to use for authorization. This will be set automatically from the ANTHROPIC_AWS_API_KEY environment variable if that variable is set when fromEnv is called.

      • region

         final AwsBackend.Builder region(Region region)

        Sets the AWS 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.

      • workspaceId

         final AwsBackend.Builder workspaceId(String workspaceId)

        Sets the workspace ID to send as the anthropic-workspace-id request header. Alternatively, this may be resolved from the ANTHROPIC_AWS_WORKSPACE_ID environment variable by calling fromEnv.

      • skipAuth

         final AwsBackend.Builder skipAuth(Boolean skipAuth)

        Skips all authentication (both SigV4 and API key). When enabled, no auth headers are added to requests and the workspace ID is not required. This is useful when requests go through a gateway or proxy that handles authentication on the caller's behalf.

      • baseUrl

         final AwsBackend.Builder baseUrl(String baseUrl)

        Overrides the base URL for requests. When set, this takes precedence over any region derived URL. Alternatively, this may be resolved from the ANTHROPIC_AWS_BASE_URL environment variable by calling fromEnv.