Skip to main content
This lesson shows how to make inference requests with the Amazon Bedrock Runtime client and compares the two primary ways to call foundation models:
  • InvokeModel — a low-level, model-specific API that gives full control over the request body.
  • Converse — a higher-level, standardized, message-based API designed for chat and multi-turn interactions.
Both have use cases depending on whether you need model-specific features or a portable chat-style interface.

InvokeModel

InvokeModel is a low-level API that accepts a model-specific JSON payload. Use it when you need fine-grained control (for example, image-generation options, custom token settings, or other model-specific fields). Because the payload is tailored to the model, it is not guaranteed to be portable across different models or vendors. Example (InvokeModel):
Key points:
  • Supply modelId (the model’s programmatic identifier).
  • The body is a JSON string (commonly produced by json.dumps() from a Python dict).
  • Payload structure and supported fields are model-specific.

Converse

Converse is a high-level API built around a unified messages structure. Each message contains a role (for example, "user", "assistant", or "system") and content items (for example, {"type": "text", "text": "..."}). This abstraction makes payloads portable across models and vendors, simplifying multi-turn and chat-style workflows. Example (Converse):
Key points:
  • Use messages with roles ("user", "system", "assistant").
  • Content items typically include a type (such as "text") and the payload text.
  • Converse is ideal for conversational flows, multi-turn sessions, or instruction-style prompts.
  • The unified format improves portability between models and cloud vendors.

When to use which

  • Use InvokeModel when you need model-specific parameters or nonstandard inputs.
  • Use Converse for chat, multi-turn interactions, or when you want a portable, standardized message format.
Quick comparison:
A slide titled "Workflow: Invoke vs Converse" showing a comparison table of features like API style, input format, cross-model compatibility, and best-suited use cases. It contrasts invoke_model() as low-level with model-specific JSON for full control, and Converse() as chat-oriented with a standardized message format for conversational apps.

Full example: InvokeModel with boto3 (Python)

The following concise example demonstrates creating a Bedrock Runtime client, building a model-specific body, calling invoke_model(), and decoding the response. Note that the SDK returns a streaming body that must be read and decoded before parsing JSON.
Always decode the response["body"] streaming object before json.loads() — otherwise you will attempt to parse raw bytes and encounter errors.
What this code does:
  • Imports json and boto3.
  • Constructs a Bedrock Runtime client for us-east-1.
  • Builds a model-specific body containing prompt and max_tokens.
  • Calls invoke_model() with modelId and the serialized body.
  • Reads and decodes the streaming response body and deserializes the JSON result.

Best practices and tips

  • Prefer Converse for conversational agents and when you want portability across models or cloud vendors.
  • Use InvokeModel when needing special model features (image inputs, advanced sampling parameters, token controls, or vendor/model-specific flags).
  • Always read and decode streaming responses before parsing JSON.
  • Verify the required/requested fields for the target model in its documentation—field names and structures vary per model.
Model-specific fields in InvokeModel are not standardized; sending the wrong structure can cause errors or unexpected outputs. Consult the model’s documentation for the exact request format.

Summary

  • InvokeModel: low-level, model-specific JSON payloads; use for full control and nonstandard inputs.
  • Converse: high-level, standardized messages format; use for conversational flows and cross-model portability.

Watch Video