軽量LLMルーティングライブラリ「litelm」公開、vLLMやOllamaに対応

概要
軽量なLLMルーティングライブラリである litelm が公開されました。このライブラリは、既存の litellm から、モデルのルーティングとメッセージ形式の変換というコア機能のみを抽出し、コード量と依存関係を最小限に抑えることを目的としています。
主張と根拠
開発者の主張によれば、litelm は litellm が持つプロキシサーバー、キャッシュ層、コスト追跡、および多くのユーザーが利用しない数十もの機能を排除することで、約2,900行のコードと2つの依存関係(openai, httpx)のみで構成されています。
機能比較
litellm と litelm の機能の有無に関する比較は以下の通りです。
| 機能 | litellm | litelm |
|---|---|---|
| Model routing (provider/model → right endpoint) | ✓ | ✓ |
| Message translation (Anthropic, Bedrock, Cloudflare, Mistral) | ✓ | ✓ |
| Streaming + stream_chunk_builder | ✓ | ✓ |
| Tool use (function calling) | ✓ | ✓ |
| Embeddings | ✓ | ✓ |
| Text completions | ✓ | ✓ |
| OpenAI Responses API | ✓ | ✓ |
| Mock responses | ✓ | ✓ |
| Router (load balancing, fallbacks) | ✓ | ✗ |
| Proxy server | ✓ | ✗ |
| Caching / budgeting / cost tracking | ✓ | ✗ |
| Token counting | ✓ | ✗ |
| Image gen, audio, OCR, fine-tuning | ✓ | ✗ |
| Agents, guardrails, scheduler | ✓ | ✗ |
プロバイダーの対応状況
litelm は「provider/model-name」という構文を用いて19のプロバイダーへのルーティングに対応しています。ただし、以下のプロバイダーについては、資料内で動作が未確認(Verified: No)と報告されています。
- Bedrock, Cloudflare, Together, Fireworks, DeepSeek, Perplexity, DeepInfra, Gemini, Cohere, Ollama, vLLM, LM Studio
一方で、OpenAI, Anthropic, Groq, Mistral, xAI, OpenRouter, Azure については、動作が確認(Verified: Yes)されています。
開発ステータスと検証
本プロジェクトは現在 Alpha ステータスです。開発者による報告では、以下の検証が行われています。
- 360個のコアパスのコミットをレビューし、互換性のギャップを修正。
- ローカルのスコープテスト:262個がパス、55個がスキップ。
- 利用可能な全45個のプロバイダー・ライブテストがパス。
- 全10個の DSPy スモークテストがパス。
- DSPy のドロップイン互換性(Predict, CoT, typed signatures, streaming, embeddings, tool use, multi-output)も検証済み。
前提条件
- 言語: Python
- 依存関係:
openai,httpx(標準インストール時) - 必要に応じて追加のSDK(
anthropic,boto3など)
手元で再現できる範囲
pip を使用してインストール可能です。
pip install litelm # openai + httpx
pip install litelm[anthropic] # + anthropic SDK
pip install litelm[bedrock] # + boto3
pip install litelm[all] # everything
基本的な使用方法
APIは litellm をミラーリングしており、関数名、引数、レスポンスタイプが共通です。すべての関数には非同期版(acompletion, aembedding, aresponses, atext_completion)が用意されています。
import litelm
# 基本的な Completion
response = litelm.completion("openai/gpt-4o", messages=[{"role": "user", "content": "Hello!"}])
print(response.choices[0].message.content)
# ストリーミング
for chunk in litelm.completion("groq/llama-3.1-70b-versatile", messages=[...], stream=True):
print(chunk.choices[0].delta.content or "", end="")
# Embeddings
response = litelm.embedding("openai/text-embedding-3-small", input=["hello world"])
エラーハンドリング
プロバイダーのエラーは、litelm の例外階層にマッピングされます。
from litelm import ContextWindowExceededError, RateLimitError, AuthenticationError
try:
response = litelm.completion("openai/gpt-4o", messages=messages)
except ContextWindowExceededError:
# プロンプトが長すぎる場合の処理
pass
except RateLimitError:
# レート制限への対応
pass
except AuthenticationError:
# APIキー不正の処理
pass
ローカル・カスタムプロバイダー
api_base を指定することで、OpenAI 互換のエンドポイントを持つ任意のサーバーを利用できます。
# vLLM
litelm.completion("openai/my-model", messages=[...], api_base="http://localhost:8000/v1")
# Ollama
litelm.completion("ollama/llama3", messages=[...], api_base="http://localhost:11434/v1")
# LM Studio
litelm.completion("openai/local-model", messages=[...], api_base="http://localhost:1234/v1")
Tool Calling の利用
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}},
}
}]
response = litelm.completion(
"openai/gpt-4o",
messages=[{"role": "user", "content": "Weather in Paris?"}],
tools=tools,
tool_choice="required",
)
tool_call = response.choices[0].message.tool_calls[0]
print(tool_call.function.name, tool_call.function.arguments)
資料が触れていないこと
litellmと比較した際の、具体的なレイテンシやメモリ使用量の改善に関する数値。- 未確認(Verified: No)とされているプロバイダーにおける、具体的な動作の安定性。
出典
更新履歴
- 2026-09-19: 下書きに戻していた記事を、材料を集め直して書き直し、公開に戻しました。

