View Source Anthropic.Messages.Content.Document (anthropic_community v0.5.0)
A PDF or plain-text document content block, usable anywhere a message can include content — vision-capable models can read PDFs directly. Supports four source variants:
:base64— inline PDF bytes, built viaprocess_document/3.:url— a hosted PDF, built viafrom_url/2.:text— inline plain text, built viafrom_text/2.:content— a pre-formatted string or list of content blocks (for citing structured content rather than a raw document), built viafrom_content/2.
Examples
{:ok, doc} = Anthropic.Messages.Content.Document.process_document("/path/to/report.pdf", :path)
Anthropic.Messages.create(client,
model: "claude-opus-4-8",
max_tokens: 1024,
messages: [
%{role: "user", content: [doc, %{type: "text", text: "Summarize this document."}]}
]
)
Summary
Functions
Builds a document content block from pre-formatted content — a string or a list of content-block maps — rather than a raw document. Useful for citing structured content that didn't come from an actual PDF/text file.
Builds a plain-text document content block from inline text.
Builds a document content block referencing a hosted PDF URL.
Processes a local PDF (binary data, a file path, or an already-base64-encoded string) into a base64 document content block.
Types
Functions
@spec from_content(String.t() | [map()], build_opts()) :: t()
Builds a document content block from pre-formatted content — a string or a list of content-block maps — rather than a raw document. Useful for citing structured content that didn't come from an actual PDF/text file.
@spec from_text(String.t(), build_opts()) :: t()
Builds a plain-text document content block from inline text.
@spec from_url(String.t(), build_opts()) :: t()
Builds a document content block referencing a hosted PDF URL.
@spec process_document(binary() | String.t(), input_type(), build_opts()) :: process_output()
Processes a local PDF (binary data, a file path, or an already-base64-encoded string) into a base64 document content block.
Options
:title— optional document title shown to the model.:context— optional context text shown to the model alongside the document.:citations— optional citations config map, e.g.%{enabled: true}.:cache_control— optionalAnthropic.CacheControlmap.