pub fn get_api_key(provider: &str, sources: &ApiKeySources) -> Result<String>
Expand description
Get API key for a specific provider with secure fallback mechanism
This function implements a secure retrieval mechanism that:
- First checks environment variables (highest priority for security)
- Then checks .env file values
- Falls back to configuration file values if neither above is set
- Supports all major providers: Gemini, Anthropic, OpenAI, OpenRouter, and xAI
- Automatically infers the correct environment variable based on provider
§Arguments
provider
- The provider name (“gemini”, “anthropic”, or “openai”)sources
- Configuration for where to look for API keys
§Returns
Ok(String)
- The API key if foundErr
- If no API key could be found for the provider