Documentation / guides
Bedrock Converse
Encode Bedrock Converse tagged content, tools, documents, and terminal usage.
codec/bedrockconverse speaks the model-neutral Converse request and response
shape. The model ID is deliberately absent from the body because Bedrock puts
it in the URL path.
Request
converseContentBlock is a tagged union with exactly one of Text, Image,
Document, Audio, ReasoningContent, ToolUse, or ToolResult set. Audio
requires inline bytes and a media type naming an AudioFormat member; an S3
source is decode-direction only. System content
supports text only. Images require inline bytes and one of jpeg, png, gif, or
webp. Documents can be bytes or text, require a valid name, and require a text
block in the same message. Tool schemas are validated as JSON objects and
required tool choice becomes toolChoice.any.
body, err := bedrockconverse.EncodeRequest(req)
if err != nil {
var unsupported *bedrockconverse.UnsupportedBlockError
if errors.As(err, &unsupported) {
fmt.Println(unsupported.Reason)
}
return err
}
_ = body
Validation
The decoder rejects missing output.message, wrong assistant role, union
blocks with zero or multiple variants, invalid tool objects, invalid document
names, and unsupported media formats. EncodeCountTokensInput keeps only the
conversation, system, tools, and additional model fields accepted by the
CountTokens operation. Response usage maps Bedrock’s read/write cache fields
to normalized usage; no request-side cache marker is emitted by this codec.
Source and proof
bedrockconverse/types.gobedrockconverse/encode.gobedrockconverse/decode.gobedrockconverse/stream_test.go
Run go test ./codec/bedrockconverse.