litelm
litellm's routing + translation in ~2,900 lines and 2 dependencies ( openai , httpx ).
litellm routes LLM calls across providers and translates between message formats. That core is buried under 100k+ LOC of proxy servers, caching layers, cost tracking, and dozens of features most users never touch. litelm extracts just the call path — model routing, message translation, streaming, tool use, embeddings — and nothing else. No Router class, no proxy, no caching.
Install
pip install litelm # openai + httpx pip install litelm[anthropic] # + anthropic SDK pip install litelm[bedrock] # + boto3 pip install litelm[all] # everything
Usage
import litelm # Basic completion response = litelm . completion ( "openai/gpt-4o" , messages = [{ "role" : "user" , "content" : "Hello!" }]) print ( response . choices [ 0 ]. message . content ) # Streaming 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" ])
Every function has an async variant: acompletion , aembedding , aresponses , atext_completion .
The API mirrors litellm — same function names, same arguments, same response types. If you're using litellm today, switching is s/litellm/litelm/ in your imports.
What's in / what's out
... continue reading