Overview
LiteLLM provides comprehensive caching capabilities to reduce API costs and improve response times by storing and reusing LLM responses. Cache responses from completion, embedding, transcription, and other API calls across multiple backend systems.Supported Cache Types
LiteLLM supports multiple caching backends:- Local (In-Memory) - Default, fastest for single-instance deployments
- Redis - Distributed caching with Redis or Redis Cluster
- Redis Semantic Cache - Similarity-based caching using embeddings
- Qdrant Semantic Cache - Vector-based semantic caching
- S3 - Object storage caching
- GCS - Google Cloud Storage caching
- Azure Blob - Azure Blob Storage caching
- Disk - File-system based caching
Quick Start
Basic In-Memory Caching
Redis Cache
Configuration Options
Cache Initialization
Redis Cluster Support
Semantic Caching
Semantic caching uses embeddings to match similar queries, not just exact matches.Redis Semantic Cache
Qdrant Semantic Cache
Cloud Storage Caching
S3 Cache
GCS Cache
Azure Blob Cache
Advanced Features
Cache Control
Control caching behavior per request:Opt-in Caching Mode
Caching Across Model Groups
Cache responses across different models in the same group:Cache Key Generation
Cache keys are generated from:- Model name
- Messages/input
- All API parameters (temperature, max_tokens, etc.)
- Namespace (if configured)
Changing any parameter (even optional ones) will create a different cache key.
Performance Considerations
Cache Type Performance
- Local: Fastest, but not shared across instances
- Redis: Good balance of speed and distribution
- Semantic: Slower due to embedding computation, but matches similar queries
- Cloud Storage (S3/GCS/Azure): Higher latency, use for long-term storage
Monitoring Cache Usage
Best Practices
- Use Redis for production - Enables distributed caching across multiple instances
- Set appropriate TTLs - Balance between cost savings and data freshness
- Use semantic caching for Q&A - Great for customer support and documentation queries
- Monitor cache hit rates - Track effectiveness of your caching strategy
- Use namespaces - Separate cache spaces for different environments or use cases
Disabling Cache
Related Features
- Load Balancing - Distribute requests across deployments
- Cost Tracking - Monitor cache savings
- Logging - Track cache hits and misses