Class AwsBackend.Builder
-
- All Implemented Interfaces:
public final class AwsBackend.BuilderA 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.
-
-
Method Summary
Modifier and Type Method Description final AwsBackend.BuilderfromEnv(AwsCredentialsProvider awsCredentialsProvider)Resolves the AWS credentials from the environment, or other sources configured by the credentials provider. final AwsBackend.BuilderfromEnv()Resolves the AWS credentials from the environment, or other sources configured by the credentials provider. final AwsBackend.BuilderawsCredentialsProvider(AwsCredentialsProvider awsCredentialsProvider)Sets the AWS credentials provider that will be used to resolve credentials. final AwsBackend.BuilderawsCredentials(AwsCredentials awsCredentials)Creates and sets an AWS credentials provider that provides only the given credentials. final AwsBackend.BuilderawsAccessKey(String awsAccessKey)Sets the AWS access key ID for SigV4 signing. final AwsBackend.BuilderawsSecretAccessKey(String awsSecretAccessKey)Sets the AWS secret access key for SigV4 signing. final AwsBackend.BuilderawsSessionToken(String awsSessionToken)Sets the AWS session token for SigV4 signing. final AwsBackend.BuilderawsProfile(String awsProfile)Sets a named AWS profile for credential resolution via SigV4 signing. final AwsBackend.BuilderapiKey(String apiKey)Sets the API key to use for authorization. final AwsBackend.Builderregion(Region region)Sets the AWS region to use when constructing the base URL for requests. final AwsBackend.BuilderworkspaceId(String workspaceId)Sets the workspace ID to send as the anthropic-workspace-idrequest header.final AwsBackend.BuilderskipAuth(Boolean skipAuth)Skips all authentication (both SigV4 and API key). final AwsBackend.BuilderbaseUrl(String baseUrl)Overrides the base URL for requests. final AwsBackendbuild()-
-
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
DefaultCredentialsProvideris 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_KEYenvironment 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_IDenvironment variable if set. The base URL is resolved from theANTHROPIC_AWS_BASE_URLenvironment 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
DefaultCredentialsProvideris 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_KEYenvironment 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_IDenvironment variable if set. The base URL is resolved from theANTHROPIC_AWS_BASE_URLenvironment 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.
-
awsAccessKey
final AwsBackend.Builder awsAccessKey(String awsAccessKey)
Sets the AWS access key ID for SigV4 signing. Must be paired with awsSecretAccessKey. Conflicts with apiKey.
-
awsSecretAccessKey
final AwsBackend.Builder awsSecretAccessKey(String awsSecretAccessKey)
Sets the AWS secret access key for SigV4 signing. Must be paired with awsAccessKey. Conflicts with apiKey.
-
awsSessionToken
final AwsBackend.Builder awsSessionToken(String awsSessionToken)
Sets the AWS session token for SigV4 signing. Only applicable when both awsAccessKey and awsSecretAccessKey are also set.
-
awsProfile
final AwsBackend.Builder awsProfile(String awsProfile)
Sets a named AWS profile for credential resolution via SigV4 signing. Conflicts with apiKey.
-
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_KEYenvironment 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-idrequest header. Alternatively, this may be resolved from theANTHROPIC_AWS_WORKSPACE_IDenvironment 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_URLenvironment variable by calling fromEnv.
-
build
final AwsBackend build()
-
-
-
-