Both scripts use the Bedrock runtime client via Boto3.
invoke_model.py
This script demonstrates a direct model invocation that includes model-specific control tokens in theprompt. These tokens come from the model’s required input format and must be provided exactly as specified by that model.
- Instantiates a Bedrock runtime client with Boto3:
boto3.client("bedrock-runtime", region_name="us-east-1"). - Builds a JSON payload that includes a
promptwith model-specific control tokens. - Calls
invoke_modelwith the chosenmodelId. - Reads and parses the response stream and prints the generated text.
invoke_model.py:
Model-specific control tokens (for example,
"<|begin_of_text|>") are required by some providers/models to frame the input correctly. These tokens vary by model—consult the model’s documentation for the exact input format before sending requests.converse.py (unified messages format)
This script demonstrates a vendor-agnostic approach using amessages array. The unified messages structure is easier to reuse across different models and providers because it removes model-specific control tokens from your application logic.
messages format?
- Vendor-agnostic: keeps your app code consistent when switching models/providers.
- Reusable: the same
messagespayload can be re-used across different model IDs. - Inspectable: because response schemas vary by model, it’s useful to print and inspect the returned JSON to determine how to extract the generated text.
converse.py (trimmed for readability):
Response schemas vary across models and providers. Do not rely on a single fixed response field—inspect the returned JSON and map the fields your application needs (for example,
generation, content, or provider-specific properties).
- Use the control plane APIs (via the SDK or console) to configure model resources and manage the service.
- Use the runtime API (e.g.,
bedrock-runtimevia Boto3) for inference/invocations.

modelId values and payload options such as temperature, top_p, and max_gen_len.
Quick comparison: direct prompt vs unified messages
Links and references
- Boto3 documentation (Bedrock runtime)
- Amazon Bedrock — general documentation (reference the AWS docs for control plane vs runtime APIs)
- Visual Studio Code
messages format.