Skip to main content

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)
The cache key is hashed using SHA-256 for consistency.
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

  1. Use Redis for production - Enables distributed caching across multiple instances
  2. Set appropriate TTLs - Balance between cost savings and data freshness
  3. Use semantic caching for Q&A - Great for customer support and documentation queries
  4. Monitor cache hit rates - Track effectiveness of your caching strategy
  5. Use namespaces - Separate cache spaces for different environments or use cases

Disabling Cache