Home Knowledge Base LiteLLM

LiteLLM is a Python library and proxy server that provides a unified OpenAI-compatible interface to 100+ LLM providers — enabling developers to switch between GPT-4, Claude, Gemini, Llama, Mistral, and any other model by changing a single string, with built-in cost tracking, rate limiting, fallbacks, and load balancing across providers.

What Is LiteLLM?

Why LiteLLM Matters

Core Python Usage

Basic Unified Call:

from litellm import completion

# Same interface, different models
response = completion(model="gpt-4o", messages=[{"role":"user","content":"Hello!"}])
response = completion(model="claude-3-5-sonnet-20241022", messages=[{"role":"user","content":"Hello!"}])
response = completion(model="gemini/gemini-1.5-pro", messages=[{"role":"user","content":"Hello!"}])
response = completion(model="ollama/llama3", messages=[{"role":"user","content":"Hello!"}])

Fallbacks:

from litellm import completion

response = completion(
    model="gpt-4o",
    messages=[{"role":"user","content":"Summarize this document."}],
    fallbacks=["claude-3-5-sonnet-20241022", "gemini/gemini-1.5-pro"],
    num_retries=2
)

Async + Load Balancing:

from litellm import Router

router = Router(model_list=[
    {"model_name": "gpt-4", "litellm_params": {"model":"gpt-4o", "api_key":"key1"}},
    {"model_name": "gpt-4", "litellm_params": {"model":"gpt-4o", "api_key":"key2"}},  # Round-robin across keys
])
response = await router.acompletion(model="gpt-4", messages=[...])

Proxy Server Setup

# config.yaml for LiteLLM proxy
model_list:
  - model_name: gpt-4
    litellm_params:
      model: openai/gpt-4o
      api_key: sk-...
  - model_name: claude
    litellm_params:
      model: anthropic/claude-3-5-sonnet-20241022
      api_key: sk-ant-...

router_settings:
  routing_strategy: least-busy
  fallbacks: [{"gpt-4": ["claude"]}]

Run with: litellm --config config.yaml --port 8000

Then existing OpenAI SDK code connects with just base_url="http://localhost:8000".

Key LiteLLM Features

LiteLLM vs Alternatives

FeatureLiteLLMPortKeyDirect SDK
Provider coverage100+20+1 per SDK
Proxy modeYesYesNo
Cost trackingBuilt-inBuilt-inManual
Open sourceYes (MIT)PartiallyVaries
Self-hostableYesYesN/A

LiteLLM is the essential abstraction layer for any LLM application that needs to work across multiple providers — by normalizing 100+ provider APIs into the single most-familiar interface in AI development, LiteLLM enables teams to evaluate models, optimize costs, and ensure reliability without writing provider-specific integration code.

litellmproxyunified

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.