BeamWeaver Anthropic
BeamWeaver includes a direct Anthropic Messages API provider under BeamWeaver.Anthropic.
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.
-
The token counting endpoint is exposed through
ChatModel.count_tokens/3. -
Checked-in model profiles cover 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. -
Request builders include Anthropic spec fields such as
:cache_control,:container,:metadata,:service_tier,:diagnostics,:speed,:user_profile_id,:inference_geo,:context_management,:mcp_servers,:fallbacks,:thinking, and:output_config. -
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. -
Opus 5 supports mid-conversation system messages and beta tool-change blocks. BeamWeaver infers the tool-change beta header. Server-side fallbacks accept either a model list or
:default, with the matching beta header inferred. -
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.
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)
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.