litellm internal architecture
A documentation series on how the litellm codebase is put together, what it seems to be aiming for, and where it falls short of that today. Written for people changing the code, not for users of the product. Checked against BerriAI/litellm main at 13118948 on 2026-10-15
Diagrams are hand-laid-out SVG files in diagrams/, generated by the scripts in tools/diagrams/. Edit a script and rerun it to change a picture
Start here
explanation/01-system-overview.md gives the big picture and the seven design principles the code implies, with a one-line verdict on each. Then pick by what you need
Explanation (why it's shaped this way, and where the shape breaks)
| Page |
Covers |
| 01 System overview |
The pieces, the intended principles, how they hold up |
| 02 Layers and dependency direction |
The implied layer stack, measured import edges, global state as hidden coupling |
| 03 Data-plane request pipeline |
The seven stages every LLM call passes through, and how each API surface deviates |
| 04 Control plane, config and state |
Config sources, startup order, where state lives, how changes reach other pods |
| 05 Extension points |
Callbacks, guardrails and hooks, and where they fire |
| 06 Python and Rust |
The Rust migration's intended end state, the rollout switch, what actually runs in Rust |
| 07 Deployment shapes |
Monolith, componentized gateway/backend/UI, Rust gateway, and the lazy-route hole in the split |
Reference (look things up)
| Page |
Covers |
| Surface map |
Every product surface mapped to its entry code, with route families and counts |
| User flows, data plane |
Sequence diagrams for chat, Messages, Responses, pass-through, MCP and direct SDK calls |
| User flows, control plane |
Startup, key creation and use, model add, spend and budgets, guardrails, callbacks |
| Flow and subsystem matrix |
Which flows touch which subsystems, and the blast radius of changing each |
| Gap register |
Every intent-vs-reality gap in one table with evidence and impact |
How-to
Tutorial
| Page |
Covers |
| Follow one request |
Run a local proxy with a mock model and match each pipeline stage to a debug log line |
Related notes in this project
The series builds on earlier work in /mnt/project-files/invariants/: the candidate invariants survey, the layer inversion plan (Linear LIT-9423), the permission-check map, the extension-point docs audit, the test-suite map and the config coverage notes. The scan scripts it relies on are in invariants/tools/ and tools/