Modules
Elixir client for the Claude API.
Connection settings for talking to the Claude API: your API key, the base URL, and how to handle timeouts and retries.
One block of content in a message. A reply from Claude is a list of
these — usually just text, sometimes thinking or a tool call mixed in.
decode/1 reads a block's "type" field and returns the matching
struct.
A thinking step Claude redacted for safety. data is opaque and
encrypted — there's nothing to read here. Pass it back to the API
unchanged when continuing the conversation: dropping one of these from an
assistant message you echo back is a 400.
A block of text Claude generated, with any citations it attached.
One step of Claude's extended thinking. If you're continuing a
conversation that used tools, pass this block back to the API exactly as
received, signature included — don't edit or regenerate it.
A request from Claude to call one of the tools you provided. Run it with
input, then send the result back as a tool_result block on your next
message, matched to this block's id.
A content block type this version of Claudex doesn't have a struct for
yet — a server tool result, for example. Nothing is lost: raw holds the
full decoded JSON, and type is its "type" field.
An error from the Claude API, or from trying to reach it.
The Files API's record of one stored file — its id, filename, MIME type, size, and timestamps.
The Files API — upload a file once, then reference it by file_id in as
many Messages requests as you like instead of re-sending the bytes.
Splits a JSON Lines byte stream into complete lines — the format the Message Batches API uses for results.
A completed message returned by the Messages API.
The Messages API — send a conversation to Claude and get its reply.
One Message Batch.
Per-status tallies for one batch: processing, plus the four end states a
request can reach — succeeded, errored, canceled, expired.
One request's outcome in a batch: the custom_id it was submitted with
and the result it ended in.
The Message Batches API — send up to 100,000 Messages requests at once for asynchronous processing, at half the token cost.
One model your API key can use, as the Models API describes it.
The Models API — find out which models your key can use and what each one supports.
One page of results from a list endpoint.
Helpers for a stream of events from Claudex.Messages.stream!/2 or
Claudex.Messages.stream_to/3.
Folds the Claudex.Stream.Event structs a stream yields back into the
Claudex.Message they describe — the same struct
Claudex.Messages.create/2 would have returned.
The events the Messages API sends while it streams a reply.
A piece of the content block at index. The delta is a tagged tuple you
can match on directly
A new content block is starting at index. The block arrives empty — its
text, thinking, or tool input comes in the deltas that follow.
The content block at index is complete.
Top-level changes to the message once its content is done: why it stopped and the final token counts.
The first event of a stream. Carries the message shell — id, model, role, usage so far — with empty content that the later events fill in.
The last event of a stream. Nothing follows it.
A stream event this version of Claudex doesn't model yet. Nothing is lost:
raw holds the full decoded JSON and type is its "type" field, so a
new event type from the API never breaks a running stream.
The process behind Claudex.Messages.stream_to/3: it consumes a stream and
forwards each event to another process as a message.
Identifies a stream started with Claudex.Messages.stream_to/3.
Decodes a Server-Sent Events byte stream into events.
One raw Server-Sent Event: its name, its data, and the two reconnection fields the SSE spec defines.
Events Claudex emits, and a ready-made logger for them.
Turns tagged functions into tools Claude can call.
Calls a registered tool function with a decoded tool_use input map.
Raise this from a @tool function to refuse a call and tell Claude why.
Turns a function's arguments and its @spec into JSON schema properties,
in the shape the Messages API expects for a tool's input_schema.
Expands a struct module into JSON schema object properties, for the
Mod.t() references Claudex.Tool.Schema finds in a @spec that
aren't one of the built-in types.
Raised at compile time when Claudex.Tool can't turn a @spec argument
type into a JSON schema — a typespec construct Claudex doesn't map (a
function type, a bare pid(), an unrecognized Ecto field type, ...), or
a Mod.t() reference that isn't a loaded struct or Ecto schema.
Runs a tool conversation: send, run whatever Claude asks for, send the results back, repeat until it stops asking.
One exchange in a tool conversation: what Claude said, what it asked to run, and what running it produced.
Token counts for one Messages API request. input_tokens and
output_tokens are what you're billed for; the rest breaks that down
further (cache hits, server tool calls, and so on).