Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Run example Amazon Bedrock API requests with the AWS Command Line Interface

Focus mode
Run example Amazon Bedrock API requests with the AWS Command Line Interface - Amazon Bedrock

This section guides you through trying out some common operations in Amazon Bedrock using the AWS CLI to test that your permissions and authentication are set up properly. Before you run the following examples, you should check that you have fulfilled the following prerequisites:

Prerequisites

Test that your permissions are set up properly for Amazon Bedrock, using a user or role that you set up with the proper permissions.

List the foundation models that Amazon Bedrock has to offer

The following example runs the ListFoundationModels operation using an Amazon Bedrock endpoint. ListFoundationModels lists the foundation models (FMs) that are available in Amazon Bedrock in your region. In a terminal, run the following command:

aws bedrock list-foundation-models --region us-east-1

If the command is successful, the response returns a list of foundation models that are available in Amazon Bedrock.

Submit a text prompt to a model and generate a text response with InvokeModel

The following example runs the InvokeModel operation using an Amazon Bedrock runtime endpoint. InvokeModel lets you submit a prompt to generate a model response. In a terminal, run the following command:

aws bedrock-runtime invoke-model \ --model-id amazon.titan-text-express-v1 \ --body '{"inputText": "Describe the purpose of a \"hello world\" program in one line.", "textGenerationConfig" : {"maxTokenCount": 512, "temperature": 0.5, "topP": 0.9}}' \ --cli-binary-format raw-in-base64-out \ invoke-model-output-text.txt

If the command is successful, the response generated by the model is written to the invoke-model-output-text.txt file. The text response is returned in the outputText field, alongside accompanying information.

Submit a text prompt to a model and generate a text response with Converse

The following example runs the Converse operation using an Amazon Bedrock runtime endpoint. Converse lets you submit a prompt to generate a model response. We recommend using Converse operation over InvokeModel when supported, because it unifies the inference request across Amazon Bedrock models and simplifies the management of multi-turn conversations. In a terminal, run the following command:

aws bedrock-runtime converse \ --model-id amazon.titan-text-express-v1 \ --messages '[{"role": "user", "content": [{"text": "Describe the purpose of a \"hello world\" program in one line."}]}]' \ --inference-config '{"maxTokens": 512, "temperature": 0.5, "topP": 0.9}'

If the command is successful, the response generated by the model is returned in the text field, alongside accompanying information.

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.