Elixir client for the Claude API.
Build a client with new/1, then hand it to the module for whatever you're
doing:
client = Claudex.new(api_key: "sk-ant-...")
{:ok, message} =
Claudex.Messages.create(client, %{
model: "claude-opus-5",
max_tokens: 1024,
messages: [%{role: "user", content: "Hello, Claude"}]
})
Claudex.Message.text(message)A client is a plain struct, so you can hold several at once and pass them around freely. Nothing here runs as a process or reads global state.
What's here
Claudex.Client- connection settings: API key, base URL, timeouts, retries.Claudex.Messages- the Messages API.create/2for a complete reply,stream!/2andstream_to/3to get it as it's written, andcount_tokens/2to price a request before sending it.Claudex.Stream- assemble a stream back into a message, or cancel one.Claudex.Stream.Eventhas the structs you match on while it runs.Claudex.Tool- turn a module's functions into tools Claude can call, with the JSON schema derived from their@specand@doc.Claudex.ToolRunner- run a whole tool conversation: send, run what Claude asks for, send the results back, repeat.Claudex.Models- which models your key can use, and what each supports.Claudex.Files- upload a file once, then reference it byfile_idinstead of re-sending the bytes; also how you download what Claude creates.Claudex.Messages.Batches- send up to 100,000 requests at once for asynchronous processing, at half the token cost.Claudex.Message,Claudex.ContentBlock,Claudex.Usage- what a reply is made of.Claudex.Error- every failure, with a:typeyou can match on.Claudex.Telemetry- the events the SDK emits, and a one-line logger for them when you want to see what it's doing.
Fallible functions return {:ok, result} or {:error, %Claudex.Error{}}.
The exceptions are the ! variants, which raise instead.
Summary
Functions
Shortcut for Claudex.Client.new/1.
Functions
@spec new(keyword()) :: Claudex.Client.t()
Shortcut for Claudex.Client.new/1.