Skip to documentation
Documentation navigation

Documentation navigation

Documentation / guides

Content translation

Map core content blocks and message roles into each dialect's vocabulary.

developer

core/content supplies the closed block vocabulary. A codec preserves block order and returns typed errors for a block it cannot represent.

Blocks

Neutral blockOpenAI ChatResponsesAnthropicGeminiBedrock Converse
TextBlockstring or text partoutput_text or input_texttexttext parttext
ImageBlockimage_urlinput_image URL/data URIimage URL/base64inlineData or fileDatainline bytes only
DocumentBlockfile part with a base64 data URIinput_file partdocument block with a titleinlineData part plus a text partdocument bytes/text
AudioBlockinput_audio partunsupported; the input union has no audio memberUnsupportedAudioErrorinlineData partConverse audio block
RefusalBlockassistant refusal memberrefusal part on the response direction; request replay is UnsupportedBlockErrorUnsupportedRefusalErrorunsupportedunsupported
ThinkingBlockomitted on requestreasoning itemthinkingthought text partreasoningContent text
ToolUseBlockassistant tool_callsfunction_call itemtool_usefunctionCalltoolUse
ToolResultBlocktext-only tool messagetext-only function_call_outputtool_resultfunctionResponsetoolResult

Images sourced from bytes are base64 encoded by JSON dialects that require a URL or base64 field. Bedrock rejects URL images and requires one of its supported inline formats. Tool and result inputs are JSON objects; empty input is normalized to {} where the native API requires an object.

Unsupported

Unsupported content is not silently discarded. For example, an OpenAI Chat tool result containing an image returns *openaiapi.UnsupportedBlockError, while Bedrock returns *bedrockconverse.UnsupportedBlockError with a reason. Use errors.As instead of matching error strings.

var blockErr *anthropicapi.UnsupportedBlockError
if errors.As(err, &blockErr) {
	log.Printf("choose a representable block: %s", blockErr.Block)
}

Anthropic splits the representation boundary across several typed errors. UnsupportedBlockError is the fallback for a block the dialect does not model at all, while audio yields UnsupportedAudioError, a refusal UnsupportedRefusalError, an unrepresentable document UnsupportedDocumentError, and an out-of-enum image media type UnsupportedImageMediaTypeError.

Source and proof

Run go test ./codec/....

← back to documentation