pub fn provider_from_env() -> Result<Arc<dyn Llm>>Expand description
Detect LLM provider from environment variables.
Checks environment variables in precedence order and returns the first
matching provider that was compiled through Cargo features. The default
minimal tier detects Gemini via GOOGLE_API_KEY; add openai or
anthropic to widen detection.
GOOGLE_GENAI_USE_ENTERPRISE/GOOGLE_GENAI_USE_VERTEXAItruthy (1or case-insensitivetrue) → Gemini on Vertex AI via Application Default Credentials, usingGOOGLE_CLOUD_PROJECTandGOOGLE_CLOUD_LOCATION(requires thegemini-vertexfeature;GOOGLE_GENAI_USE_ENTERPRISEtakes precedence when both are set)ANTHROPIC_API_KEY→ Anthropic (Claude)OPENAI_API_KEY→ OpenAIGOOGLE_API_KEY→ Gemini
When a Vertex flag is truthy but the gemini-vertex feature is not
compiled, a tracing warning is emitted and detection falls through to
the API-key steps, which may select the Gemini Studio endpoint
(generativelanguage.googleapis.com).
§Errors
Returns AdkError when no supported environment variable is set, or
when a Vertex flag is truthy but GOOGLE_CLOUD_PROJECT /
GOOGLE_CLOUD_LOCATION is missing.
§Example
ⓘ
use adk_rust::provider_from_env;
use std::sync::Arc;
let model: Arc<dyn adk_rust::Llm> = provider_from_env()?;