Skip to content
Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

27,891 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Untitled design (7)-Photoroom

Helix AI Gateway – Production Implementation

Open-Source LLM Proxy that Saves Money, Reduces Latency, and Stops PII Leaks

Built on top of LiteLLM with enterprise-grade features for AI/ML workloads.

πŸš€ Quick Start

Prerequisites

  • Docker and Docker Compose
  • Redis Stack (with RediSearch)
  • PostgreSQL 15+
  • Python 3.11+ (for development)

One-Line Setup

# Clone and start Helix
git clone https://github.com/berriai/litellm.git
cd litellm
git checkout -b helix-gateway
cp .env.example .env
# Add your API keys to .env
docker-compose -f docker-compose.helix.yml up -d

That's it! Your Helix AI Gateway is now running:

🎯 One-Code-Change Integration

Replace your OpenAI client base URL:

# Before
import openai
openai.api_key = "sk-your-key"
response = openai.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)

# After - ONE LINE CHANGE
import openai
openai.api_key = "any"  # Helix handles auth
openai.api_base = "http://localhost:4000/v1"  # ← Helix
response = openai.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)

Everything else stays the same – but now you get:

  • 30-60% cost savings from intelligent caching
  • 10x faster responses on cached queries
  • Enterprise-grade PII protection
  • Real-time spend tracking and budget controls

πŸ“Š Features Overview

πŸš€ Intelligent Caching

  • Exact caching: Perfect match detection for repeated queries
  • Semantic caching: Vector similarity search with configurable thresholds
  • Hybrid approach: Combines exact and semantic for optimal performance
  • Smart eviction: LRU + TTL + memory management
  • Cache analytics: Real-time hit rates, savings metrics, performance tracking

πŸ”’ PII Protection & Redaction

  • Microsoft Presidio integration: Enterprise-grade PII detection
  • 100+ entity types: Custom recognizers, ML-based detection
  • Real-time redaction: Automatic masking before reaching LLM providers
  • Audit logging: Complete compliance trail for detected incidents
  • Configurable policies: Per-user, per-team, per-organization rules

πŸ’° Cost Optimization

  • Real-time spend tracking: Per-request cost calculation
  • Budget management: Daily/weekly/monthly limits with alerts
  • Model swapping: Intelligent routing to cost-effective alternatives
  • Cache savings calculation: Automatic savings attribution
  • Spend alerts: Configurable thresholds and notifications

πŸ“ˆ Real-time Monitoring

  • Streamlit dashboard: Live metrics, charts, and analytics
  • Grafana integration: Advanced visualizations and alerts
  • Prometheus metrics: Full observability stack
  • User leaderboards: Top spenders, usage patterns, insights
  • Performance metrics: Latency, throughput, error rates

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Client App    │───▢│   Helix Gateway  │───▢│  LLM Provider   β”‚
β”‚                 β”‚    β”‚                  β”‚    β”‚ (OpenAI/Anthropicβ”‚
β”‚ OpenAI SDK      β”‚    β”‚ β€’ Semantic Cache β”‚    β”‚  /Groq/etc.)   β”‚
β”‚ β€’ 1-line change β”‚    β”‚ β€’ PII Redaction β”‚    β”‚                 β”‚
β”‚ β€’ Transparent    β”‚    β”‚ β€’ Cost Tracking  β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚ β€’ Optimization   β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                       β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”
                       β”‚             β”‚
                β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”
                β”‚   Redis     β”‚ β”‚PostgreSQL  β”‚
                β”‚ β€’ Vector DB β”‚ β”‚ β€’ Users    β”‚
                β”‚ β€’ Cache     β”‚ β”‚ β€’ Config   β”‚
                β”‚ β€’ Metrics   β”‚ β”‚ β€’ Logs     β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‹ Configuration

Environment Variables

# Core Configuration
HELIX_ENABLED=true
REDIS_URL=redis://localhost:6379
DATABASE_URL=postgresql://helix:password@localhost:5432/helix

# API Keys (add yours)
OPENAI_API_KEY=sk-your-openai-key
ANTHROPIC_API_KEY=sk-your-anthropic-key
GROQ_API_KEY=gsk_your-groq-key
GOOGLE_API_KEY=your-google-key

# Monitoring
LANGFUSE_PUBLIC_KEY=your-langfuse-public
LANGFUSE_SECRET_KEY=your-langfuse-secret
LANGFUSE_HOST=https://cloud.langfuse.com

# Security
MASTER_KEY=your-master-key
GRAFANA_PASSWORD=your-grafana-password
POSTGRES_PASSWORD=your-postgres-password

Configuration File

See config/helix.example.yaml for comprehensive configuration options:

helix_settings:
  semantic_cache:
    enabled: true
    similarity_threshold: 0.88
    embedding_model: "all-MiniLM-L6-v2"
    ttl: 2592000  # 30 days

  pii_protection:
    enabled: true
    strict_mode: true
    entities: ["CREDIT_CARD", "EMAIL_ADDRESS", "PHONE_NUMBER"]
    action: "redact"

  cost_optimization:
    enabled: true
    model_swapping: true
    budget_alerts: true

  dashboard:
    enabled: true
    port: 8501
    refresh_interval: 5

🚒 Production Deployment

Docker Compose (Recommended)

# Production deployment with all components
docker-compose -f docker-compose.helix.yml up -d

# Check services status
docker-compose -f docker-compose.helix.yml ps

# View logs
docker-compose -f docker-compose.helix.yml logs -f

Kubernetes

See k8s/ directory for Kubernetes manifests:

# Deploy to Kubernetes
kubectl apply -f k8s/

# Check deployment
kubectl get pods -l app=helix
kubectl port-forward service/helix-proxy 4000:4000

Manual Installation

# Install dependencies
pip install -e ".[proxy]"
pip install sentence-transformers presidio-analyzer presidio-anonymizer redis streamlit

# Initialize Redis
redis-cli -u redis://localhost:6379 < redis/helix_init.redis

# Start proxy
uvicorn litellm.proxy.proxy_server:app --host 0.0.0.0 --port 4000

# Start dashboard
streamlit run helix/dashboard/dashboard.py --server.port=8501

πŸ“Š Dashboard & Monitoring

Streamlit Dashboard (http://localhost:8501)

  • Overview: Real-time metrics, savings, performance
  • Cost Analysis: Spend trends, budget tracking, model costs
  • Cache Performance: Hit rates, latency, memory usage
  • PII Incidents: Detection logs, redaction statistics
  • User Leaderboard: Top spenders, usage patterns
  • System Health: Service status, resource usage
  • Advanced visualizations: Custom dashboards, drill-downs
  • Alerting: Configurable thresholds, notifications
  • Historical analysis: Long-term trends, capacity planning
  • Integration: Prometheus, custom metrics

Default credentials: admin / your-grafana-password

Redis Commander (http://localhost:8081)

  • Redis GUI: Browse cache entries, inspect vectors
  • Performance monitoring: Memory usage, connection stats
  • Manual operations: Cache management, key inspection

πŸ”§ Development

Project Structure

litellm/
β”œβ”€β”€ proxy/
β”‚   β”œβ”€β”€ helix_hooks.py           # Main Helix integration
β”‚   └── example_config_yaml/
β”‚       └── helix_config.yaml    # Production config
helix/
β”œβ”€β”€ dashboard/
β”‚   β”œβ”€β”€ dashboard.py              # Streamlit dashboard
β”‚   β”œβ”€β”€ Dockerfile
β”‚   └── requirements.txt
β”œβ”€β”€ core/
β”‚   └── config.py                # Configuration management
β”œβ”€β”€ migrations/
β”‚   └── helix_schema_extensions.prisma  # Database schema
β”œβ”€β”€ redis/
β”‚   β”œβ”€β”€ redis.conf               # Redis optimization
β”‚   └── helix_init.redis       # Initialization script
β”œβ”€β”€ database/
β”‚   └── init.sql                # PostgreSQL schema
β”œβ”€β”€ monitoring/
β”‚   β”œβ”€β”€ prometheus.yml          # Prometheus config
β”‚   └── helix_rules.yml        # Alerting rules
└── nginx/
    └── nginx.conf              # Reverse proxy config

Adding Custom Features

  1. Custom PII Recognizers:
# In helix_config.yaml
pii_protection:
  custom_recognizers:
    - name: "internal_token"
      pattern: "token_[a-f0-9]{32}"
      entity_type: "API_KEY"
      confidence_level: 0.95
  1. Cost Optimization Rules:
# In helix_config.yaml
cost_optimization:
  rules:
    - rule_name: "simple_queries"
      conditions:
        max_tokens: 1000
      action:
        model: "fast-model"
        reason: "Cost optimization for simple queries"
  1. Custom Metrics:
# In helix_hooks.py
async def custom_metric_hook(data, response, user_api_key_dict):
    # Add your custom tracking logic
    await track_custom_metrics(data, response)

Testing

# Run tests
make test

# Run specific test
pytest tests/test_helix/ -v

# Load testing
locust -f tests/performance/locustfile.py

πŸ” Monitoring & Debugging

Health Checks

# Proxy health
curl http://localhost:4000/health

# Redis health
redis-cli ping

# Dashboard health
curl http://localhost:8501/_stcore/health

Metrics Endpoints

# Prometheus metrics
curl http://localhost:4000/metrics

# Custom Helix metrics
curl http://localhost:4000/helix/metrics

Debug Mode

# Enable debug logging
HELIX_DEBUG=true docker-compose -f docker-compose.helix.yml up

# View detailed logs
docker-compose -f docker-compose.helix.yml logs litellm -f

πŸ“š API Reference

Proxy Endpoints

  • POST /v1/chat/completions: OpenAI-compatible completion endpoint
  • POST /v1/embeddings: Embedding generation
  • GET /health: Health check
  • GET /metrics: Prometheus metrics
  • GET /helix/stats: Helix-specific statistics

Cache Management

# Manual cache invalidation
redis-cli DEL helix:exact:<hash>

# Clear semantic cache
redis-cli FT.DROPINDEX helix:semantic:index DD

# View cache stats
redis-cli HGETALL helix:cache:metrics

Configuration Management

# Reload configuration
curl -X POST http://localhost:4000/helix/reload-config

# View current config
curl http://localhost:4000/helix/config

# Validate configuration
curl http://localhost:4000/helix/config/validate

🚨 Troubleshooting

Common Issues

  1. Cache misses:

    • Check Redis connection: redis-cli ping
    • Verify vector index: redis-cli FT.INFO helix:semantic:index
    • Check similarity threshold in config
  2. PII not detected:

    • Verify Presidio configuration
    • Check entity list in config
    • Enable debug logging for PII processing
  3. High latency:

    • Monitor Redis memory usage
    • Check cache hit rates
    • Verify embedding model performance
  4. Dashboard not loading:

    • Check Redis connection in dashboard
    • Verify Streamlit configuration
    • Check for missing dependencies

Performance Tuning

# Redis optimization
maxmemory: 2gb
maxmemory-policy: allkeys-lru

# Vector search optimization
# In redis.conf
M 32                    # Better recall
ef_construction 400      # Better graph
ef_runtime 100          # Better search

# Cache settings
similarity_threshold: 0.88    # Balance precision/recall
cache_ttl: 2592000            # 30 days

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Development Setup

# Clone repository
git clone https://github.com/berriai/litellm.git
cd litellm

# Install development dependencies
make install-dev
make install-proxy-dev

# Start development stack
docker-compose -f docker-compose.helix.yml up -d

# Run tests
make test

πŸ“„ License

Apache 2.0 License - see LICENSE file for details.

πŸ™ Acknowledgments

  • LiteLLM: Foundation for the proxy functionality
  • Microsoft Presidio: Enterprise-grade PII detection
  • Sentence Transformers: Semantic similarity search
  • Redis Stack: High-performance caching and vector search
  • Streamlit: Real-time dashboard framework

πŸ“ž Support


Built with ❀️ by the LiteLLM team

About

Open-Source LLM Proxy that Saves Money, Reduces Latency, and Stops PII Leaks

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages