Skip to main content

Module anthropic

Module anthropic 

Source
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§

AnthropicBedrockConfig
Routes an AnthropicModel to Claude on Amazon Bedrock’s InvokeModel API (AnthropicBedrock).
AnthropicClientConfig
How the client reaches the Messages API.
AnthropicClientConfigBuilder
Use builder syntax to set the inputs and finish with build().
AnthropicModel
A model on the Anthropic Messages API (AnthropicModel).
AnthropicModelConfig
Configuration of an AnthropicModel (AnthropicModelConfig): the BaseModelConfig fields and the Anthropic ones.
AnthropicModelConfigBuilder
Use builder syntax to set the inputs and finish with build().
AnthropicModelOptions
Options for AnthropicModel::new (AnthropicModelOptions): the AnthropicModelConfig fields and the client ones.
AnthropicModelOptionsBuilder
Use builder syntax to set the inputs and finish with build_options().