use std::time::Duration;
const DEFAULT_BASE_URL: &str = "https://api.anthropic.com";
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum AuthKind {
#[default]
ApiKey,
Bearer,
}
#[derive(Debug, Clone)]
pub struct Config {
pub base_url: String,
pub api_key: Option<String>,
pub auth_kind: AuthKind,
pub max_retries: u32,
pub timeout: Duration,
}
impl Default for Config {
fn default() -> Self {
Self {
base_url: DEFAULT_BASE_URL.to_string(),
api_key: None,
auth_kind: AuthKind::ApiKey,
max_retries: 2,
timeout: Duration::from_secs(60),
}
}
}
impl Config {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn from_env() -> Self {
let api_key = std::env::var("ANTHROPIC_API_KEY")
.ok()
.filter(|key| !key.is_empty());
Self {
api_key,
..Self::default()
}
}
#[must_use]
pub fn with_api_key(mut self, api_key: impl Into<String>) -> Self {
self.api_key = Some(api_key.into());
self
}
#[must_use]
pub fn with_auth_kind(mut self, auth_kind: AuthKind) -> Self {
self.auth_kind = auth_kind;
self
}
#[must_use]
pub fn with_base_url(mut self, base_url: impl Into<String>) -> Self {
self.base_url = base_url.into();
self
}
#[must_use]
pub fn with_max_retries(mut self, max_retries: u32) -> Self {
self.max_retries = max_retries;
self
}
#[must_use]
pub fn with_timeout(mut self, timeout: Duration) -> Self {
self.timeout = timeout;
self
}
}