1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Anthropic backend kinds (typed, provider-owned).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum AnthropicBackendKind {
/// Native `api.anthropic.com` API (Claude.ai / Console).
AnthropicApi,
/// AWS Bedrock InvokeModelWithResponseStream (event-stream, SigV4).
Bedrock,
/// Google Vertex AI (Anthropic-on-Vertex), Bearer auth via GoogleAuth.
Vertex,
/// Azure Foundry (Anthropic-on-Foundry), Bearer auth via Azure AD.
Foundry,
}
impl AnthropicBackendKind {
pub const ALL: &'static [Self] = &[
Self::AnthropicApi,
Self::Bedrock,
Self::Vertex,
Self::Foundry,
];
pub fn parse(raw: &str) -> Option<Self> {
match raw {
"anthropic_api" => Some(Self::AnthropicApi),
"bedrock" => Some(Self::Bedrock),
"vertex" => Some(Self::Vertex),
"foundry" => Some(Self::Foundry),
_ => None,
}
}
pub fn as_str(self) -> &'static str {
match self {
Self::AnthropicApi => "anthropic_api",
Self::Bedrock => "bedrock",
Self::Vertex => "vertex",
Self::Foundry => "foundry",
}
}
pub fn default_base_url(self) -> &'static str {
match self {
Self::AnthropicApi => "https://api.anthropic.com",
// Bedrock uses <region>.amazonaws.com base (region-specific; the
// binding's BackendProfile.base_url carries the full URL).
Self::Bedrock => "",
// Vertex uses <region>-aiplatform.googleapis.com.
Self::Vertex => "",
// Foundry uses a per-deployment base URL from binding options.
Self::Foundry => "",
}
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
mod tests {
use super::*;
#[test]
fn parse_roundtrip() {
for v in AnthropicBackendKind::ALL {
let v = *v;
assert_eq!(AnthropicBackendKind::parse(v.as_str()), Some(v));
}
assert_eq!(AnthropicBackendKind::parse("other"), None);
}
}