Skip to main content

litellm_rs/
config.rs

1use std::collections::HashMap;
2
3#[derive(Debug, Clone, Default)]
4pub struct Config {
5    pub default_provider: Option<String>,
6    pub providers: HashMap<String, ProviderConfig>,
7}
8
9#[derive(Debug, Clone, Default)]
10pub struct ProviderConfig {
11    pub base_url: Option<String>,
12    pub api_key_env: Option<String>,
13    pub api_key: Option<String>,
14    pub kind: ProviderKind,
15    pub no_auth: bool,
16    pub extra_headers: HashMap<String, String>,
17}
18
19#[derive(Debug, Clone, Default, PartialEq, Eq)]
20pub enum ProviderKind {
21    #[default]
22    OpenAICompatible,
23    Anthropic,
24    Gemini,
25}
26
27impl ProviderConfig {
28    pub fn with_base_url(mut self, base: impl Into<String>) -> Self {
29        self.base_url = Some(base.into());
30        self
31    }
32
33    pub fn with_api_key_env(mut self, env: impl Into<String>) -> Self {
34        self.api_key_env = Some(env.into());
35        self
36    }
37
38    pub fn with_api_key(mut self, key: impl Into<String>) -> Self {
39        self.api_key = Some(key.into());
40        self
41    }
42
43    pub fn with_kind(mut self, kind: ProviderKind) -> Self {
44        self.kind = kind;
45        self
46    }
47
48    pub fn with_no_auth(mut self, no_auth: bool) -> Self {
49        self.no_auth = no_auth;
50        self
51    }
52
53    pub fn with_header(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
54        self.extra_headers.insert(key.into(), value.into());
55        self
56    }
57}