use std::time::Duration;
#[derive(Debug, Clone)]
pub struct AnthropicProviderConfig {
pub base_url: String,
pub model: String,
pub api_key: Option<String>,
pub timeout: Duration,
pub default_max_tokens: u32,
pub adaptive_thinking: bool,
pub effort: Option<String>,
pub cache: bool,
pub api_version: String,
}
impl AnthropicProviderConfig {
pub fn new(model: impl Into<String>) -> Self {
Self {
base_url: "https://api.anthropic.com".to_string(),
model: model.into(),
api_key: None,
timeout: Duration::from_secs(300),
default_max_tokens: 32_000,
adaptive_thinking: true,
effort: None,
cache: true,
api_version: "2023-06-01".to_string(),
}
}
pub fn with_base_url(mut self, base_url: impl Into<String>) -> Self {
self.base_url = base_url.into();
self
}
pub fn with_api_key(mut self, api_key: impl Into<String>) -> Self {
self.api_key = Some(api_key.into());
self
}
pub fn with_timeout(mut self, timeout: Duration) -> Self {
self.timeout = timeout;
self
}
pub fn with_default_max_tokens(mut self, max_tokens: u32) -> Self {
self.default_max_tokens = max_tokens;
self
}
pub fn with_adaptive_thinking(mut self, enabled: bool) -> Self {
self.adaptive_thinking = enabled;
self
}
pub fn with_effort(mut self, effort: impl Into<String>) -> Self {
self.effort = Some(effort.into());
self
}
pub fn with_cache(mut self, enabled: bool) -> Self {
self.cache = enabled;
self
}
pub(crate) fn messages_url(&self) -> String {
format!("{}/v1/messages", self.base_url.trim_end_matches('/'))
}
pub(crate) fn count_tokens_url(&self) -> String {
format!(
"{}/v1/messages/count_tokens",
self.base_url.trim_end_matches('/')
)
}
pub(crate) fn models_url(&self) -> String {
format!("{}/v1/models", self.base_url.trim_end_matches('/'))
}
}