This version is still in development and is not considered stable yet. For the latest snapshot version, please use Spring AI 1.0.0-SNAPSHOT!spring-doc.cn

Amazon Bedrock

Amazon Bedrock is a managed service that provides foundation models from various AI providers, available through a unified API.spring-doc.cn

Spring AI supports all the Chat and Embedding AI models available through Amazon Bedrock by implementing the Spring interfaces ChatModel, StreamingChatModel, and EmbeddingModel.spring-doc.cn

Additionally, Spring AI provides Spring Auto-Configurations and Boot Starters for all clients, making it easy to bootstrap and configure for the Bedrock models.spring-doc.cn

Getting Started

There are a few steps to get startedspring-doc.cn

Project Dependencies

Then add the Spring Boot Starter dependency to your project’s Maven pom.xml build file:spring-doc.cn

<dependency>
 <artifactId>spring-ai-bedrock-ai-spring-boot-starter</artifactId>
 <groupId>org.springframework.ai</groupId>
</dependency>

or to your Gradle build.gradle build file.spring-doc.cn

dependencies {
    implementation 'org.springframework.ai:spring-ai-bedrock-ai-spring-boot-starter'
}
Refer to the Dependency Management section to add the Spring AI BOM to your build file.

Connect to AWS Bedrock

Use the BedrockAwsConnectionProperties to configure AWS credentials and region:spring-doc.cn

spring.ai.bedrock.aws.region=us-east-1

spring.ai.bedrock.aws.access-key=YOUR_ACCESS_KEY
spring.ai.bedrock.aws.secret-key=YOUR_SECRET_KEY

spring.ai.bedrock.aws.timeout=10m

The region property is compulsory.spring-doc.cn

AWS credentials are resolved in the following order:spring-doc.cn

  1. Spring-AI Bedrock spring.ai.bedrock.aws.access-key and spring.ai.bedrock.aws.secret-key properties.spring-doc.cn

  2. Java System Properties - aws.accessKeyId and aws.secretAccessKey.spring-doc.cn

  3. Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.spring-doc.cn

  4. Web Identity Token credentials from system properties or environment variables.spring-doc.cn

  5. Credential profiles file at the default location (~/.aws/credentials) shared by all AWS SDKs and the AWS CLI.spring-doc.cn

  6. Credentials delivered through the Amazon EC2 container service if the AWS_CONTAINER_CREDENTIALS_RELATIVE_URI environment variable is set and the security manager has permission to access the variable.spring-doc.cn

  7. Instance profile credentials delivered through the Amazon EC2 metadata service or set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.spring-doc.cn

AWS region is resolved in the following order:spring-doc.cn

  1. Spring-AI Bedrock spring.ai.bedrock.aws.region property.spring-doc.cn

  2. Java System Properties - aws.region.spring-doc.cn

  3. Environment Variables - AWS_REGION.spring-doc.cn

  4. Credential profiles file at the default location (~/.aws/credentials) shared by all AWS SDKs and the AWS CLI.spring-doc.cn

  5. Instance profile region delivered through the Amazon EC2 metadata service.spring-doc.cn

In addition to the standard Spring-AI Bedrock credentials and region properties configuration, Spring-AI provides support for custom AwsCredentialsProvider and AwsRegionProvider beans.spring-doc.cn

For example, using Spring-AI and Spring Cloud for Amazon Web Services at the same time. Spring-AI is compatible with Spring Cloud for Amazon Web Services credential configuration.

Enable selected Bedrock model

By default, all models are disabled. You have to enable the chosen Bedrock models explicitly using the spring.ai.bedrock.<model>.<chat|embedding>.enabled=true property.

Here are the supported <model> and <chat|embedding> combinations:spring-doc.cn

Model Chat Chat Streaming Embedding

llamaspring-doc.cn

Yesspring-doc.cn

Yesspring-doc.cn

Nospring-doc.cn

jurassic2spring-doc.cn

Yesspring-doc.cn

Nospring-doc.cn

Nospring-doc.cn

coherespring-doc.cn

Yesspring-doc.cn

Yesspring-doc.cn

Yesspring-doc.cn

anthropic 2spring-doc.cn

Yesspring-doc.cn

Yesspring-doc.cn

Nospring-doc.cn

anthropic 3spring-doc.cn

Yesspring-doc.cn

Yesspring-doc.cn

Nospring-doc.cn

jurassic2 (WIP)spring-doc.cn

Yesspring-doc.cn

Nospring-doc.cn

Nospring-doc.cn

titanspring-doc.cn

Yesspring-doc.cn

Yesspring-doc.cn

Yes (however, no batch support)spring-doc.cn

For example, to enable the Bedrock Llama chat model, you need to set spring.ai.bedrock.llama.chat.enabled=true.spring-doc.cn

Next, you can use the spring.ai.bedrock.<model>.<chat|embedding>.* properties to configure each model as provided.spring-doc.cn

For more information, refer to the documentation below for each supported model.spring-doc.cn