A small client-side helper for multi-turn Messages conversations.
This is NOT a server resource — the Anthropic Messages API is stateless
and each request carries the full history. Conversation just holds the
accumulated messages plus optional system prompt and default request
options so you don't have to rebuild the payload yourself.
Example
convo =
ReqAnthropic.Conversation.new(
model: "claude-haiku-4-5",
max_tokens: 512,
system: "You are a concise assistant."
)
|> ReqAnthropic.Conversation.user("Tell me about Elixir.")
{:ok, convo} = ReqAnthropic.Conversation.send(convo)
IO.puts(ReqAnthropic.Conversation.last_text(convo))
convo =
convo
|> ReqAnthropic.Conversation.user("What about OTP?")
{:ok, convo} = ReqAnthropic.Conversation.send(convo)
Summary
Functions
Append an assistant message (e.g. from a prior response).
Return the plain text from the most recent assistant reply, if any.
Build a new conversation. :model is required. Any other keyword is
forwarded to ReqAnthropic.Messages.create/1 on each send/2 call,
which includes :api_key, :max_tokens, :temperature, :tools,
:metadata, :system, etc.
Send the conversation to the Messages API and return an updated
Conversation with the assistant's reply appended.
Append a user message. content may be a string or a content-block list.
Types
Functions
Append an assistant message (e.g. from a prior response).
Return the plain text from the most recent assistant reply, if any.
Build a new conversation. :model is required. Any other keyword is
forwarded to ReqAnthropic.Messages.create/1 on each send/2 call,
which includes :api_key, :max_tokens, :temperature, :tools,
:metadata, :system, etc.
Send the conversation to the Messages API and return an updated
Conversation with the assistant's reply appended.
extra_opts are merged over the conversation's stored request options,
so you can override :max_tokens, :temperature, etc. on a per-turn
basis.
Append a user message. content may be a string or a content-block list.