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

Functions

@spec from_json(map()) :: t() | map()
@spec to_json(t() | map()) :: map()

Encodes a content-block struct (or a plain map, passed through unchanged) back to its wire shape.