

# Run example Amazon Bedrock API requests with the AWS Command Line Interface
<a name="getting-started-api-ex-cli"></a>

This section guides you through trying out some common operations in Amazon Bedrock using the AWS Command Line Interface 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**
+ You have an AWS account and a user or role with authentication set up and the necessary permissions for Amazon Bedrock. Otherwise, follow the steps at [Get started with the API](getting-started-api.md).
+ You've installed and set up authentication for the AWS CLI. To install the AWS CLI, follow the steps at [Install or update to the latest version of the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html). Verify that you've set up your credentials to use the CLI by following the steps at [Get credentials to grant programmatic access](getting-started-api.md#gs-grant-program-access).

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

**Topics**
+ [

## List the foundation models that Amazon Bedrock has to offer
](#getting-started-api-ex-cli-listfm)
+ [

## Submit a text prompt to a model and generate a text response with InvokeModel
](#getting-started-api-ex-cli-invoke-text)
+ [

## Submit a text prompt to a model and generate a text response with Converse
](#getting-started-api-ex-cli-converse)

## List the foundation models that Amazon Bedrock has to offer
<a name="getting-started-api-ex-cli-listfm"></a>

The following example runs the [ListFoundationModels](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_ListFoundationModels.html) operation using the AWS CLI. `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
```

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
<a name="getting-started-api-ex-cli-invoke-text"></a>

The following example runs the [InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html) operation using the AWS CLI. `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
<a name="getting-started-api-ex-cli-converse"></a>

The following example runs the [Converse](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html) operation using the AWS CLI. `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.