Skip to main content

Code map

Since v1.110.0

Where the router's code lives. Paths are relative to the repo root.

The router code map: the Python facade and its modules lead to the RustCore
step driver, the router_rust step modules, the python-bridge crate and the
router-core crate

Python​

FileHolds
litellm/router.pyRouter, the facade. It builds the config, chooses the core and delegates every member
litellm/router_api.pythe entry point views and types, see Entry points, plus ROUTER_INIT_ARGS and apply_changes
litellm/router_core.pythe RouterCore protocol and make_core
litellm/router_config.pyRouterConfig, RouterDynamicConfig, and the only router reads of litellm.* settings
litellm/router_deprecated.pyDeprecatedRouterMembers, the old member names with a DeprecationWarning
litellm/router_python_host.pyPythonHost, the host inside a Python process: endpoint functions, sleep, dynamic config, callbacks, caches
litellm/router_host.pyRouterHost, what only the application can answer, and litellm/proxy/_router_host.py with the proxy's version
litellm/router_strategy/the stateful strategies, lar1, the sub-routers, the budget limiter and tag routing. The core reaches them through the select and pre-route steps
litellm/router_utils/helpers the host uses, such as the cooldown cache, the health state cache, pre-call checks and the response headers
litellm/litellm_core_utils/helpers the router and other modules share, such as wildcard matching, PTU shares and the retry and fallback headers
litellm/types/router.pyDeployment, RoutingGroup, RetryPolicy and the other config types
litellm/proxy/route_llm_request.pymaps a proxy request to a Router endpoint method

litellm/router_rust/​

Everything the core needs on the Python side.

PathHolds
core.pyRustCore, the step driver for async and sync calls
steps/answers to the steps that need live Python objects: selection.py (strategies), prerouting.py (sub-routers, session binding, custom strategies), precall.py (pre-call facts), plugins.py (Router(plugins=[...])), callbacks.py (CustomLogger filters), access.py (caller access facts)
invoke/one attempt: endpoints.py (the endpoint wrappers), shaping.py (request and response shaping), streaming.py (stream wrappers that report the outcome when a stream ends), slots.py (max_parallel_requests), walk.py (retry and fallback metadata), prompt_management.py, websocket.py
surface/the Python Router API over the core's state: registry.py, model_list.py, indexes.py, members.py, model_info.py, settings.py, health.py, health_routing.py, retries.py, fallbacks.py, alerting.py, replay.py

litellm/router_attempt.py builds the keyword arguments of one attempt for the deployment the core picked. It does not pick, retry or record anything.

Rust​

litellm-rust/crates/router-core/src/.

FileHolds
lib.rsRouter, RouterBuilder, and the crate overview
config.rsRouterConfig, RouterDynamicConfig, Op, RoutingStrategy, retry and allowed fails policies
registry.rsRegistry, Deployment, ChangeSet, deployment_id
build.rsbuilding deployments from config with the host's secrets, validate, provider and added steps
resolve.rsname resolution, a port of _common_checks_available_deployment
select.rsthe filter chain and simple-shuffle
access.rs, ptu.rs, health_routing.rs, precall.rsthe access group and window, PTU share, health check and pre-call filters
prerouting.rs, routing_plugins.rs, routing_groups.rspre-routing, routing plugin candidates and routing group members
strategy.rs, weights.rswhich strategy a pick uses, and per-request weights
call.rs, call/stream.rsthe call loop with retries, fallbacks and weighted failover, and stream recovery
retry.rs, fallback.rs, mock.rsretry rules, the fallback lists, and mock_testing_* failures
health.rscooldowns, allowed fails, usage, and the cache keys
cache.rsRouterCache and an in-memory implementation for tests
settings.rsthe frozen Settings view
host.rsHost, Attempt, RouterRequest, RouterEvent, RoutingContext
lookup.rs, host_index.rsthe indexes and listings the Python surface reads
model_info.rs, group_info.rsmodel info and model group info merges
error.rsConfigError, Error, AttemptError, FailureKind

litellm-rust/crates/python-bridge/src/router/ exposes the core to Python as RouterCoreHandle and RouterCall, turns Python's config and dynamic snapshot into the core's types, and turns each hostcall into a step.

Tests and checks​

PathWhat it covers
tests/unit/test_router/core/the core suite, run against the core with a scripted host: selection, retries and cooldowns, fallbacks, registry change sets, endpoints
litellm-rust/crates/router-core unit teststhe Rust modules, with seeded randomness and a test clock
tests/unit/test_router/router unit tests through the facade, including test_router_entry_points.py
tests/code_coverage_tests/router_surface_check.pythe shrink-only surface allowlist, run in CI
tests/code_coverage_tests/router_litellm_globals_check.pychecks that only litellm/router_config.py reads litellm.* settings
tests/code_coverage_tests/router_code_coverage.pychecks that every router function has a test
litefuzz translation-diff suitedifferential fuzzing of routing behavior, run on every change to the core
LiteLLM Enterprise
SSO/SAML, audit logs, spend tracking, multi-team management, and guardrails, built for production.
Learn more →