LiteLLM is an open-source Python SDK and proxy server (LLM Gateway) that enables calling over 100 large language model APIs in OpenAI format, including major providers like Bedrock, Azure, OpenAI, VertexAI, Cohere, Anthropic, Sagemaker, HuggingFace, Replicate, and Groq.
GitHub: https://github.com/BerriAI/litellm
['choices'][0]['message']['content']
.from litellm import completion
import os
os.environ["OPENAI_API_KEY"] = "your-openai-key"
os.environ["ANTHROPIC_API_KEY"] = "your-anthropic-key"
messages = [{"content": "Hello, how are you?", "role": "user"}]
# OpenAI
response = completion(model="openai/gpt-4o", messages=messages)
# Anthropic
response = completion(model="anthropic/claude-3-sonnet-20240229", messages=messages)
from litellm import acompletion
import asyncio
async def test_get_response():
user_message = "Hello, how are you?"
messages = [{"content": user_message, "role": "user"}]
response = await acompletion(model="openai/gpt-4o", messages=messages)
return response
response = asyncio.run(test_get_response())
from litellm import completion
response = completion(model="openai/gpt-4o", messages=messages, stream=True)
for part in response:
print(part.choices[0].delta.content or "")
pip install 'litellm[proxy]'
litellm --model huggingface/bigcode/starcoder
# INFO: Proxy running on http://0.0.0.0:4000
import openai
client = openai.OpenAI(
api_key="anything",
base_url="http://0.0.0.0:4000"
)
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{
"role": "user",
"content": "this is a test request, write a short poem"
}]
)
LiteLLM supports over 30 major LLM providers, including:
LiteLLM has built-in support for various monitoring and logging platforms:
import litellm
import os
os.environ["LUNARY_PUBLIC_KEY"] = "your-lunary-public-key"
os.environ["HELICONE_API_KEY"] = "your-helicone-auth-key"
os.environ["LANGFUSE_PUBLIC_KEY"] = "your-langfuse-public-key"
litellm.success_callback = [
"lunary", "mlflow", "langfuse",
"athina", "helicone"
]
response = completion(
model="openai/gpt-4o",
messages=[{"role": "user", "content": "Hi 👋"}]
)
Supported monitoring platforms:
curl 'http://0.0.0.0:4000/key/generate' \
--header 'Authorization: Bearer sk-1234' \
--header 'Content-Type: application/json' \
--data-raw '{
"models": ["gpt-3.5-turbo", "gpt-4", "claude-2"],
"duration": "20m",
"metadata": {
"user": "user@company.com",
"team": "core-infra"
}
}'
git clone https://github.com/BerriAI/litellm
cd litellm
echo 'LITELLM_MASTER_KEY="sk-1234"' > .env
echo 'LITELLM_SALT_KEY="your-salt-key"' > .env
docker-compose up
/ui
for a visual management interface.openai>=1.0.0
(v1.0.0+ required)pydantic>=2.0.0
(v1.40.14+ required)-stable
tag.pip install litellm
pip install 'litellm[proxy]'
git clone https://github.com/BerriAI/litellm
cd litellm
python -m venv .venv
source .venv/bin/activate
pip install -e ".[all]"
uvicorn litellm.proxy.proxy_server:app --host localhost --port 4000 --reload
LiteLLM has been adopted by well-known companies such as Rocket Money, Samsara, Lemonade, and Adobe. By providing a unified API interface, powerful routing capabilities, and enterprise-grade management features, it significantly simplifies the management complexity of multi-LLM environments, making it an ideal choice for modern AI application development.