providers_kit/config/anthropic.rs
1use url::Url;
2
3use super::ApiKey;
4
5const DEFAULT_ANTHROPIC_BASE_URL: &str = "https://api.anthropic.com";
6pub(crate) const DEFAULT_ANTHROPIC_VERSION: &str = "2023-06-01";
7
8/// Anthropic credentials and endpoint configuration.
9///
10/// ```
11/// let config = providers_kit::config::AnthropicConfig::new(
12/// providers_kit::config::ApiKey::new("anthropic-test")?,
13/// );
14/// let _ = config;
15///
16/// # Ok::<(), providers_kit::KitError>(())
17/// ```
18#[derive(Clone)]
19pub struct AnthropicConfig {
20 api_key: ApiKey,
21 base_url: Url,
22}
23
24impl AnthropicConfig {
25 /// Creates a configuration for the public Anthropic endpoint.
26 ///
27 /// This only constructs configuration; provider operations perform network I/O.
28 ///
29 /// # Examples
30 ///
31 /// ```
32 /// use providers_kit::config::{ApiKey, AnthropicConfig};
33 /// let config = AnthropicConfig::new(ApiKey::new("example-key")?);
34 /// let _owned_configuration = config;
35 ///
36 /// # Ok::<(), providers_kit::KitError>(())
37 /// ```
38 ///
39 #[must_use]
40 pub fn new(api_key: ApiKey) -> Self {
41 Self {
42 api_key,
43 base_url: Url::parse(DEFAULT_ANTHROPIC_BASE_URL)
44 .expect("crate-owned Anthropic base URL should parse"),
45 }
46 }
47
48 /// Replaces the API base URL.
49 ///
50 /// This only constructs configuration; provider operations perform network I/O.
51 ///
52 /// # Examples
53 ///
54 /// ```
55 /// use providers_kit::config::{ApiKey, AnthropicConfig};
56 /// let config = AnthropicConfig::new(ApiKey::new("example-key")?);
57 /// let config = config.with_base_url("https://example.com/api".parse().unwrap());
58 /// let _owned_configuration = config;
59 ///
60 /// # Ok::<(), providers_kit::KitError>(())
61 /// ```
62 ///
63 #[must_use]
64 pub fn with_base_url(mut self, base_url: Url) -> Self {
65 self.base_url = base_url;
66 self
67 }
68
69 pub(crate) fn api_key(&self) -> &ApiKey {
70 &self.api_key
71 }
72
73 pub(crate) fn base_url(&self) -> &Url {
74 &self.base_url
75 }
76}