AWS Bedrock

Use AWS Bedrock foundation models with Kern agents.

Use AWS Bedrock to access various foundation models on AWS. Manage your access to models on the portal.

See all the AWS Bedrock foundational models. Not all Bedrock models support all features. See the supported features for each model.

Note

For async support with AWS Bedrock, you need to install aioboto3:

1uv pip install aioboto3

We recommend experimenting to find the best-suited model for your use-case. Here are some general recommendations:

  • For a Mistral model with generally good performance, look at mistral.mistral-large-2402-v1:0.
  • You can play with Amazon Nova models. Use amazon.nova-pro-v1:0 for general purpose tasks.
  • For Claude models, see our Claude integration.

Authentication

AWS Bedrock supports three authentication methods:

Method 1: Access Key and Secret Key (Recommended)

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 to the model:

1from kern.agent import Agent
2from kern.models.aws import AwsBedrock
3
4agent = Agent(
5 model=AwsBedrock(
6 id="mistral.mistral-large-2402-v1:0",
7 aws_access_key_id="your-access-key",
8 aws_secret_access_key="your-secret-key",
9 aws_region="us-east-1"
10 )
11)

Method 2: SSO Authentication

Use SSO authentication by leveraging your current AWS profile's authentication:

1from kern.agent import Agent
2from kern.models.aws import AwsBedrock
3
4agent = Agent(
5 model=AwsBedrock(
6 id="mistral.mistral-large-2402-v1:0",
7 aws_sso_auth=True,
8 aws_region="us-east-1"
9 )
10)

Method 3: Boto3 Session

Use a pre-configured boto3 Session for advanced authentication scenarios (including SSO, role assumption, etc.):

1from boto3.session import Session
2from kern.agent import Agent
3from kern.models.aws import AwsBedrock
4
5# Create a boto3 session with your preferred authentication
6session = Session(
7 aws_access_key_id="your-access-key",
8 aws_secret_access_key="your-secret-key",
9 region_name="us-east-1"
10)
11
12agent = Agent(
13 model=AwsBedrock(
14 id="mistral.mistral-large-2402-v1:0",
15 session=session
16 )
17)
Note

The authentication methods are checked in this order: Session → API Key → Access Key/Secret Key. The first available method will be used.

Example

Use AwsBedrock with your Agent:

1from kern.agent import Agent
2from kern.models.aws import AwsBedrock
3
4agent = Agent(
5 model=AwsBedrock(id="mistral.mistral-large-2402-v1:0"),
6 markdown=True
7)
8
9# Print the response on the terminal
10agent.print_response("Share a 2 sentence horror story.")
Note View more examples here.

Parameters

ParameterTypeDefaultDescription
idstr"mistral.mistral-small-2402-v1:0"The specific model ID used for generating responses.
namestr"AwsBedrock"The name identifier for the AWS Bedrock agent.
providerstr"AwsBedrock"The provider of the model.
aws_access_key_idOptional[str]NoneThe AWS access key ID for authentication. Can also be set via AWS_ACCESS_KEY_ID environment variable.
aws_secret_access_keyOptional[str]NoneThe AWS secret access key for authentication. Can also be set via AWS_SECRET_ACCESS_KEY environment variable.
aws_regionOptional[str]NoneThe AWS region to use for API requests. Can also be set via AWS_REGION environment variable.
sessionOptional[Session]NoneA boto3 Session object for advanced authentication scenarios (SSO, role assumption, etc.).
aws_sso_authOptional[bool]FalseRemoves the need for an access and secret access key by leveraging the current profile's authentication.
max_tokensOptional[int]NoneThe maximum number of tokens to generate in the response.
temperatureOptional[float]NoneThe sampling temperature to use, between 0 and 2. Higher values like 0.8 make the output more random, while lower values like 0.2 make it more focused and deterministic.
top_pOptional[float]NoneThe nucleus sampling parameter. The model considers the results of the tokens with top_p probability mass.
stop_sequencesOptional[List[str]]NoneA list of sequences where the API will stop generating further tokens.
request_paramsOptional[Dict[str, Any]]NoneAdditional parameters for the request, provided as a dictionary.
client_paramsOptional[Dict[str, Any]]NoneAdditional client parameters for initializing the AwsBedrock client, provided as a dictionary.
clientOptional[AwsClient]NoneA pre-configured AWS client instance.

AwsBedrock is a subclass of the Model class and has access to the same params.