ConverseCommand

Sends messages to the specified Amazon Bedrock model. Converse provides a consistent interface that works with all models that support messages. This allows you to write code once and use it with different models. If a model has unique inference parameters, you can also pass those unique parameters to the model.

Amazon Bedrock doesn't store any text, images, or documents that you provide as content. The data is only used to generate the response.

You can submit a prompt by including it in the messages field, specifying the modelId of a foundation model or inference profile to run inference on it, and including any other fields that are relevant to your use case.

You can also submit a prompt from Prompt management by specifying the ARN of the prompt version and including a map of variables to values in the promptVariables field. You can append more messages to the prompt by using the messages field. If you use a prompt from Prompt management, you can't include the following fields in the request: additionalModelRequestFields, inferenceConfig, system, or toolConfig. Instead, these fields must be defined through Prompt management. For more information, see Use a prompt from Prompt management .

For information about the Converse API, see Use the Converse API in the Amazon Bedrock User Guide. To use a guardrail, see Use a guardrail with the Converse API in the Amazon Bedrock User Guide. To use a tool with a model, see Tool use (Function calling) in the Amazon Bedrock User Guide

For example code, see Converse API examples in the Amazon Bedrock User Guide.

This operation requires permission for the bedrock:InvokeModel action.

To deny all inference access to resources that you specify in the modelId field, you need to deny access to the bedrock:InvokeModel and bedrock:InvokeModelWithResponseStream actions. Doing this also denies access to the resource through the base inference actions (InvokeModel  and InvokeModelWithResponseStream ). For more information see Deny access for inference on specific models .

For troubleshooting some of the common errors you might encounter when using the Converse API, see Troubleshooting Amazon Bedrock API Error Codes  in the Amazon Bedrock User Guide

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { BedrockRuntimeClient, ConverseCommand } from "@aws-sdk/client-bedrock-runtime"; // ES Modules import
// const { BedrockRuntimeClient, ConverseCommand } = require("@aws-sdk/client-bedrock-runtime"); // CommonJS import
const client = new BedrockRuntimeClient(config);
const input = { // ConverseRequest
  modelId: "STRING_VALUE", // required
  messages: [ // Messages
    { // Message
      role: "user" || "assistant", // required
      content: [ // ContentBlocks // required
        { // ContentBlock Union: only one key present
          text: "STRING_VALUE",
          image: { // ImageBlock
            format: "png" || "jpeg" || "gif" || "webp", // required
            source: { // ImageSource Union: only one key present
              bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
            },
          },
          document: { // DocumentBlock
            format: "pdf" || "csv" || "doc" || "docx" || "xls" || "xlsx" || "html" || "txt" || "md", // required
            name: "STRING_VALUE", // required
            source: { // DocumentSource Union: only one key present
              bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
            },
          },
          video: { // VideoBlock
            format: "mkv" || "mov" || "mp4" || "webm" || "flv" || "mpeg" || "mpg" || "wmv" || "three_gp", // required
            source: { // VideoSource Union: only one key present
              bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
              s3Location: { // S3Location
                uri: "STRING_VALUE", // required
                bucketOwner: "STRING_VALUE",
              },
            },
          },
          toolUse: { // ToolUseBlock
            toolUseId: "STRING_VALUE", // required
            name: "STRING_VALUE", // required
            input: "DOCUMENT_VALUE", // required
          },
          toolResult: { // ToolResultBlock
            toolUseId: "STRING_VALUE", // required
            content: [ // ToolResultContentBlocks // required
              { // ToolResultContentBlock Union: only one key present
                json: "DOCUMENT_VALUE",
                text: "STRING_VALUE",
                image: {
                  format: "png" || "jpeg" || "gif" || "webp", // required
                  source: {//  Union: only one key present
                    bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
                  },
                },
                document: {
                  format: "pdf" || "csv" || "doc" || "docx" || "xls" || "xlsx" || "html" || "txt" || "md", // required
                  name: "STRING_VALUE", // required
                  source: {//  Union: only one key present
                    bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
                  },
                },
                video: {
                  format: "mkv" || "mov" || "mp4" || "webm" || "flv" || "mpeg" || "mpg" || "wmv" || "three_gp", // required
                  source: {//  Union: only one key present
                    bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
                    s3Location: {
                      uri: "STRING_VALUE", // required
                      bucketOwner: "STRING_VALUE",
                    },
                  },
                },
              },
            ],
            status: "success" || "error",
          },
          guardContent: { // GuardrailConverseContentBlock Union: only one key present
            text: { // GuardrailConverseTextBlock
              text: "STRING_VALUE", // required
              qualifiers: [ // GuardrailConverseContentQualifierList
                "grounding_source" || "query" || "guard_content",
              ],
            },
            image: { // GuardrailConverseImageBlock
              format: "png" || "jpeg", // required
              source: { // GuardrailConverseImageSource Union: only one key present
                bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
              },
            },
          },
        },
      ],
    },
  ],
  system: [ // SystemContentBlocks
    { // SystemContentBlock Union: only one key present
      text: "STRING_VALUE",
      guardContent: {//  Union: only one key present
        text: {
          text: "STRING_VALUE", // required
          qualifiers: [
            "grounding_source" || "query" || "guard_content",
          ],
        },
        image: {
          format: "png" || "jpeg", // required
          source: {//  Union: only one key present
            bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
          },
        },
      },
    },
  ],
  inferenceConfig: { // InferenceConfiguration
    maxTokens: Number("int"),
    temperature: Number("float"),
    topP: Number("float"),
    stopSequences: [ // NonEmptyStringList
      "STRING_VALUE",
    ],
  },
  toolConfig: { // ToolConfiguration
    tools: [ // Tools // required
      { // Tool Union: only one key present
        toolSpec: { // ToolSpecification
          name: "STRING_VALUE", // required
          description: "STRING_VALUE",
          inputSchema: { // ToolInputSchema Union: only one key present
            json: "DOCUMENT_VALUE",
          },
        },
      },
    ],
    toolChoice: { // ToolChoice Union: only one key present
      auto: {},
      any: {},
      tool: { // SpecificToolChoice
        name: "STRING_VALUE", // required
      },
    },
  },
  guardrailConfig: { // GuardrailConfiguration
    guardrailIdentifier: "STRING_VALUE", // required
    guardrailVersion: "STRING_VALUE", // required
    trace: "enabled" || "disabled",
  },
  additionalModelRequestFields: "DOCUMENT_VALUE",
  promptVariables: { // PromptVariableMap
    "<keys>": { // PromptVariableValues Union: only one key present
      text: "STRING_VALUE",
    },
  },
  additionalModelResponseFieldPaths: [ // AdditionalModelResponseFieldPaths
    "STRING_VALUE",
  ],
  requestMetadata: { // RequestMetadata
    "<keys>": "STRING_VALUE",
  },
  performanceConfig: { // PerformanceConfiguration
    latency: "standard" || "optimized",
  },
};
const command = new ConverseCommand(input);
const response = await client.send(command);
// { // ConverseResponse
//   output: { // ConverseOutput Union: only one key present
//     message: { // Message
//       role: "user" || "assistant", // required
//       content: [ // ContentBlocks // required
//         { // ContentBlock Union: only one key present
//           text: "STRING_VALUE",
//           image: { // ImageBlock
//             format: "png" || "jpeg" || "gif" || "webp", // required
//             source: { // ImageSource Union: only one key present
//               bytes: new Uint8Array(),
//             },
//           },
//           document: { // DocumentBlock
//             format: "pdf" || "csv" || "doc" || "docx" || "xls" || "xlsx" || "html" || "txt" || "md", // required
//             name: "STRING_VALUE", // required
//             source: { // DocumentSource Union: only one key present
//               bytes: new Uint8Array(),
//             },
//           },
//           video: { // VideoBlock
//             format: "mkv" || "mov" || "mp4" || "webm" || "flv" || "mpeg" || "mpg" || "wmv" || "three_gp", // required
//             source: { // VideoSource Union: only one key present
//               bytes: new Uint8Array(),
//               s3Location: { // S3Location
//                 uri: "STRING_VALUE", // required
//                 bucketOwner: "STRING_VALUE",
//               },
//             },
//           },
//           toolUse: { // ToolUseBlock
//             toolUseId: "STRING_VALUE", // required
//             name: "STRING_VALUE", // required
//             input: "DOCUMENT_VALUE", // required
//           },
//           toolResult: { // ToolResultBlock
//             toolUseId: "STRING_VALUE", // required
//             content: [ // ToolResultContentBlocks // required
//               { // ToolResultContentBlock Union: only one key present
//                 json: "DOCUMENT_VALUE",
//                 text: "STRING_VALUE",
//                 image: {
//                   format: "png" || "jpeg" || "gif" || "webp", // required
//                   source: {//  Union: only one key present
//                     bytes: new Uint8Array(),
//                   },
//                 },
//                 document: {
//                   format: "pdf" || "csv" || "doc" || "docx" || "xls" || "xlsx" || "html" || "txt" || "md", // required
//                   name: "STRING_VALUE", // required
//                   source: {//  Union: only one key present
//                     bytes: new Uint8Array(),
//                   },
//                 },
//                 video: {
//                   format: "mkv" || "mov" || "mp4" || "webm" || "flv" || "mpeg" || "mpg" || "wmv" || "three_gp", // required
//                   source: {//  Union: only one key present
//                     bytes: new Uint8Array(),
//                     s3Location: {
//                       uri: "STRING_VALUE", // required
//                       bucketOwner: "STRING_VALUE",
//                     },
//                   },
//                 },
//               },
//             ],
//             status: "success" || "error",
//           },
//           guardContent: { // GuardrailConverseContentBlock Union: only one key present
//             text: { // GuardrailConverseTextBlock
//               text: "STRING_VALUE", // required
//               qualifiers: [ // GuardrailConverseContentQualifierList
//                 "grounding_source" || "query" || "guard_content",
//               ],
//             },
//             image: { // GuardrailConverseImageBlock
//               format: "png" || "jpeg", // required
//               source: { // GuardrailConverseImageSource Union: only one key present
//                 bytes: new Uint8Array(),
//               },
//             },
//           },
//         },
//       ],
//     },
//   },
//   stopReason: "end_turn" || "tool_use" || "max_tokens" || "stop_sequence" || "guardrail_intervened" || "content_filtered", // required
//   usage: { // TokenUsage
//     inputTokens: Number("int"), // required
//     outputTokens: Number("int"), // required
//     totalTokens: Number("int"), // required
//   },
//   metrics: { // ConverseMetrics
//     latencyMs: Number("long"), // required
//   },
//   additionalModelResponseFields: "DOCUMENT_VALUE",
//   trace: { // ConverseTrace
//     guardrail: { // GuardrailTraceAssessment
//       modelOutput: [ // ModelOutputs
//         "STRING_VALUE",
//       ],
//       inputAssessment: { // GuardrailAssessmentMap
//         "<keys>": { // GuardrailAssessment
//           topicPolicy: { // GuardrailTopicPolicyAssessment
//             topics: [ // GuardrailTopicList // required
//               { // GuardrailTopic
//                 name: "STRING_VALUE", // required
//                 type: "DENY", // required
//                 action: "BLOCKED", // required
//               },
//             ],
//           },
//           contentPolicy: { // GuardrailContentPolicyAssessment
//             filters: [ // GuardrailContentFilterList // required
//               { // GuardrailContentFilter
//                 type: "INSULTS" || "HATE" || "SEXUAL" || "VIOLENCE" || "MISCONDUCT" || "PROMPT_ATTACK", // required
//                 confidence: "NONE" || "LOW" || "MEDIUM" || "HIGH", // required
//                 filterStrength: "NONE" || "LOW" || "MEDIUM" || "HIGH",
//                 action: "BLOCKED", // required
//               },
//             ],
//           },
//           wordPolicy: { // GuardrailWordPolicyAssessment
//             customWords: [ // GuardrailCustomWordList // required
//               { // GuardrailCustomWord
//                 match: "STRING_VALUE", // required
//                 action: "BLOCKED", // required
//               },
//             ],
//             managedWordLists: [ // GuardrailManagedWordList // required
//               { // GuardrailManagedWord
//                 match: "STRING_VALUE", // required
//                 type: "PROFANITY", // required
//                 action: "BLOCKED", // required
//               },
//             ],
//           },
//           sensitiveInformationPolicy: { // GuardrailSensitiveInformationPolicyAssessment
//             piiEntities: [ // GuardrailPiiEntityFilterList // required
//               { // GuardrailPiiEntityFilter
//                 match: "STRING_VALUE", // required
//                 type: "ADDRESS" || "AGE" || "AWS_ACCESS_KEY" || "AWS_SECRET_KEY" || "CA_HEALTH_NUMBER" || "CA_SOCIAL_INSURANCE_NUMBER" || "CREDIT_DEBIT_CARD_CVV" || "CREDIT_DEBIT_CARD_EXPIRY" || "CREDIT_DEBIT_CARD_NUMBER" || "DRIVER_ID" || "EMAIL" || "INTERNATIONAL_BANK_ACCOUNT_NUMBER" || "IP_ADDRESS" || "LICENSE_PLATE" || "MAC_ADDRESS" || "NAME" || "PASSWORD" || "PHONE" || "PIN" || "SWIFT_CODE" || "UK_NATIONAL_HEALTH_SERVICE_NUMBER" || "UK_NATIONAL_INSURANCE_NUMBER" || "UK_UNIQUE_TAXPAYER_REFERENCE_NUMBER" || "URL" || "USERNAME" || "US_BANK_ACCOUNT_NUMBER" || "US_BANK_ROUTING_NUMBER" || "US_INDIVIDUAL_TAX_IDENTIFICATION_NUMBER" || "US_PASSPORT_NUMBER" || "US_SOCIAL_SECURITY_NUMBER" || "VEHICLE_IDENTIFICATION_NUMBER", // required
//                 action: "ANONYMIZED" || "BLOCKED", // required
//               },
//             ],
//             regexes: [ // GuardrailRegexFilterList // required
//               { // GuardrailRegexFilter
//                 name: "STRING_VALUE",
//                 match: "STRING_VALUE",
//                 regex: "STRING_VALUE",
//                 action: "ANONYMIZED" || "BLOCKED", // required
//               },
//             ],
//           },
//           contextualGroundingPolicy: { // GuardrailContextualGroundingPolicyAssessment
//             filters: [ // GuardrailContextualGroundingFilters
//               { // GuardrailContextualGroundingFilter
//                 type: "GROUNDING" || "RELEVANCE", // required
//                 threshold: Number("double"), // required
//                 score: Number("double"), // required
//                 action: "BLOCKED" || "NONE", // required
//               },
//             ],
//           },
//           invocationMetrics: { // GuardrailInvocationMetrics
//             guardrailProcessingLatency: Number("long"),
//             usage: { // GuardrailUsage
//               topicPolicyUnits: Number("int"), // required
//               contentPolicyUnits: Number("int"), // required
//               wordPolicyUnits: Number("int"), // required
//               sensitiveInformationPolicyUnits: Number("int"), // required
//               sensitiveInformationPolicyFreeUnits: Number("int"), // required
//               contextualGroundingPolicyUnits: Number("int"), // required
//             },
//             guardrailCoverage: { // GuardrailCoverage
//               textCharacters: { // GuardrailTextCharactersCoverage
//                 guarded: Number("int"),
//                 total: Number("int"),
//               },
//               images: { // GuardrailImageCoverage
//                 guarded: Number("int"),
//                 total: Number("int"),
//               },
//             },
//           },
//         },
//       },
//       outputAssessments: { // GuardrailAssessmentListMap
//         "<keys>": [ // GuardrailAssessmentList
//           {
//             topicPolicy: {
//               topics: [ // required
//                 {
//                   name: "STRING_VALUE", // required
//                   type: "DENY", // required
//                   action: "BLOCKED", // required
//                 },
//               ],
//             },
//             contentPolicy: {
//               filters: [ // required
//                 {
//                   type: "INSULTS" || "HATE" || "SEXUAL" || "VIOLENCE" || "MISCONDUCT" || "PROMPT_ATTACK", // required
//                   confidence: "NONE" || "LOW" || "MEDIUM" || "HIGH", // required
//                   filterStrength: "NONE" || "LOW" || "MEDIUM" || "HIGH",
//                   action: "BLOCKED", // required
//                 },
//               ],
//             },
//             wordPolicy: {
//               customWords: [ // required
//                 {
//                   match: "STRING_VALUE", // required
//                   action: "BLOCKED", // required
//                 },
//               ],
//               managedWordLists: [ // required
//                 {
//                   match: "STRING_VALUE", // required
//                   type: "PROFANITY", // required
//                   action: "BLOCKED", // required
//                 },
//               ],
//             },
//             sensitiveInformationPolicy: {
//               piiEntities: [ // required
//                 {
//                   match: "STRING_VALUE", // required
//                   type: "ADDRESS" || "AGE" || "AWS_ACCESS_KEY" || "AWS_SECRET_KEY" || "CA_HEALTH_NUMBER" || "CA_SOCIAL_INSURANCE_NUMBER" || "CREDIT_DEBIT_CARD_CVV" || "CREDIT_DEBIT_CARD_EXPIRY" || "CREDIT_DEBIT_CARD_NUMBER" || "DRIVER_ID" || "EMAIL" || "INTERNATIONAL_BANK_ACCOUNT_NUMBER" || "IP_ADDRESS" || "LICENSE_PLATE" || "MAC_ADDRESS" || "NAME" || "PASSWORD" || "PHONE" || "PIN" || "SWIFT_CODE" || "UK_NATIONAL_HEALTH_SERVICE_NUMBER" || "UK_NATIONAL_INSURANCE_NUMBER" || "UK_UNIQUE_TAXPAYER_REFERENCE_NUMBER" || "URL" || "USERNAME" || "US_BANK_ACCOUNT_NUMBER" || "US_BANK_ROUTING_NUMBER" || "US_INDIVIDUAL_TAX_IDENTIFICATION_NUMBER" || "US_PASSPORT_NUMBER" || "US_SOCIAL_SECURITY_NUMBER" || "VEHICLE_IDENTIFICATION_NUMBER", // required
//                   action: "ANONYMIZED" || "BLOCKED", // required
//                 },
//               ],
//               regexes: [ // required
//                 {
//                   name: "STRING_VALUE",
//                   match: "STRING_VALUE",
//                   regex: "STRING_VALUE",
//                   action: "ANONYMIZED" || "BLOCKED", // required
//                 },
//               ],
//             },
//             contextualGroundingPolicy: {
//               filters: [
//                 {
//                   type: "GROUNDING" || "RELEVANCE", // required
//                   threshold: Number("double"), // required
//                   score: Number("double"), // required
//                   action: "BLOCKED" || "NONE", // required
//                 },
//               ],
//             },
//             invocationMetrics: {
//               guardrailProcessingLatency: Number("long"),
//               usage: {
//                 topicPolicyUnits: Number("int"), // required
//                 contentPolicyUnits: Number("int"), // required
//                 wordPolicyUnits: Number("int"), // required
//                 sensitiveInformationPolicyUnits: Number("int"), // required
//                 sensitiveInformationPolicyFreeUnits: Number("int"), // required
//                 contextualGroundingPolicyUnits: Number("int"), // required
//               },
//               guardrailCoverage: {
//                 textCharacters: {
//                   guarded: Number("int"),
//                   total: Number("int"),
//                 },
//                 images: {
//                   guarded: Number("int"),
//                   total: Number("int"),
//                 },
//               },
//             },
//           },
//         ],
//       },
//     },
//     promptRouter: { // PromptRouterTrace
//       invokedModelId: "STRING_VALUE",
//     },
//   },
//   performanceConfig: { // PerformanceConfiguration
//     latency: "standard" || "optimized",
//   },
// };

ConverseCommand Input

See ConverseCommandInput for more details

Parameter
Type
Description
modelId
Required
string | undefined

Specifies the model or throughput with which to run inference, or the prompt resource to use in inference. The value depends on the resource that you use:

The Converse API doesn't support imported models .

additionalModelRequestFields
__DocumentType | undefined

Additional inference parameters that the model supports, beyond the base set of inference parameters that Converse and ConverseStream support in the inferenceConfig field. For more information, see Model parameters .

additionalModelResponseFieldPaths
string[] | undefined

Additional model parameters field paths to return in the response. Converse and ConverseStream return the requested fields as a JSON Pointer object in the additionalModelResponseFields field. The following is example JSON for additionalModelResponseFieldPaths.

[ "/stop_sequence" ]

For information about the JSON Pointer syntax, see the Internet Engineering Task Force (IETF)  documentation.

Converse and ConverseStream reject an empty JSON Pointer or incorrectly structured JSON Pointer with a 400 error code. if the JSON Pointer is valid, but the requested field is not in the model response, it is ignored by Converse.

guardrailConfig
GuardrailConfiguration | undefined

Configuration information for a guardrail that you want to use in the request. If you include guardContent blocks in the content field in the messages field, the guardrail operates only on those messages. If you include no guardContent blocks, the guardrail operates on all messages in the request body and in any included prompt resource.

inferenceConfig
InferenceConfiguration | undefined

Inference parameters to pass to the model. Converse and ConverseStream support a base set of inference parameters. If you need to pass additional parameters that the model supports, use the additionalModelRequestFields request field.

messages
Message[] | undefined

The messages that you want to send to the model.

performanceConfig
PerformanceConfiguration | undefined

Model performance settings for the request.

promptVariables
Record<string, PromptVariableValues> | undefined

Contains a map of variables in a prompt from Prompt management to objects containing the values to fill in for them when running model invocation. This field is ignored if you don't specify a prompt resource in the modelId field.

requestMetadata
Record<string, string> | undefined

Key-value pairs that you can use to filter invocation logs.

system
SystemContentBlock[] | undefined

A prompt that provides instructions or context to the model about the task it should perform, or the persona it should adopt during the conversation.

toolConfig
ToolConfiguration | undefined

Configuration information for the tools that the model can use when generating a response.

For information about models that support tool use, see Supported models and model features .

ConverseCommand Output

See ConverseCommandOutput for details

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.
metrics
Required
ConverseMetrics | undefined

Metrics for the call to Converse.

output
Required
ConverseOutput | undefined

The result from the call to Converse.

stopReason
Required
StopReason | undefined

The reason why the model stopped generating output.

usage
Required
TokenUsage | undefined

The total number of tokens used in the call to Converse. The total includes the tokens input to the model and the tokens generated by the model.

additionalModelResponseFields
__DocumentType | undefined

Additional fields in the response that are unique to the model.

performanceConfig
PerformanceConfiguration | undefined

Model performance settings for the request.

trace
ConverseTrace | undefined

A trace object that contains information about the Guardrail behavior.

Throws

Name
Fault
Details
AccessDeniedException
client

The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error, see AccessDeniedException  in the Amazon Bedrock User Guide

InternalServerException
server

An internal server error occurred. For troubleshooting this error, see InternalFailure  in the Amazon Bedrock User Guide

ModelErrorException
client

The request failed due to an error while processing the model.

ModelNotReadyException
client

The model specified in the request is not ready to serve inference requests. The AWS SDK will automatically retry the operation up to 5 times. For information about configuring automatic retries, see Retry behavior  in the AWS SDKs and Tools reference guide.

ModelTimeoutException
client

The request took too long to process. Processing time exceeded the model timeout length.

ResourceNotFoundException
client

The specified resource ARN was not found. For troubleshooting this error, see ResourceNotFound  in the Amazon Bedrock User Guide

ServiceUnavailableException
server

The service isn't currently available. For troubleshooting this error, see ServiceUnavailable  in the Amazon Bedrock User Guide

ThrottlingException
client

Your request was denied due to exceeding the account quotas for Amazon Bedrock. For troubleshooting this error, see ThrottlingException  in the Amazon Bedrock User Guide

ValidationException
client

The input fails to satisfy the constraints specified by Amazon Bedrock. For troubleshooting this error, see ValidationError  in the Amazon Bedrock User Guide

BedrockRuntimeServiceException
Base exception class for all service exceptions from BedrockRuntime service.