Skip to main content

opendev_http/adapters/
mod.rs

1//! Provider-specific request/response adapters.
2//!
3//! Each LLM provider has slightly different API conventions. Adapters
4//! normalize requests to the provider's format and responses back to
5//! a common Chat Completions format.
6
7pub mod anthropic;
8pub mod azure;
9pub mod base;
10pub mod bedrock;
11pub mod gemini;
12pub mod groq;
13pub mod mistral;
14pub mod ollama;
15pub mod openai;
16pub mod schema_adapter;
17
18pub use base::ProviderAdapter;
19pub use schema_adapter::adapt_for_provider;
20
21/// Detect the LLM provider from an API key prefix.
22///
23/// Returns `Some(provider_name)` if the key matches a known pattern:
24/// - `sk-ant-` -> `"anthropic"`
25/// - `sk-` -> `"openai"`
26/// - `gsk_` -> `"groq"`
27/// - `AIza` -> `"gemini"`
28///
29/// Returns `None` if the key format is not recognized.
30pub fn detect_provider_from_key(api_key: &str) -> Option<&'static str> {
31    // Order matters: check more specific prefixes first (sk-ant- before sk-).
32    if api_key.starts_with("sk-ant-") {
33        Some("anthropic")
34    } else if api_key.starts_with("sk-") {
35        Some("openai")
36    } else if api_key.starts_with("gsk_") {
37        Some("groq")
38    } else if api_key.starts_with("AIza") {
39        Some("gemini")
40    } else {
41        None
42    }
43}
44
45#[cfg(test)]
46mod tests;