View Source API Reference anthropic_community v0.5.0
Modules
The Batches resource (Message Batches API): submit up to 100k Messages.create/2-shaped
requests for asynchronous, discounted bulk processing.
Builds cache_control maps for prompt
caching. Attach the
result to a content block's :cache_control field
(Anthropic.Messages.Content.{Text, Image, ToolUse, ToolResult}) to mark it as a cache
breakpoint.
Holds connection-level configuration for the Anthropic API: credentials, base URL,
API version, retry policy, and transport pool. Built once via new/1 and passed
explicitly as the first argument to every resource function (Anthropic.Messages.create/2,
Anthropic.Models.list/1, etc.) rather than held implicitly in process/application state.
Unified error type returned as {:error, %Anthropic.Error{}} from every resource
function, and raised by the ! bang variants (this struct is a defexception).
The Files resource: upload a file once and reference it by file_id in a later message
instead of inlining base64 data.
The single internal request-sending layer. Anthropic.Messages.create/2 (via post/3),
Anthropic.Models/Anthropic.Batches (via get/2, post/3, and delete/2), and
Anthropic.Messages.stream/2 (via stream/3) all funnel through this module, so
header-building, retry/backoff, and error-mapping are defined exactly once and never
diverge between request styles.
Behaviour for the underlying HTTP transport. Defaults to Finch, swappable via
Application.get_env(:anthropic, :http_adapter, Finch) — used in tests to mock the
network boundary while exercising the real retry/backoff/SSE-parsing logic in
Anthropic.HTTPTransport.
Minimal multipart/form-data body encoder (RFC 7578) — just enough for file uploads
(Anthropic.Files.create/2), not a general-purpose multipart library.
Exponential backoff + jitter, shared by both plain requests (HTTPTransport.post/3) and
the initial connection attempt of HTTPTransport.stream/3, so retry behavior never
diverges between the two.
Minimal line-buffering Server-Sent-Events parser. Consumes raw byte chunks (as delivered
by Finch.stream/5's :data callback) and emits complete {event_name, data} frames,
buffering partial lines and partial frames across chunk boundaries.
The Messages resource: create/2 for a single request/response turn, stream/2 for a
server-sent-events stream of the same. See Anthropic.ToolRunner for driving a full
tool-use agentic loop on top of create/2.
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.
The result of a bash server-tool call. content is the raw decoded JSON payload (a
stdout/stderr/return-code map, or an error map) — not deeply typed; see the bash tool
docs for its
shape.
Decodes a raw citation object (as found in a Text content block's :citations list)
into one of the five typed citation-location structs, discriminated on "type":
CharLocation, PageLocation, ContentBlockLocation, SearchResultLocation,
WebSearchResultLocation.
A citation to a character range within a plain-text document.
A citation to a block range within a content-source document (Document.from_content/2).
A citation to a page range within a PDF document.
A citation to a block range within a search_result content block.
A citation to a web search result.
The result of a code_execution server-tool call. content is the raw decoded JSON
payload (a stdout/stderr/return-code map, or an error map) — not deeply typed; see the
code execution tool
docs
for its shape.
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
Validates, processes, and converts images into Anthropic.Messages.Content.Image request
content blocks for use in a user message, per the vision
guide.
A redacted-thinking content block (opaque, encrypted thinking content).
A server tool invocation the API executed on Claude's behalf (web search, web fetch, code
execution, bash, text editor). Unlike Anthropic.Messages.Content.ToolUse, this never
needs a client-side execute/1 dispatch — the matching *ToolResult block already
carries the result within the same turn, and Anthropic.ToolRunner/Message.tool_uses/1
don't match on this struct, so it's simply along for the ride when replaying message
history.
A plain text content block.
The result of a text_editor server-tool call (view/create/str_replace). content is
the raw decoded JSON payload — not deeply typed, since its shape varies by which editor
command was run; see the text editor tool
docs for
its shape.
An extended-thinking content block.
The result of executing a tool, sent back to the API as a tool_result content block
inside a user message. tool_use_id must match the id of the corresponding
Anthropic.Messages.Content.ToolUse block the assistant requested.
A tool invocation requested by the assistant, as a native tool_use content block.
The result of a web_fetch server-tool call. content is the raw decoded JSON payload
(a fetched-document map, or an error map) — not deeply typed; see the web fetch tool
docs for
its shape.
The result of a web_search server-tool call. content is the raw decoded JSON payload
(a list of search-result maps, or an error map) — not deeply typed, since the API defines
several nested result/error sub-shapes; see the web search tool
docs for
its shape.
A message returned by the Anthropic Messages API — the {:ok, message} result of
Anthropic.Messages.create/2 or the final fold of Anthropic.Messages.stream/2.
Builds and validates the wire params for a POST /v1/messages request from a Client and
caller-supplied options. This is the single place where client defaults, call-site opts,
and wire-shape validation are merged for Anthropic.Messages.create/2 and stream/2.
Folds a stream of Anthropic.Messages.StreamEvent structs (as produced by
Anthropic.Messages.stream/2) into a final Anthropic.Messages.Message — the streaming
equivalent of Anthropic.Messages.create/2's return value.
Decodes a raw SSE frame ({event_name, data}, as produced by Anthropic.HTTPTransport.SSE)
into a typed event struct. See Anthropic.Messages.StreamAccumulator for folding a stream
of these into a final Anthropic.Messages.Message.
An incremental update to the content block at index. delta is the raw wire delta map,
one of %{"type" => "text_delta", "text" => ...}, %{"type" => "input_json_delta", "partial_json" => ...}, %{"type" => "thinking_delta", "thinking" => ...}, or
%{"type" => "signature_delta", "signature" => ...}.
Announces a new content block at index, with its (still-partial) initial value.
Marks the content block at index as complete.
A terminal error delivered as the final element of the event stream — either an in-band
event: error frame from the API, or a transport-level failure (connection drop, decode
failure, timeout) surfaced this way instead of raising mid-Stream.
Top-level message fields that change at the end of a turn (stop_reason, stop_sequence) plus cumulative usage.
The first event of a stream: a partial Message (empty content, incomplete usage).
The final event of a successful stream.
A keep-alive event with no payload.
The Models resource: list and retrieve available Claude models.
Builds output_config request-param maps for structured
outputs. Pass
the result as the :output_config option to Anthropic.Messages.create/2 or stream/2
to constrain Claude's response to a given JSON Schema.
Auto-paginating Stream helper for cursor-based list endpoints (Anthropic.Models.list_all/2,
Anthropic.Batches.list_all/2). Walks pages forward via after_id/last_id, fetching
each page lazily as the stream is consumed, until the API reports has_more: false (or a
page comes back with no last_id to continue from).
Builds thinking request-param maps for extended
thinking. Pass
the result as the :thinking option to Anthropic.Messages.create/2 or stream/2.
Drives Anthropic.Messages.create/2 in a loop, executing tool calls the assistant
requests until it produces a final answer (stop_reason other than "tool_use").
Behaviour for user-defined tools, driving the native Anthropic tools API field (JSON
Schema input_schema) rather than a hand-rolled prompt-injection protocol.
Builds the bash
server tool definition. Pass the result inside the :tools list to
Anthropic.Messages.create/2 — Claude runs shell commands server-side in a sandbox and
the result comes back as a %Anthropic.Messages.Content.BashCodeExecutionToolResult{}
block; no client-side execute/1 needed.
Builds the code execution
server tool definition. Pass the result inside the :tools list to
Anthropic.Messages.create/2 — Claude runs code server-side in a sandbox and the result
comes back as a %Anthropic.Messages.Content.CodeExecutionToolResult{} block; no
client-side execute/1 needed.
Builds the memory
server tool definition. Pass the result inside the :tools list to
Anthropic.Messages.create/2 — Claude manages a persistent file-based memory store
server-side; no client-side execute/1 needed.
Builds the text editor
server tool definition. Pass the result inside the :tools list to
Anthropic.Messages.create/2 — Claude views/creates/edits files server-side in a sandbox
and the result comes back as a
%Anthropic.Messages.Content.TextEditorCodeExecutionToolResult{} block; no client-side
execute/1 needed.
Builds the web fetch
server tool definition. Pass the result inside the :tools list to
Anthropic.Messages.create/2 — Claude fetches the URL server-side and the result comes
back as a %Anthropic.Messages.Content.WebFetchToolResult{} block; no client-side
execute/1 needed.
Builds the web search
server tool definition. Pass the result inside the :tools list to
Anthropic.Messages.create/2 — Claude performs the search server-side and the result
comes back as a %Anthropic.Messages.Content.WebSearchToolResult{} block; there is no
client-side execute/1 to implement, unlike Anthropic.Tools-based custom tools.