providers_kit/config/gemini.rs
1use url::Url;
2
3use super::ApiKey;
4
5const DEFAULT_GEMINI_BASE_URL: &str = "https://generativelanguage.googleapis.com";
6
7/// Gemini request service tier.
8#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
9pub enum GeminiServiceTier {
10 /// Standard request processing.
11 #[default]
12 Standard,
13 /// Flexible lower-priority processing.
14 Flex,
15 /// Priority processing.
16 Priority,
17}
18
19/// Gemini credentials and endpoint configuration.
20///
21/// ```
22/// let config = providers_kit::config::GeminiConfig::new(
23/// providers_kit::config::ApiKey::new("gemini-test")?,
24/// );
25/// let _ = config;
26///
27/// # Ok::<(), providers_kit::KitError>(())
28/// ```
29#[derive(Clone)]
30pub struct GeminiConfig {
31 api_key: ApiKey,
32 base_url: Url,
33 service_tier: GeminiServiceTier,
34}
35
36impl GeminiConfig {
37 /// Creates a configuration for the public Gemini endpoint.
38 ///
39 /// This only constructs configuration; provider operations perform network I/O.
40 ///
41 /// # Examples
42 ///
43 /// ```
44 /// use providers_kit::config::{ApiKey, GeminiConfig};
45 /// let config = GeminiConfig::new(ApiKey::new("example-key")?);
46 /// let _owned_configuration = config;
47 ///
48 /// # Ok::<(), providers_kit::KitError>(())
49 /// ```
50 ///
51 #[must_use]
52 pub fn new(api_key: ApiKey) -> Self {
53 Self {
54 api_key,
55 base_url: Url::parse(DEFAULT_GEMINI_BASE_URL)
56 .expect("crate-owned Gemini base URL should parse"),
57 service_tier: GeminiServiceTier::Standard,
58 }
59 }
60
61 /// Replaces the API base URL.
62 ///
63 /// This only constructs configuration; provider operations perform network I/O.
64 ///
65 /// # Examples
66 ///
67 /// ```
68 /// use providers_kit::config::{ApiKey, GeminiConfig};
69 /// let config = GeminiConfig::new(ApiKey::new("example-key")?);
70 /// let config = config.with_base_url("https://example.com/api".parse().unwrap());
71 /// let _owned_configuration = config;
72 ///
73 /// # Ok::<(), providers_kit::KitError>(())
74 /// ```
75 ///
76 #[must_use]
77 pub fn with_base_url(mut self, base_url: Url) -> Self {
78 self.base_url = base_url;
79 self
80 }
81
82 /// Replaces the request service tier.
83 ///
84 /// The selected endpoint/model determines support; configuration does not probe it.
85 ///
86 /// # Examples
87 ///
88 /// ```
89 /// use providers_kit::config::{ApiKey, GeminiConfig, GeminiServiceTier};
90 /// let _config = GeminiConfig::new(ApiKey::new("example-key")?)
91 /// .with_service_tier(GeminiServiceTier::Standard);
92 ///
93 /// # Ok::<(), providers_kit::KitError>(())
94 /// ```
95 ///
96 #[must_use]
97 pub fn with_service_tier(mut self, service_tier: GeminiServiceTier) -> Self {
98 self.service_tier = service_tier;
99 self
100 }
101
102 pub(crate) fn api_key(&self) -> &ApiKey {
103 &self.api_key
104 }
105
106 pub(crate) fn base_url(&self) -> &Url {
107 &self.base_url
108 }
109
110 pub(crate) fn service_tier(&self) -> GeminiServiceTier {
111 self.service_tier
112 }
113}