Formatting Requests for Bedrock and SageMaker AI
This lesson explains the request formats a developer must know, since a malformed request fails with a validation error and a well-formed but poorly structured one wastes tokens or confuses the model.
Learning outcomes
After completing this lesson, you will be able to:
- Format Converse API messages and content blocks.
- Use InvokeModel native formats.
- Format SageMaker AI endpoint payloads.
- Follow conversation formatting rules such as alternating roles.
The Converse API format
The Converse API uses one format for all supported models. messages is a list of turns, each with a role of user or assistant and a list of content blocks. Content blocks can be text, image (format and bytes or an S3 location), document (for example a PDF with a name), video for supported models, toolUse and toolResult, and cachePoint markers for prompt caching. The system field holds system prompts separately, and inferenceConfig holds maxTokens, temperature, topP and stopSequences.
response = brt.converse(
modelId="us.amazon.nova-pro-v1:0",
system=[{"text": "You are a claims assistant. Answer in under 120 words."}],
messages=[
{"role": "user", "content": [
{"document": {"format": "pdf", "name": "policy", "source": {"bytes": policy_pdf}}},
{"text": "Is water damage from a burst pipe covered?"},
]},
],
inferenceConfig={"maxTokens": 300, "temperature": 0.2},
)The following diagram shows the parts of a Converse request and response.

InvokeModel and native formats
InvokeModel sends the provider's native request body as JSON and returns the native response. Each model family has its own body: for example, Anthropic models use a messages body with an anthropic_version field and max_tokens, Amazon Nova uses messages with an inferenceConfig object, and embedding models take inputText and return an embedding array. InvokeModel is needed for models or features that Converse does not cover, such as embedding models and some image generation models, but code written for one provider's body does not work for another.
Converse, InvokeModel or InvokeEndpoint?
SageMaker AI endpoint payloads
A SageMaker AI endpoint accepts whatever format its serving container defines, sent with InvokeEndpoint or InvokeEndpointWithResponseStream and a matching ContentType. Large model inference containers typically accept {"inputs": "...", "parameters": {"max_new_tokens": 256, "temperature": 0.2}}, and many also offer an OpenAI-compatible chat completions schema with messages. When a raw text-completion interface is used with a chat model, the application must apply the model's chat template (special tokens that mark system, user and assistant turns); otherwise output quality drops sharply.
Conversation formatting rules
Chat models are trained on conversations with a particular structure, and requests that break it are either rejected or produce poor answers. Dialog applications must therefore follow a few rules. Turns are kept in chronological order, and the conversation starts with a user turn. User and assistant roles alternate; consecutive messages with the same role are rejected by the API or must be merged. Standing instructions belong in the system prompt rather than being repeated in each user turn.
Tool use adds a further rule: when the assistant's turn contains a tool use request, the result of the tool is returned in the following user turn, linked to the request by its tool use ID. Finally, because the whole history is sent with every request, long conversations must be trimmed, for example by keeping the most recent turns, or summarised, so they stay within the context window and do not increase cost with every turn. The following table summarises the request formats.
| Interface | Request structure | Use for |
|---|---|---|
| Converse / ConverseStream | messages, system, inferenceConfig, toolConfig | Provider-neutral chat, tools, documents and images |
| InvokeModel | Provider-specific JSON body | Embeddings, native features, models without Converse support |
| Batch inference | JSONL records with recordId and modelInput | Large offline jobs |
| SageMaker InvokeEndpoint | Container-defined JSON (for example inputs and parameters) | Self-hosted models |
The following diagram compares the stored history with the corrected one.

A rejected Converse request
A failing chat request
After adding a feature that stores each assistant reply twice, chat requests fail with ValidationException. The logs show messages with roles user, assistant, assistant, user.
The Converse API requires alternating roles, and two consecutive assistant messages violate that rule. The fix is to deduplicate history when building the messages list (or merge consecutive same-role content), and to validate the conversation structure before each call.
Which API must be used to call an embedding model on Bedrock?
Show answer
InvokeModel, with the provider-specific body. Converse is for conversational text and multimodal models.
Exam Tips
Remember for the exam
- Converse: messages with roles and content blocks; system and inferenceConfig separate.
- InvokeModel: provider-specific body; required for embedding models.
- Batch inference input: JSONL with recordId and modelInput.
- Alternate user and assistant roles; tool results go in a user turn.