Expand description
The Anthropic Messages API provider, behind the anthropic feature.
AnthropicModel streams from the Messages API over HTTP, with the official Anthropic SDK’s
transport behaviour (retries, timeout, error texts). It maps every content block, the system
prompt, tool specs and tool choice, prompt caching (CacheConfig), structured output,
extended thinking (through AnthropicModelConfig::params), Anthropic’s server-side tools
(such as the native web_search, through AnthropicModelConfig::anthropic_tools) and
server-side summaries by on-demand compaction.
use strands::models::anthropic::AnthropicModel;
use strands::models::Model;
let model = AnthropicModel::builder()
.model_id("claude-sonnet-4-6")
.max_tokens(4096)
.api_key("my-api-key")
.build()?;
assert_eq!(model.model_id().as_deref(), Some("claude-sonnet-4-6"));An agent with extended thinking, through params (the API key comes from
ANTHROPIC_API_KEY):
use serde_json::json;
use strands::Agent;
use strands::models::anthropic::AnthropicModel;
let model = AnthropicModel::builder()
.model_id("claude-sonnet-4-6")
.max_tokens(16_000)
.params(json!({"thinking": {"type": "enabled", "budget_tokens": 4096}}))
.build()?;
let mut agent = Agent::builder().model(model).build()?;
let result = agent.invoke("Why is the sky blue?").await?;
println!("{result}");Structs§
- Anthropic
Bedrock Config - Routes an
AnthropicModelto Claude on Amazon Bedrock’s InvokeModel API (AnthropicBedrock). - Anthropic
Client Config - How the client reaches the Messages API.
- Anthropic
Client Config Builder - Use builder syntax to set the inputs and finish with
build(). - Anthropic
Model - A model on the Anthropic Messages API (
AnthropicModel). - Anthropic
Model Config - Configuration of an
AnthropicModel(AnthropicModelConfig): theBaseModelConfigfields and the Anthropic ones. - Anthropic
Model Config Builder - Use builder syntax to set the inputs and finish with
build(). - Anthropic
Model Options - Options for
AnthropicModel::new(AnthropicModelOptions): theAnthropicModelConfigfields and the client ones. - Anthropic
Model Options Builder - Use builder syntax to set the inputs and finish with
build_options().