View Source Anthropic.Messages.Content (anthropic_community v0.5.0)
Dispatches between the typed content-block structs (Text, ToolUse, ToolResult,
Thinking, RedactedThinking, Image, Document, ServerToolUse, and the
*ToolResult server-tool-result blocks) and their wire JSON shape.
Response and request content blocks share the same struct types: a %Text{} decoded
from a response round-trips through to_json/1 unchanged if replayed into a later
request (e.g. in a tool-use loop), so there is no separate request-param/response-type
split to maintain.
Content-block types the API adds in the future (e.g. computer-use/MCP tool-result blocks,
not yet modeled here) decode as plain maps rather than raising, so callers on an older
version of this library keep working — pattern-match on %{"type" => ...} alongside the
typed structs to handle them.
Summary
Functions
Encodes a content-block struct (or a plain map, passed through unchanged) back to its wire shape.
Types
@type t() :: Anthropic.Messages.Content.Text.t() | Anthropic.Messages.Content.ToolUse.t() | Anthropic.Messages.Content.ToolResult.t() | Anthropic.Messages.Content.Thinking.t() | Anthropic.Messages.Content.RedactedThinking.t() | Anthropic.Messages.Content.Image.t() | Anthropic.Messages.Content.Document.t() | Anthropic.Messages.Content.ServerToolUse.t() | Anthropic.Messages.Content.WebSearchToolResult.t() | Anthropic.Messages.Content.WebFetchToolResult.t() | Anthropic.Messages.Content.CodeExecutionToolResult.t() | Anthropic.Messages.Content.BashCodeExecutionToolResult.t() | Anthropic.Messages.Content.TextEditorCodeExecutionToolResult.t()
Functions
Encodes a content-block struct (or a plain map, passed through unchanged) back to its wire shape.