pub struct AnthropicConfig {
pub api_key: Option<String>,
pub base_url: String,
pub default_model: String,
pub max_context_tokens: usize,
pub retry_policy: RetryPolicy,
pub enable_prompt_caching: bool,
pub cache_ttl: String,
}Expand description
Configuration for Anthropic Claude models.
Claude models support prompt caching for significant cost savings (90% on cache reads). Enable caching for static system prompts and context that doesn’t change often.
§Example
use multi_llm::AnthropicConfig;
let config = AnthropicConfig {
api_key: Some("sk-ant-api03-...".to_string()),
default_model: "claude-3-5-sonnet-20241022".to_string(),
enable_prompt_caching: true,
cache_ttl: "1h".to_string(), // 1-hour cache
..Default::default()
};§Environment Variables
ANTHROPIC_API_KEY: API key (required)
§Models
claude-3-5-sonnet-20241022: Latest Sonnet (recommended)claude-3-opus-20240229: Most capableclaude-3-haiku-20240307: Fastest, cheapest
Fields§
§api_key: Option<String>Anthropic API key (starts with “sk-ant-”).
base_url: StringBase URL for API requests (default: https://api.anthropic.com).
default_model: StringDefault model to use for requests.
max_context_tokens: usizeMaximum context window size in tokens (200K for Claude 3).
retry_policy: RetryPolicyRetry policy for transient failures.
enable_prompt_caching: boolEnable prompt caching for cost savings.
When enabled, static system prompts and context are cached, reducing costs by 90% on cache reads.
cache_ttl: StringCache TTL setting: “5m” for 5-minute cache, “1h” for 1-hour cache.
- “5m”: Ephemeral cache, 1.25x write cost, good for development
- “1h”: Extended cache, 2x write cost, good for production
Trait Implementations§
Source§impl Clone for AnthropicConfig
impl Clone for AnthropicConfig
Source§fn clone(&self) -> AnthropicConfig
fn clone(&self) -> AnthropicConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for AnthropicConfig
impl Debug for AnthropicConfig
Source§impl Default for AnthropicConfig
impl Default for AnthropicConfig
Source§impl<'de> Deserialize<'de> for AnthropicConfig
impl<'de> Deserialize<'de> for AnthropicConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl ProviderConfig for AnthropicConfig
impl ProviderConfig for AnthropicConfig
Source§fn provider_name(&self) -> &'static str
fn provider_name(&self) -> &'static str
Get the provider identifier (e.g., “openai”, “anthropic”).
Source§fn max_context_tokens(&self) -> usize
fn max_context_tokens(&self) -> usize
Get the maximum context window size in tokens.
Source§fn validate(&self) -> LlmResult<()>
fn validate(&self) -> LlmResult<()>
Validate that the configuration is complete and valid. Read more
Source§fn default_model(&self) -> &str
fn default_model(&self) -> &str
Get the default model name for this provider.
Source§fn retry_policy(&self) -> &RetryPolicy
fn retry_policy(&self) -> &RetryPolicy
Get the retry policy for transient failures.
Auto Trait Implementations§
impl Freeze for AnthropicConfig
impl RefUnwindSafe for AnthropicConfig
impl Send for AnthropicConfig
impl Sync for AnthropicConfig
impl Unpin for AnthropicConfig
impl UnwindSafe for AnthropicConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more