Anthropic (adk-anthropic)
The adk-anthropic crate is a dedicated Anthropic API client for ADK-Rust. It provides direct access to the full Anthropic Messages API surface, including streaming, extended thinking, prompt caching, citations, vision, PDF processing, and token pricing.
Architecture
adk-anthropic is a standalone client crate that adk-model wraps via its Anthropic adapter. You can use it directly for low-level API access, or through adk-model for the unified Llm trait.
βββββββββββββββ βββββββββββββββββ ββββββββββββββββ
β Your Code ββββββΆβ adk-model ββββββΆβadk-anthropic ββββββΆ Anthropic API
β β β (Llm trait) β β (HTTP client)β
βββββββββββββββ βββββββββββββββββ ββββββββββββββββ
Supported Models
| Model | API ID | Notes |
|---|---|---|
| Claude Opus 4.7 | claude-opus-4-7 | Most capable GA model, 1M context, 128K output, adaptive thinking only |
| Claude Opus 4.6 | claude-opus-4-6 | Previous flagship, 1M context, 128K output |
| Claude Sonnet 4.6 | claude-sonnet-4-6 | Best speed/intelligence balance, 1M context |
| Claude Haiku 4.5 | claude-haiku-4-5 | Fastest, 200K context |
| Claude Opus 4.5 | claude-opus-4-5 | Previous generation |
| Claude Sonnet 4.5 | claude-sonnet-4-5 | Previous generation |
| Claude Sonnet 4 | claude-sonnet-4-0 | Legacy (retiring June 2026) |
| Claude Opus 4 | claude-opus-4-0 | Legacy (retiring June 2026) |
Setup
Set your API key:
export ANTHROPIC_API_KEY=sk-ant-...
Direct Client Usage
use adk_anthropic::{Anthropic, KnownModel, MessageCreateParams};
let client = Anthropic::new(None)?; // reads ANTHROPIC_API_KEY
let params = MessageCreateParams::simple("Hello!", KnownModel::ClaudeSonnet46);
let response = client.send(params).await?;
Through adk-model
use adk_model::anthropic::{AnthropicClient, AnthropicConfig};
let api_key = std::env::var("ANTHROPIC_API_KEY")?;
let model = AnthropicClient::new(AnthropicConfig::new(api_key, "claude-sonnet-4-6"))?;
Custom base URL (gateways, proxies, compatible endpoints)
Point the client at a different endpoint to route through a corporate proxy or a
Messages-API-compatible gateway. Provide the root URL without the /v1/
suffix β it is appended automatically. AnthropicConfig::with_base_url flows
through adk-model to the underlying client:
use adk_model::anthropic::{AnthropicClient, AnthropicConfig};
let model = AnthropicClient::new(
AnthropicConfig::new(api_key, "claude-sonnet-4-6")
.with_base_url("https://gateway.internal/anthropic"),
)?;
Or set it directly on the low-level client, and read back the effective endpoint
with base_url():
use adk_anthropic::Anthropic;
let client = Anthropic::new(Some(api_key))?
.with_base_url("https://api.minimax.io/anthropic".to_string())?;
assert_eq!(client.base_url(), "https://api.minimax.io/anthropic");
When unset, the client uses Anthropic's public API (https://api.anthropic.com).
with_base_url returns Result because the client attaches the Anthropic API key
to every request. Only https://, or http:// with a loopback host
(localhost, 127.0.0.1, [::1]) for local development, is accepted β anything
else is rejected as a validation error rather than silently sending the key in
cleartext. The same rule applies to AnthropicConfig::with_base_url, which is
validated when AnthropicClient::new builds the underlying client.
Key Features
Adaptive Thinking (4.6+ models)
Opus 4.7 only supports adaptive thinking β budget_tokens is rejected.
use adk_anthropic::{ThinkingConfig, OutputConfig, EffortLevel};
// Opus 4.7: use xhigh effort (recommended for coding/agentic)
let mut params = MessageCreateParams::simple("Solve this...", KnownModel::ClaudeOpus47)
.with_thinking(ThinkingConfig::adaptive());
params.output_config = Some(OutputConfig::with_effort(EffortLevel::XHigh));
// Sonnet 4.6: any effort level works
let mut params = MessageCreateParams::simple("Solve this...", KnownModel::ClaudeSonnet46)
.with_thinking(ThinkingConfig::adaptive());
params.output_config = Some(OutputConfig::with_effort(EffortLevel::High));
Prompt Caching
use adk_anthropic::CacheControlEphemeral;
let mut params = MessageCreateParams::simple("Question", KnownModel::ClaudeSonnet46)
.with_system("Large system prompt...");
params.cache_control = Some(CacheControlEphemeral::new());
Structured Output
use adk_anthropic::{OutputConfig, OutputFormat};
let mut params = MessageCreateParams::simple("Extract data", KnownModel::ClaudeSonnet46);
params.output_config = Some(OutputConfig::new(OutputFormat::json_schema(schema)));
Token Pricing
use adk_anthropic::pricing::{ModelPricing, estimate_cost};
let cost = estimate_cost(ModelPricing::SONNET_46, &response.usage);
println!("${:.6}", cost.total());
Examples
Run with cargo run -p adk-anthropic --example <name>:
basicβ non-streaming chatstreamingβ SSE streamingthinkingβ adaptive + budget thinkingtoolsβ tool callingstructured_outputβ JSON schemacachingβ multi-turn caching with costscontext_editingβ tool/thinking clearing (beta)compactionβ server-side compactiontoken_countingβ pre-send token estimationstop_reasonsβ handling all stop reasonsfast_modeβ fast inference (beta)citationsβ document citationspdf_processingβ PDF analysisvisionβ image understanding