Guides & Best Practices
Learn how to maximize B2ALABS capabilities with practical guides and tutorials. All guides based on real production deployments and proven techniques.
Cost Optimization
Reduce AI Costs by 70%
Use intelligent routing to automatically select the cheapest available provider for each request
Model Selection Strategies
Choose the right model tier based on task complexity to optimize cost vs. quality
Reliability & Failover
Implement Multi-Provider Failover
Set up automatic failover between providers for 99.9% uptime
Security & Access Control
Security Best Practices
Secure your B2ALABS deployment with industry best practices
Advanced Topics
Advanced Routing Strategies
Implement custom routing logic for specialized use cases
Supported AI Providers (October 2025)
B2ALABS supports 8 major AI providers with 20+ models for intelligent routing and failover
OpenAI
Supported- • GPT-5
- • GPT-5 Pro
- • GPT-5 Mini
- • GPT-5
- • GPT-5 Mini
Azure OpenAI
Supported- • All OpenAI models
Anthropic
Supported- • Claude Opus 4
- • Claude Sonnet 4.5
- • Claude Haiku 3
Google Gemini
Supported- • Gemini 2.5 Pro
- • Gemini 2.5 Flash
- • Gemini 2.5 Flash-Lite
Mistral AI
Supported- • Mistral Large
- • Mistral Medium
- • Mixtral 8x7B
xAI Grok
Supported- • Grok 4
Meta Llama
Supported- • Llama 4
DeepSeek
Supported- • DeepSeek R1
- • DeepSeek V3
How to Reduce AI Costs by 70%
Use B2ALABS intelligent routing to automatically select the cheapest provider
Step 1: Enable Cost-Based Routing
Configure B2ALABS to use the lowest_cost routing strategy:
# Environment variable
ROUTING_STRATEGY=lowest_cost
# Or via API request
curl -X POST http://localhost:8080/api/v1/ai/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5",
"routing_strategy": "lowest_cost",
"messages": [{"role": "user", "content": "Hello!"}]
}'Step 2: Configure Multiple Providers
Add API keys for multiple providers in your .env file:
# .env file OPENAI_API_KEY=sk-... ANTHROPIC_API_KEY=sk-ant-... GOOGLE_API_KEY=AIza... AZURE_OPENAI_API_KEY=... MISTRAL_API_KEY=...
Step 3: Let B2ALABS Choose
B2ALABS will automatically:
- Estimate prompt tokens (1 token ≈ 4 characters)
- Calculate costs for all available providers
- Select the cheapest healthy provider
- Fallback to next cheapest if first fails
Real Savings Examples:
- • GPT-5 ($0.005/1K) → Gemini-flash-lite ($0.00015/1K) = 97% savings
- • GPT-5-mini ($0.001/1K) → Gemini-flash-lite ($0.00015/1K) = 85% savings
- • Claude Opus 4 ($0.015/1K) → Claude Haiku 3 ($0.00025/1K) = 98% savings
Implement Multi-Provider Failover
Achieve 99.9% uptime with automatic failover between 8 providers
How Failover Works
B2ALABS automatically configures fallback chains for each model. When a request fails:
- Primary provider attempts request
- If failed, health checker marks provider as potentially unhealthy
- Automatic retry with next provider in fallback chain
- Continue until success or all providers exhausted
- Provider auto-recovers when success rate improves
Example Fallback Chain (GPT-5)
- 1Azure OpenAI GPT-5 (Primary)
- 2OpenAI GPT-5 (Fallback)
- 3Anthropic Claude Opus 4 (Cross-provider)
- 4Claude Sonnet 4.5 (Cost-effective)
- 5OpenAI GPT-5-mini (Final fallback)
Health Checking Configuration
# Automatic health checking (from smart_router.go) - CheckIcon interval: 30 seconds - Failure threshold: 3 consecutive failures - Auto-recovery: When success rate > 90% # View provider health curl http://localhost:8080/api/v1/router/health \ -H "Authorization: Bearer YOUR_API_KEY"
Result: 99.9% Uptime
With 8 providers and automatic failover, your gateway remains operational even when multiple providers experience outages. Each request has up to 5 fallback options, ensuring high availability.
Related Documentation
Was this page helpful?
