AWS Claude
Use Claude models through AWS Bedrock with Kern agents.
Use Claude models through AWS Bedrock. This provides a native Claude integration optimized for AWS infrastructure.
We recommend experimenting to find the best-suited model for your use-case. Here are some general recommendations:
anthropic.claude-sonnet-4-20250514-v1:0model is their most capable model (Claude Sonnet 4).anthropic.claude-3-5-sonnet-20241022-v2:0model is good for most use-cases and supports image input.anthropic.claude-3-5-haiku-20241022-v2:0model is their fastest model.
Authentication
AWS Claude supports three authentication methods:
Method 1: API Key Authentication (Recommended)
Use the AWS Bedrock API key for simplified authentication:
1export AWS_BEDROCK_API_KEY=***2export AWS_REGION=***1setx AWS_BEDROCK_API_KEY ***2setx AWS_REGION ***Or pass them directly to the model:
1from kern.agent import Agent2from kern.models.aws import Claude34agent = Agent(5 model=Claude(6 id="us.anthropic.claude-sonnet-4-20250514-v1:0",7 api_key="your-api-key",8 aws_region="us-east-1"9 )10)Method 2: Access Key and Secret Key
Set your AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_REGION environment variables.
Get your keys from here.
1export AWS_ACCESS_KEY_ID=***2export AWS_SECRET_ACCESS_KEY=***3export AWS_REGION=***1setx AWS_ACCESS_KEY_ID ***2setx AWS_SECRET_ACCESS_KEY ***3setx AWS_REGION ***Or pass them directly:
1from kern.agent import Agent2from kern.models.aws import Claude34agent = Agent(5 model=Claude(6 id="us.anthropic.claude-sonnet-4-20250514-v1:0",7 aws_access_key="your-access-key",8 aws_secret_key="your-secret-key",9 aws_region="us-east-1"10 )11)Method 3: Boto3 Session
Use a pre-configured boto3 Session for advanced authentication scenarios:
1from boto3.session import Session2from kern.agent import Agent3from kern.models.aws import Claude45# Create a boto3 session with your preferred authentication6session = Session(7 aws_access_key_id="your-access-key",8 aws_secret_access_key="your-secret-key",9 region_name="us-east-1"10)1112agent = Agent(13 model=Claude(14 id="us.anthropic.claude-sonnet-4-20250514-v1:0",15 session=session16 )17)The authentication methods are checked in this order: Session → API Key → Access Key/Secret Key. The first available method will be used.
Example
Use Claude with your Agent:
1from kern.agent import Agent2from kern.models.aws import Claude34agent = Agent(5 model=Claude(id="us.anthropic.claude-sonnet-4-20250514-v1:0"),6 markdown=True7)89# Print the response on the terminal10agent.print_response("Share a 2 sentence horror story.")Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
id | str | "anthropic.claude-sonnet-4-20250514-v1:0" | The specific AWS Bedrock Claude model ID to use |
name | str | "AwsBedrockAnthropicClaude" | The name identifier for the AWS Bedrock Claude model |
provider | str | "AwsBedrock" | The provider of the model |
api_key | Optional[str] | None | The AWS Bedrock API key for authentication (defaults to AWS_BEDROCK_API_KEY env var) |
aws_access_key | Optional[str] | None | The AWS access key to use (defaults to AWS_ACCESS_KEY env var) |
aws_secret_key | Optional[str] | None | The AWS secret key to use (defaults to AWS_SECRET_KEY env var) |
aws_region | Optional[str] | None | The AWS region to use (defaults to AWS_REGION env var) |
session | Optional[Session] | None | A boto3 Session object to use for authentication |
max_tokens | int | 4096 | Maximum number of tokens to generate in the chat completion |
temperature | Optional[float] | None | Controls randomness in the model's output |
top_p | Optional[float] | None | Controls diversity via nucleus sampling |
top_k | Optional[int] | None | Controls diversity via top-k sampling |
stop_sequences | Optional[List[str]] | None | A list of strings that the model should stop generating text at |
request_params | Optional[Dict[str, Any]] | None | Additional parameters to include in the request |
client_params | Optional[Dict[str, Any]] | None | Additional parameters for client configuration |
Claude (AWS) extends the Anthropic Claude model with AWS Bedrock integration and has access to most of the same parameters.