BeamWeaver Anthropic
BeamWeaver includes a direct Anthropic Messages API provider under BeamWeaver.Anthropic.
Haiku 5.5 and Sonnet 5.5
Use anthropic:claude-haiku-5-5 or anthropic:claude-sonnet-5-5. Both profiles support a 1M-token context window, 128K output, text/image/PDF inputs, structured output with tools, parallel tool calls, streaming, and effort levels from :low through :max. Batch-only 300K output and its required beta are recorded as metadata; the Messages adapter retains the 128K limit.
Token prices in USD per million tokens:
| Token category | Haiku prompt <= 100K | Haiku prompt > 100K | Sonnet |
|---|---|---|---|
| Standard input | $0.10 | $0.50 | $2.00 |
| Standard output | $0.50 | $2.50 | $10.00 |
| Cache read | $0.01 | $0.05 | $0.10 |
| 5-minute cache write | $0.125 | $0.625 | $2.50 |
| 1-hour cache write | $0.20 | $1.00 | $4.00 |
| Batch input | $0.05 | $0.25 | $1.00 |
| Batch output | $0.25 | $1.25 | $5.00 |
Haiku's higher rates apply to the entire request above 100K prompt tokens, including output and cache categories. UsageCost.calculate/3 selects standard rates from normalized total input tokens, including cache reads and writes. Batch rates are profile metadata; the cost calculator does not choose a processing tier. Sonnet has no long-prompt surcharge. Both have a 512-token cache minimum. US-only inference adds 10%. Sonnet cache reads fell from $0.20 to $0.10 on October 7; dated estimates retain the earlier rate.
Adaptive thinking is the default, at :medium effort for Haiku and :high for Sonnet. Haiku permits thinking: %{type: :disabled} through :high effort and accepts forced tool choice, which suppresses thinking for that response. Sonnet rejects disabled thinking and forced tools; use thinking: %{type: :between_tools} through :high to turn off up-front thinking while retaining progress updates between tools. At :xhigh and :max, use adaptive thinking on either model. Manual budget_tokens thinking is rejected before both generation and token counting. Per-message effort cannot change while Haiku thinking is disabled or Sonnet uses between_tools; adaptive thinking permits those changes. Prefix-binding controls likewise require adaptive thinking.
Omit sampling controls. The new profiles accept only temperature: 1 or top_p: 0.99, separately, and reject every top_k value. In particular, top_p: 1 is invalid. Assistant prefills and legacy computer_20* declarations are rejected; use Tools.computer_toolset/1. Toolset member calls retain toolset_name for replay; provide that name on their tool-result blocks too. Haiku does not support server-side fallback or Priority Tier. Sonnet 5.5 rejects advisor tools configured with Opus 4.8, Opus 4.7, or Sonnet 5; use Opus 5.5 or Opus 5 as the advisor instead. For migration details, see
Haiku migration
and
Sonnet migration
.
Thinking text defaults to omitted, so a signed thinking block may have an empty thinking string. Preserve the complete block when replaying it. Set thinking: %{type: :adaptive, display: :summarized} for summaries or display: :updates for progress updates; BeamWeaver infers the updates beta. Thinking signatures are bound to the conversation prefix and the producing account. Keep history append-only and replay through the producing or linked account. With adaptive thinking, use block_binding: %{prefix_mismatch_behavior: :drop_block} when intentionally editing history; BeamWeaver infers its beta header. See
thinking
. The newer tokenizer produces roughly 30% more tokens for the same text than Haiku 4.5; recount through ChatModel.count_tokens/3 with the new model ID.
Implemented
-
BeamWeaver.Anthropic.ChatModelimplementsBeamWeaver.Core.ChatModel. -
BeamWeaver.Anthropic.Toolsrenders custom tools and Anthropic server-side tool declarations. -
Requests go through
BeamWeaver.Transport, so tests can run against fake or replay transports without live credentials. -
Anthropic namespace constructors load defaults from
config :beam_weaver, :anthropic; put any OS environment reads in yourconfig/runtime.exs. Custom routing uses explicit:endpointand:count_tokens_endpointoptions. -
BeamWeaver messages become Anthropic
messagesplus top-levelsystem. -
Tool result messages become user-role
tool_resultblocks. -
Assistant
tool_callsbecome Anthropictool_usecontent blocks. -
Tool-call IDs are normalized at the Anthropic provider boundary. Existing Anthropic
toolu_*IDs are preserved, and cross-provider call IDs are mapped deterministically to Anthropic-safe IDs without mutating BeamWeaver's native message structs. -
Text, image, file/document, thinking, redacted thinking, citations, server tool calls/results, and unknown provider blocks are preserved where possible.
-
Responses become assistant messages with normalized usage metadata, cache token details, response metadata, and extracted tool calls.
-
Streaming SSE bodies are parsed into text deltas, lifecycle events, typed stream envelopes, and reconstructed final assistant messages. Signed thinking deltas and fragmented tool inputs retain their block state across transport batches; signed thinking is assembled into one provider-faithful replay block.
-
The token counting endpoint is exposed through
ChatModel.count_tokens/3. -
Checked-in model profiles cover Claude Fable 5.1, Claude Mythos 5.1, Claude Opus 5.5, Claude Sonnet 5.5, Claude Haiku 5.5, Claude Opus 5, Claude Sonnet 5, Claude Fable 5, Claude Mythos 5, current Claude Opus 4.8/4.7/4.6/4.5/4.1, Claude Sonnet 4.6/4.5, and Claude Haiku 4.5 models, with a permissive fallback for future
claude-*models. -
Deprecated or retired Claude IDs return tagged
:deprecated_modelerrors with:replacement,:expected, and retirement metadata instead of falling through to the family fallback. -
claude-opus-4-1-20250805is retired as of August 5, 2026 and resolves to a tagged replacement error namingclaude-opus-4-8; it is no longer an active checked-in profile. -
Request builders include Anthropic spec fields such as
:cache_control,:compaction,:container,:metadata,:service_tier,:diagnostics,:speed,:user_profile_id,:inference_geo,:context_management,:mcp_servers,:fallbacks,:fallback_credit_token,:thinking, and:output_config. User-profile attribution is sent as theanthropic-user-profile-idheader, never as a JSON request field.:workspace_idlikewise becomes theanthropic-workspace-idheader for Messages and token counting; the response workspace header is preserved in normalized metadata. -
Claude Opus 5, Claude Sonnet 5, Claude Opus 4.7, and later models follow Anthropic's current request restrictions: non-
1.0:temperature, any:top_k,:top_pbelow0.99, and non-adaptive enabled:thinkingfail before the transport call. -
Claude Opus 5 uses adaptive thinking by default and supports
:low,:medium,:high,:xhigh, and:maxeffort. Explicitly disabled thinking is rejected at:xhighand:max. -
Claude Fable 5.1 and invite-only Claude Mythos 5.1 have 1M-token context windows, 128K output limits, the full effort ladder, and always-on adaptive thinking. BeamWeaver rejects disabled thinking and forced
:anyor named tool choices before both Messages and count-tokens requests;:autoand:noneremain supported. -
Fable 5.1 and Mythos 5.1 do not normally support final assistant-message prefills. A refusal's
fallback_credit_tokencan authorize the documented partial-response continuation form when structured output and forced tool choice are not active. Their thinking blocks are bound to the exact conversation prefix and must be replayed append-only; earlier Claude models cannot consume them. Applications that intentionally edit history can use thethinking-binding-controls-2026-08-01beta and setprefix_mismatch_behaviorto"drop_block"; BeamWeaver infers the beta header from this request option. Built-in summarization, compact-conversation, and local context-editing middleware automatically strip carried reasoning blocks when they rewrite prior history. Applications that vary system prompts or tool definitions between calls should use the samedrop_blockcontrol because those values also participate in the bound prefix. -
Fable 5.1 and Mythos 5.1 use a 512-token prompt-cache minimum and $0.25 per million cache-read tokens, alongside current standard, cache-write, and batch pricing metadata.
-
Claude Opus 5.5 uses always-on adaptive thinking, defaults to
:mediumeffort, and rejects disabled/manual-budget thinking and forced tool choice. On the direct Claude API it also rejects legacycomputer_20*declarations; useTools.computer_toolset/1. Its 1M context, 128K output, 512-token cache minimum, and $4 input / $20 output prices are recorded in the profile. See the Opus 5.5 model page and migration guide . -
On-demand compaction sends
compaction: %{type: :summarize}with the requiredcompact-2026-09-04beta header. The signed response block can be replayed unchanged at the start of later history; replay also infers the beta header. BeamWeaver exposes the compaction iteration's token usage, since Anthropic reports zero top-level tokens for that response. See Anthropic's compaction guide . Runmix run examples/anthropic_opus55_compaction.exswith an Anthropic API key to check signed replay, workspace selection, and inline tool use live. -
Mid-conversation
tool_additionblocks with inline definitions infer theinline-tools-2026-09-15beta header. Replayedmcp_tool_listingblocks retain the listed schemas and infermcp-client-2026-09-15; anmcp_toolsetdeclaration with a pinnedtoolslist uses that header too. -
Tools.web_fetch/1passes through the currenturl_sourcesconfiguration, including user-input and tool-result filters. -
Opus 5 supports mid-conversation system messages and beta tool-change blocks. Such system messages can carry
clear_atand per-turnoutput_config.effortin message metadata. BeamWeaver infers the corresponding beta headers. Server-side fallbacks accept either a model list or:default, with the matching beta header inferred. -
Server-tool helpers default to Anthropic's current schema revisions for web search/fetch and code execution. Browser and computer toolsets are available through
Tools.browser_toolset/1andTools.computer_toolset/1. -
Anthropic does not expose web fetch or Priority Tier on Opus 5. BeamWeaver rejects
BeamWeaver.Anthropic.Tools.web_fetch/1for that profile before transport. -
Claude Sonnet 5 supports thinking levels through adaptive thinking: use
thinking: %{type: :adaptive}witheffort: :high,:xhigh, or:max. BeamWeaver records the requested effort and Anthropic usage details in trace metadata for WeaveScope ingestion. -
Current Opus 4.5, Sonnet 4.5, and Haiku 4.5 profiles carry standard, cache-read, five-minute and one-hour cache-write, batch, and retirement-floor pricing metadata so exact usage accounting does not have to infer those dimensions from a family default.
Usage
model =
BeamWeaver.Anthropic.chat_model(
model: "claude-opus-5",
effort: :xhigh,
max_tokens: 64_000,
api_key: "sk-ant-test"
)
BeamWeaver.Core.ChatModel.invoke(model, [
BeamWeaver.Core.Message.user("Write a short haiku about the BEAM.")
])
Tools are plain request values:
tools = [
BeamWeaver.Anthropic.Tools.web_search(),
BeamWeaver.Anthropic.Tools.code_execution(),
BeamWeaver.Anthropic.Tools.function(my_tool, strict: true)
]
BeamWeaver.Core.ChatModel.invoke(model, messages, tools: tools, tool_choice: :auto)
Opus 5 can ask Anthropic to retry classifier refusals on the provider's current recommended fallback:
BeamWeaver.Core.ChatModel.invoke(model, messages, fallbacks: :default)
To retry an eligible refusal while preserving Anthropic's cache credit, pass the short-lived token returned in message.response_metadata.stop_details:
BeamWeaver.Core.ChatModel.invoke(fallback_model, retry_messages,
fallback_credit_token: stop_details["fallback_credit_token"]
)
Use %{token: token, mode: :best_effort} for the current object form. A fallback-credit token cannot be combined with :fallbacks.
Use BeamWeaver.Anthropic.Tools.web_fetch/1 only with a model whose Anthropic feature matrix includes web fetch; Opus 5 does not.
When forwarding tool history from another provider into Anthropic, keep the native Message.tool/2 or assistant tool_calls history. The Anthropic request builder normalizes IDs only for the outgoing wire payload, so later BeamWeaver middleware and tracing still see the original native IDs.
Token counting uses Anthropic's count-tokens endpoint:
BeamWeaver.Anthropic.ChatModel.count_tokens(model, [
BeamWeaver.Core.Message.user("Count this.")
])
Unsupported Anthropic Surfaces
-
Bedrock/Vertex Anthropic routing. The direct Anthropic provider is implemented first.
-
Provider-specific files API helpers beyond message/document block support.
-
Managed Agents beta resources from Anthropic's OpenAPI spec, such as sessions, environments, skills, memories, vaults, and user profiles, are not exposed as first-class BeamWeaver modules yet; supported request fields can be passed where the Messages API accepts them.
-
Exact Python class identity and serialization compatibility. BeamWeaver keeps native Elixir modules and tagged errors.