Using LibreChat with LiteLLM Proxy
LiteLLM is a proxy server that allows LibreChat to access and load balance across over 100 large language models (LLMs) from various providers.
Using LibreChat with LiteLLM Proxy
Use LiteLLM Proxy for:
- Calling 100+ LLMs Huggingface/Bedrock/TogetherAI/etc. in the OpenAI ChatCompletions & Completions format
- Load balancing - between Multiple Models + Deployments of the same model LiteLLM proxy can handle 1k+ requests/second during load tests
- Authentication & Spend Tracking Virtual Keys
Start LiteLLM Proxy Server
1. Uncomment desired sections in docker-compose.override.yml
The override file contains sections for the below LiteLLM features
Minimum working docker-compose.override.yml
Example:
api:
volumes:
- type: bind
source: ./librechat.yaml
target: /app/librechat.yaml
litellm:
image: ghcr.io/berriai/litellm:main-latest
volumes:
- ./litellm/litellm-config.yaml:/app/config.yaml
# NOTE: For Google - required auth "GOOGLE_APPLICATION_CREDENTIALS" envronment and volume mount
# This also means you need to add the `application_default_credentaials.json` file within ~/litellm
- ./litellm/application_default_credentials.json:/app/application_default_credentials.json
ports:
- "4000:8000"
command: [ "--config", "/app/config.yaml", "--port", "8000", "--num_workers", "8" ]
For Google - see above about required auth "GOOGLE_APPLICATION_CREDENTIALS" envronment and volume mount
environment:
GOOGLE_APPLICATION_CREDENTIALS: /app/application_default_credentials.json
Caching with Redis
Litellm supports in-memory, redis, and s3 caching. Note: Caching currently only works with exact matching.
Performance Monitoring with Langfuse
Litellm supports various logging and observability options. The settings below will enable Langfuse which will provide a cache_hit tag showing which conversations used cache.
2. Create a Config for LiteLLM proxy
LiteLLM requires a configuration file in addition to the override file. Within LibreChat, this will be litellm/litellm-config.yml
. The file
below has the options to enable llm proxy to various providers, load balancing, Redis caching, and Langfuse monitoring. Review documentation for other configuration options.
More information on LiteLLM configurations here: docs.litellm.ai/docs/simple_proxy
Working Example of incorporating OpenAI, Azure OpenAI, AWS Bedrock, and GCP
Please note the ...
being a secret or a value you should not share (API key, custom tenant endpoint, etc)
You can potentially use env variables for these too, ex: api_key: "os.environ/AZURE_API_KEY" # does os.getenv("AZURE_API_KEY")
Example of a few Different Options (ex: rpm, stream, ollama)
3. Configure LibreChat
Use librechat.yaml
Configuration file (guide here) to add Reverse Proxies as separate endpoints.
Here is an example config:
custom:
- name: "Lite LLM"
# A place holder - otherwise it becomes the default (OpenAI) key
# Provide the key instead in each "model" block within "litellm/litellm-config.yaml"
apiKey: "sk-from-config-file"
# See the required changes above in "Start LiteLLM Proxy Server" step.
baseURL: "http://host.docker.internal:4000"
# A "default" model to start new users with. The "fetch" will pull the rest of the available models from LiteLLM
# More or less this is "irrelevant", you can pick any model. Just pick one you have defined in LiteLLM.
models:
default: ["gpt-3.5-turbo"]
fetch: true
titleConvo: true
titleModel: "gpt-3.5-turbo"
summarize: false
summaryModel: "gpt-3.5-turbo"
forcePrompt: false
modelDisplayLabel: "Lite LLM"
Why use LiteLLM?
-
Access to Multiple LLMs: It allows calling over 100 LLMs from platforms like Huggingface, Bedrock, TogetherAI, etc., using OpenAI’s ChatCompletions and Completions format.
-
Load Balancing: Capable of handling over 1,000 requests per second during load tests, it balances load across various models and deployments.
-
Authentication & Spend Tracking: The server supports virtual keys for authentication and tracks spending.
Key components and features include:
- Installation: Easy installation.
- Testing: Testing features to route requests to specific models.
- Server Endpoints: Offers multiple endpoints for chat completions, completions, embeddings, model lists, and key generation.
- Supported LLMs: Supports a wide range of LLMs, including AWS Bedrock, Azure OpenAI, Huggingface, AWS Sagemaker, Anthropic, and more.
- Proxy Configurations: Allows setting various parameters like model list, server settings, environment variables, and more.
- Multiple Models Management: Configurations can be set up for managing multiple models with fallbacks, cooldowns, retries, and timeouts.
- Embedding Models Support: Special configurations for embedding models.
- Authentication Management: Features for managing authentication through virtual keys, model upgrades/downgrades, and tracking spend.
- Custom Configurations: Supports setting model-specific parameters, caching responses, and custom prompt templates.
- Debugging Tools: Options for debugging and logging proxy input/output.
- Deployment and Performance: Information on deploying LiteLLM Proxy and its performance metrics.
- Proxy CLI Arguments: A wide range of command-line arguments for customization.
Overall, LiteLLM Server offers a comprehensive suite of tools for managing, deploying, and interacting with a variety of LLMs, making it a versatile choice for large-scale AI applications.