Supported Providers

ai-lib supports 20+ AI providers through a unified interface. Each provider is configured via environment variables and offers consistent API access. For enterprise environments requiring advanced provider management, routing, and analytics, see ai-lib-pro.

Provider Categories

Config-Driven Providers

These providers use a unified configuration system for easy setup and optimal performance:

ProviderChatStreamingMultimodalFunction CallsNotes
GroqUltra-low latency, Llama models
AnthropicClaude 3, strong reasoning
Azure OpenAIEnterprise OpenAI with compliance
HuggingFaceVariesVariesCommunity models, varies by model
TogetherAIVariesVariesCost-efficient, open models
DeepSeekReasoning-focused models
OllamaVariesVariesLocal/airgapped deployment
xAI GrokReal-time oriented
OpenRouterVariesVariesOpenAI-compatible gateway, provider/model routing
ReplicateVariesVariesHosted open-source models

Chinese Ecosystem Providers

Specialized for Chinese language and enterprise needs:

ProviderChatStreamingMultimodalFunction CallsNotes
Baidu WenxinEnterprise Chinese AI
Tencent HunyuanCloud integration
iFlytek SparkVoice + multimodal
Moonshot KimiLong context models

Independent Adapters

These providers have custom integration logic with high-performance direct HTTP client implementation:

ProviderChatStreamingMultimodalFunction CallsNotes
OpenAIGPT-4, GPT-3.5, broad model set
Google GeminiNative multimodal, Gemini Pro
MistralPartialEuropean models, lightweight
CohereLimitedCommand models, RAG optimized
QwenAlibaba’s multilingual models
PerplexityLimitedSearch-augmented conversations
AI21LimitedJurassic series
ZhipuAI (GLM)Chinese GLM series
MiniMaxChinese multimodal

Environment Variables

Configure API keys for each provider:

# Core providers
export OPENAI_API_KEY=your_openai_key
export GROQ_API_KEY=your_groq_key
export ANTHROPIC_API_KEY=your_anthropic_key
export GEMINI_API_KEY=your_gemini_key

# Chinese providers
export BAIDU_API_KEY=your_baidu_key
export TENCENT_SECRET_ID=your_tencent_id
export TENCENT_SECRET_KEY=your_tencent_key
export IFlytek_APP_ID=your_iflytek_id
export IFlytek_API_KEY=your_iflytek_key
export MOONSHOT_API_KEY=your_moonshot_key

# Other providers
export MISTRAL_API_KEY=your_mistral_key
export COHERE_API_KEY=your_cohere_key
export HUGGINGFACE_API_KEY=your_hf_key
export TOGETHERAI_API_KEY=your_together_key
export DEEPSEEK_API_KEY=your_deepseek_key
export QWEN_API_KEY=your_qwen_key
export XAI_API_KEY=your_xai_key
export OPENROUTER_API_KEY=your_openrouter_key
export REPLICATE_API_TOKEN=your_replicate_token
export PERPLEXITY_API_KEY=your_perplexity_key
export AI21_API_KEY=your_ai21_key
export ZHIPU_API_KEY=your_zhipu_key
export MINIMAX_API_KEY=your_minimax_key

# Ollama (local)
export OLLAMA_BASE_URL=http://localhost:11434

Provider Selection

Choose providers based on your needs:

use ai_lib::{AiClient, Provider};

// For speed and cost efficiency
let groq = AiClient::new(Provider::Groq)?;

// For reasoning and quality
let anthropic = AiClient::new(Provider::Anthropic)?;

// For multimodal capabilities
let gemini = AiClient::new(Provider::Gemini)?;

// For local/private deployment
let ollama = AiClient::new(Provider::Ollama)?;

Model Management

Each provider offers different models with varying capabilities:

// Get default model for provider
let default_model = client.default_chat_model();

// Use model arrays for load balancing (requires routing_mvp feature)
#[cfg(feature = "routing_mvp")]
{
    use ai_lib::{ModelArray, LoadBalancingStrategy};

    let array = ModelArray::new("production")
        .with_strategy(LoadBalancingStrategy::HealthBased)
        .add_endpoint(ModelEndpoint {
            name: "groq-1".into(),
            url: "https://api.groq.com".into(),
            weight: 1.0,
            healthy: true,
        });
}

Provider-Specific Notes

Groq

  • Best for: Speed and cost efficiency
  • Models: Llama 3, Mixtral variants
  • Latency: Ultra-low (sub-100ms typical)
  • Limitations: No multimodal support

Anthropic

  • Best for: Reasoning and complex tasks
  • Models: Claude 3 Opus, Sonnet, Haiku
  • Strengths: Long context, tool use, safety
  • Use cases: Research, analysis, complex reasoning

OpenAI

  • Best for: General purpose, broad capabilities
  • Models: GPT-4, GPT-3.5, DALL-E
  • Strengths: Multimodal, function calling, reliability
  • Use cases: General AI applications

Gemini

  • Best for: Multimodal applications
  • Models: Gemini Pro, Gemini Ultra
  • Strengths: Native image/audio processing
  • Use cases: Content analysis, multimodal AI

Enterprise Provider Management

For production environments with multiple providers, consider ai-lib-pro’s advanced features:

  • Advanced Routing: Intelligent load balancing across providers
  • Health Monitoring: Real-time provider health and performance tracking
  • Cost Optimization: Provider cost analysis and automatic cost-based routing
  • Failover Management: Automatic failover with configurable policies
  • Usage Analytics: Detailed provider usage patterns and optimization insights

Provider Constants Reference

This section provides a complete reference of all supported providers, their enum constants, default models, and environment variable requirements. Use this as a quick reference when integrating ai-lib into your applications.

Provider Enum Constants

All providers are defined in the Provider enum:

use ai_lib::Provider;

// Config-driven providers
Provider::Groq
Provider::XaiGrok
Provider::Ollama
Provider::DeepSeek
Provider::Anthropic
Provider::AzureOpenAI
Provider::HuggingFace
Provider::TogetherAI
Provider::OpenRouter
Provider::Replicate

// Chinese ecosystem providers
Provider::BaiduWenxin
Provider::TencentHunyuan
Provider::IflytekSpark
Provider::Moonshot
Provider::ZhipuAI
Provider::MiniMax

// Independent adapter providers
Provider::OpenAI
Provider::Qwen
Provider::Gemini
Provider::Mistral
Provider::Cohere
Provider::Perplexity
Provider::AI21

Default Models

Each provider has a default chat model and optional multimodal model:

ProviderDefault Chat ModelDefault Multimodal Model
Groqllama-3.1-8b-instant-
XaiGrokgrok-beta-
Ollamallama3-8b-
DeepSeekdeepseek-chat-
Anthropicclaude-3-5-sonnet-20241022claude-3-5-sonnet-20241022
AzureOpenAIgpt-35-turbogpt-4o
HuggingFacemicrosoft/DialoGPT-medium-
TogetherAImeta-llama/Llama-3-8b-chat-hf-
OpenRouteropenai/gpt-3.5-turboopenai/gpt-4o
Replicatemeta/llama-2-7b-chatmeta/llama-2-7b-chat
BaiduWenxinernie-3.5-
TencentHunyuanhunyuan-standard-
IflytekSparkspark-v3.0-
Moonshotmoonshot-v1-8k-
ZhipuAIglm-4glm-4v
MiniMaxabab6.5-chatabab6.5-chat
OpenAIgpt-3.5-turbogpt-4o
Qwenqwen-turbo-
Geminigemini-1.5-flashgemini-1.5-flash
Mistralmistral-small-
Coherecommand-rcommand-r-plus
Perplexityllama-3.1-sonar-small-128k-onlinellama-3.1-sonar-small-128k-online
AI21j2-ultraj2-ultra

Environment Variables

Each provider requires specific environment variables for authentication:

ProviderEnvironment VariableDescription
GroqGROQ_API_KEYGroq API key
XaiGrokGROK_API_KEYxAI Grok API key
OllamaOLLAMA_BASE_URLOllama server URL (default: http://localhost:11434)
DeepSeekDEEPSEEK_API_KEYDeepSeek API key
AnthropicANTHROPIC_API_KEYAnthropic API key
AzureOpenAIAZURE_OPENAI_API_KEY
AZURE_OPENAI_ENDPOINT
Azure OpenAI API key and endpoint
HuggingFaceHUGGINGFACE_API_KEYHuggingFace API token
TogetherAITOGETHER_API_KEYTogetherAI API key
OpenRouterOPENROUTER_API_KEYOpenRouter API key
ReplicateREPLICATE_API_TOKENReplicate API token
BaiduWenxinBAIDU_WENXIN_API_KEY
BAIDU_WENXIN_SECRET_KEY
Baidu Wenxin API credentials
TencentHunyuanTENCENT_HUNYUAN_SECRET_ID
TENCENT_HUNYUAN_SECRET_KEY
Tencent Hunyuan credentials
IflytekSparkIFLYTEK_APP_ID
IFLYTEK_API_KEY
iFlytek Spark credentials
MoonshotMOONSHOT_API_KEYMoonshot API key
ZhipuAIZHIPU_API_KEYZhipuAI API key
MiniMaxMINIMAX_API_KEYMiniMax API key
OpenAIOPENAI_API_KEYOpenAI API key
QwenDASHSCOPE_API_KEYAlibaba DashScope API key
GeminiGEMINI_API_KEYGoogle Gemini API key
MistralMISTRAL_API_KEYMistral API key
CohereCOHERE_API_KEYCohere API key
PerplexityPERPLEXITY_API_KEYPerplexity API key
AI21AI21_API_KEYAI21 API key

Provider Capabilities Matrix

ProviderChatStreamingMultimodalFunction CallingNotes
GroqUltra-low latency, Llama models
XaiGrokReal-time oriented
OllamaVariesVariesLocal/airgapped deployment
DeepSeekReasoning-focused models
AnthropicClaude 3, strong reasoning
AzureOpenAIEnterprise OpenAI with compliance
HuggingFaceVariesVariesCommunity models, varies by model
TogetherAIVariesVariesCost-efficient, open models
OpenRouterVariesVariesOpenAI-compatible gateway, provider/model routing
ReplicateVariesVariesHosted open-source models
BaiduWenxinEnterprise Chinese AI
TencentHunyuanCloud integration
IflytekSparkVoice + multimodal
MoonshotLong context models
ZhipuAIChinese GLM series
MiniMaxChinese multimodal
OpenAIGPT-4, GPT-3.5, broad model set
QwenAlibaba’s multilingual models
GeminiNative multimodal, Gemini Pro
MistralPartialEuropean models, lightweight
CohereLimitedCommand models, RAG optimized
PerplexityLimitedSearch-augmented conversations
AI21LimitedJurassic series

Feature Flags Reference

ai-lib uses Cargo feature flags to enable optional functionality. Use these flags in your Cargo.toml:

Core Features

[dependencies.ai-lib]
version = "0.4.0"
features = [
    # Enable interceptor pipeline (retry, rate limiters, circuit breaker)
    "interceptors",
    # Enable unified reqwest client factory/shared transport settings
    "unified_transport",
    # Enable unified SSE parser for streaming
    "unified_sse",
    # Enable minimal cost accounting metrics
    "cost_metrics",
    # Enable strategy-based routing MVP
    "routing_mvp",
    # Enable observability interfaces (Tracer, AuditSink)
    "observability",
    # Enable config hot-reload traits
    "config_hot_reload",
]

Convenience Aliases

# Enable streaming support (equivalent to "unified_sse")
features = ["streaming"]

# Enable transport layer (equivalent to "unified_transport")
features = ["transport"]

# Enable resilience features (equivalent to "interceptors")
features = ["resilience"]

# Enable hot reload (equivalent to "config_hot_reload")
features = ["hot_reload"]

# Enable all features
features = ["all"]
Use CaseRecommended Features
Basic ChatNone (default)
Streaming["streaming"]
Production App["resilience", "transport", "streaming"]
Enterprise["resilience", "transport", "streaming", "observability"]
Dynamic Config["resilience", "transport", "streaming", "hot_reload"]
Everything["all"]

Feature Dependencies

  • streaming → enables unified_sse
  • transport → enables unified_transport
  • resilience → enables interceptors
  • hot_reload → enables config_hot_reload
  • all → enables all core features

Next Steps

Build: f101766 · 2025-12-18T16:26:59.904Z · v0.21