mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-25 22:20:43 +00:00
* feat(proxy): supervise the opt-in Rust forwarding server With LITELLM_RUST on, `litellm` and `python -m gateway.launch` start a supervisor that runs the Rust gateway on the public port and Python on a private loopback listener. Python still serves every route and sees each request as if the client had connected to it directly. Rust sends the client's TCP peer in `x-litellm-rust-peer`. The supervised server turns server-level proxy headers off, and a middleware restores the peer and then applies the operator's own trust, so client IPs, trusted proxies and every IP-based setting behave the same with Rust on or off. The supervisor is transparent to Python. Signals pass through, Python's exit status is the result, and both children shut down when the supervisor's end of their stdin closes, so nothing outlives it. Rust starts only once Python listens. When forwarding cannot start (no gateway binary, TLS, a Unix socket, Hypercorn or Granian), the entry point warns and serves from Python alone. Every forwarding decision lives in litellm/proxy/rust_forward, paired with the gateway-forward crate. OS differences sit behind a Platform protocol, with Windows supported for local CLI runs. AGENTS.md files in the touched folders state the boundary. The `--rust_gateway` flag is gone in favor of the environment variable. * refactor(proxy): switch Rust forwarding on with LITELLM_RUST_FIRST Forwarding gets its own switch, independent of LITELLM_RUST, which keeps selecting only the Rust paths inside the SDK. Neither turns the other on. --------- Co-authored-by: narmstrong-berri <narmstrong@berri.ai>
1.5 KiB
1.5 KiB
Gateway image entry point
python -m gateway.launch is how the gateway image starts. launch.py hands its arguments to uvicorn's own CLI and serves main.py, which trims the proxy app to the LLM data plane
- Importing
launch.pystays cheap. Every uvicorn worker imports it again before it can answer its first health ping, so LiteLLM imports wait untilmainorworker_appruns - PgBouncer starts exactly once per pod, before the workers start, and the workers inherit the loopback URL through
DATABASE_URL.configure_databaseis the only place that does this
Rust forwarding
launch.py is an entry point of Rust forwarding, and every forwarding decision lives in litellm/proxy/rust_forward/, whose AGENTS.md states the contract
maindispatches onrust_forward_modeand does nothing else about forwarding. With forwarding off or refused it serves exactly as beforepython_serverreads the flags and environment through uvicorn's own CLI parser, so Rust gets the values uvicorn would run with. Never reparse a uvicorn flag by hand- Under forwarding the supervisor process runs
configure_database, asbefore_start, once forwarding is known to be possible. The supervised child never runs it and inherits the exported URL - The supervised child appends
mode.uvicorn_flagsafter the operator's flags, so the private listener and--no-proxy-headerswin worker_appwraps the app withpeer.wrap, which is the identity when forwarding is off