# Amazon Bedrock Runtime code examples for the SDK for Java 2.x ## Overview Shows how to use the AWS SDK for Java 2.x to work with Amazon Bedrock Runtime. *Amazon Bedrock Runtime is a fully managed service that makes it easy to use foundation models from third-party providers and Amazon.* ## ⚠ Important * Running this code might result in charges to your AWS account. For more details, see [AWS Pricing](https://aws.amazon.com/pricing/?aws-products-pricing.sort-by=item.additionalFields.productNameLowercase&aws-products-pricing.sort-order=asc&awsf.Free%20Tier%20Type=*all&awsf.tech-category=*all) and [Free Tier](https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc&awsf.Free%20Tier%20Types=*all&awsf.Free%20Tier%20Categories=*all). * Running the tests might result in charges to your AWS account. * We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege). * This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services). ## Code examples ### Prerequisites For prerequisites, see the [README](../../README.md#Prerequisites) in the `javav2` folder. > ⚠ You must request access to a model before you can use it. If you try to use the model (with the API or console) before you have requested access to it, you will receive an error message. For more information, see [Model access](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html). ### Single actions Code excerpts that show you how to call individual service functions. * [Invoke AI21 Labs Jurassic-2 on Amazon Bedrock](src/main/java/com/example/bedrockruntime/InvokeModel.java#L101) (`InvokeModel`) * [Invoke Anthropic Claude 2 on Amazon Bedrock](src/main/java/com/example/bedrockruntime/InvokeModel.java#L51) (`InvokeModel`) * [Invoke Meta Llama 2 on Amazon Bedrock](src/main/java/com/example/bedrockruntime/InvokeModel.java#L151) (`InvokeModel`) * [Invoke Stability.ai Stable Diffusion XL on Amazon Bedrock](src/main/java/com/example/bedrockruntime/InvokeModel.java#L198) (`InvokeModel`) * [Invoke a model on Amazon Bedrock with a response stream](src/main/java/com/example/bedrockruntime/InvokeModelWithResponseStream.java#L49) (`InvokeModelWithResponseStream`) ## Run the examples ### Instructions ### Tests ⚠ Running tests might result in charges to your AWS account. To find instructions for running these tests, see the [README](../../README.md#Tests) in the `javav2` folder. ## Additional resources * [Amazon Bedrock Runtime User Guide](https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-bedrock.html) * [Amazon Bedrock Runtime API Reference](https://docs.aws.amazon.com/bedrock/latest/APIReference/welcome.html) * [SDK for Java 2.x Amazon Bedrock Runtime reference](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/bedrock-runtime/package-summary.html) --- Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0