Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To call an Amazon Bedrock chat model from a Java application using Spring AI, add the spring-ai-starter-model-bedrock-converse starter, configure an AWS region and credentials, enable a compatible Bedrock model in your AWS account, and select its model ID. Then use Spring AI’s ChatClient for a regular response or a reactive stream.

What you need before you start

  • An AWS account with credentials available to your application.
  • An AWS region configured for Bedrock.
  • Access to a Bedrock model enabled for your account, plus its model ID.
  • A Java application using Spring AI, with the Bedrock Converse starter and Spring AI BOM on its build classpath.

Model access, supported capabilities, and regional availability vary. Check AWS’s current model compatibility information before choosing a model or region. A model available in one region or through one Bedrock API is not necessarily available in another.

Add the Spring AI Bedrock Converse starter

Use spring-ai-starter-model-bedrock-converse as the application starter and import the Spring AI BOM so the starter’s version is managed consistently with the rest of Spring AI. Keep the BOM and Spring AI dependencies on the same release line; use the version selected for your project rather than mixing independently chosen Spring AI component versions.

The starter integrates Spring AI with Bedrock’s Converse API. This is the chat integration described here; it is distinct from choosing another Bedrock API directly through an AWS SDK integration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configure the AWS region, credentials, and model

Set spring.ai.bedrock.aws.region to the region where the model is available. Supply credentials through Spring properties, environment or profile-based AWS credential resolution, or compatible provider beans. Keep credentials out of source code and avoid committing secrets to application configuration.

Enable the model for the AWS account that will make the calls, then select its model ID in Spring AI’s Bedrock chat configuration. The exact model ID and available configuration properties depend on the model and Spring AI release; consult the reference for the release used by your application rather than copying a property key from a different version.

Spring AI lets you set the model and generation options through configuration properties or through BedrockChatOptions. Available options include temperature, top-p, top-k, maximum tokens, and tool callbacks. Choose values the selected model supports; a property being available in Spring AI does not imply that every Bedrock model accepts every option.

Make a regular chat request with ChatClient

Inject ChatClient.Builder, build a client, and pass the user’s message to call().content(). This compact controller illustrates the request flow:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
@RestController
public class ChatController {
    private final ChatClient chatClient;

    public ChatController(ChatClient.Builder builder) {
        this.chatClient = builder.build();
    }

    @GetMapping("/chat")
    public String chat(@RequestParam String message) {
        return chatClient.prompt(message).call().content();
    }
}

With the AWS region, credentials, model access, and model selection configured, a request to /chat?message=... returns the model response as a string. In a real application, validate and constrain user input, handle service errors, and avoid returning sensitive prompts or provider details to clients.

Stream a response

For incremental output, use stream().content() instead of call().content(). The result is a reactive stream that can be returned from an HTTP streaming endpoint:

@GetMapping(value = "/chat/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<String> stream(@RequestParam String message) {
    return chatClient.prompt(message).stream().content();
}

This returns chunks as they arrive rather than waiting for one complete string. The client consuming the endpoint must support the chosen streaming response format, and the application needs its reactive web stack configured to serve that format.

Use conversation instructions, tools, and multimodal input

Bedrock Converse supports system messages, tool or function calling, and multimodal inputs when the selected model supports them. Spring AI also exposes tool callbacks through BedrockChatOptions. Treat these capabilities as model-dependent: verify the chosen model’s supported input types, tool behavior, and structured-output support before designing an application around them.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Native structured output is available for supported models. It is not a guarantee that every model will produce a valid result for every schema or prompt, so applications should still validate returned data before using it.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose a Bedrock model for the application

Compare candidate models against the workload rather than choosing by name alone. AWS’s model compatibility information is the authority for API and regional support; check these criteria for each candidate:

  • API support: confirm the model supports Converse, not only another Bedrock API.
  • Regional availability: confirm it can be invoked in the region configured for the application.
  • Modalities: check whether it accepts the text, image, or other input types your use case requires.
  • Tools and structured output: verify support for tool use and any native structured-output behavior you plan to rely on.
  • Context and token limits: check the model’s input and output limits against your prompts and expected responses.
  • Latency and cost: assess these for your workload and deployment region; they differ by model and usage.

Use AWS’s Java examples as a separate reference

AWS provides a Java Foundation Model Playground sample: a Spring Boot application with text, chat, and image playgrounds using the Bedrock Runtime and AWS SDK for Java 2.x. It is useful for understanding the AWS SDK path and seeing multiple playground interactions. Spring AI’s Converse starter is the integration path in this guide; the AWS sample is not a substitute for Spring AI configuration.

AWS’s Spring AI AgentCore article specifies Java 17 or higher, Spring Boot 3.5 or higher, an AWS account, and Maven or Gradle for that example, and demonstrates region and model properties plus streaming with Flux<String>. Treat those versions as requirements for that example, not as universal minimum versions for every Spring AI Bedrock application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.