* docs: realtime pre-warmed connection pool design + raw-passthrough follow-up * docs: realtime pool benchmark, repro steps, and deploy guidance * feat: expose Router::deployments() for host-side upstream enumeration * refactor: split realtime dial/splice and add warm-handoff entry point * feat: pre-warmed upstream realtime connection pool with fresh-dial fallback * feat: add realtime pool handle to gateway AppState * feat: try warm pooled upstream before fresh-dial in realtime service * feat: thread realtime pool through the realtime route bridge * feat: build and pre-warm the realtime pool at gateway startup * build: lean Dockerfile for the realtime gateway (default features, env stand-in) Minimal multi-stage image for load-testing the realtime pool: builds the gateway with default features (no python-config, no libpython), runs on a debian-slim base (~157MB), and reads model_list from the OPENAI_REALTIME_MODEL env stand-in. No config.yaml or pip install needed. Build context is the repo root; only litellm-rust/ is included via the sidecar .dockerignore. * docs: add generic ai-gateway benchmarking skill Teaches an agent how to benchmark any ai-gateway endpoint: deploy the gateway, run one load generator against both provider-direct and the gateway with the same protocol, phase-decompose latency (dial/session/first-token/total), compare at scale, and report success% + p50/p95. Documents the benchmarks/<endpoint>/ layout and the hard no-committed-keys rule. * docs: drop per-endpoint realtime benchmark README The measured results table lives in the PR description (numbers go stale in a committed README). The benchmarks/realtime/ dir now holds only the sanitized load-gen harness; the generic method is in benchmarks/SKILL.md. * test: add sanitized realtime WS load-gen harness for gateway benchmarks Copies the ws-bench Go load generator (main.go, go.mod, go.sum, Dockerfile, run.sh) into benchmarks/realtime/. Measures dial/session/first-audio/total per WebSocket connection against both OpenAI-direct and the gateway. No keys are hardcoded — the bearer token comes from -key / $OPENAI_API_KEY; default host is api.openai.com. * test: add hosted-runner serve.sh wrapper for the realtime harness Render one-off jobs don't surface stdout via the Logs API, so on a hosted runner the long-lived web service runs the leg and PUBLISHES the result: serve.sh decodes the base64 flag list, runs wsbench teeing output to /tmp/web/result.txt, then serves it over HTTP so the result is fetchable at /result.txt. No secrets are written to the served file (the -key is only in wsbench's argv). The Dockerfile now copies both run.sh and serve.sh. * test: make serve.sh publish result atomically and clear stale output Remove any prior result.txt at startup and write the new run to a .partial file that's atomically moved into place only once complete. Prevents a fetcher from reading a previous run's numbers while the current run is still in flight. * perf: refill the realtime pool concurrently so warm supply keeps up at scale The replenisher dialed missing warm sockets sequentially, so a full refill cost needed x handshake (~needed x 350ms). Under high connect rates the pool drained faster than it refilled and ~85% of connects missed (measured: only ~15% pool hits at 5000/500). Firing the dials together with join_all refills in ~one handshake window, keeping warm supply close to peak concurrent connects so the sub-millisecond warm handoff becomes the median rather than the lucky-hit tail. Each warm_one dial is independent (no shared state until the final push under the lock), so concurrent refill is safe. Pool unit tests unchanged and passing. * build: drop Dockerfile.lean The lean load-test image isn't worth carrying in the repo; deploy the gateway however you normally do and set the pool env vars. * docs: slim benchmarks/realtime to a README (harness moved to its own repo) Drop the Go load-gen, Dockerfile, run.sh, serve.sh, and the generic SKILL.md from the repo. The harness now lives at github.com/ishaan-berri/litellm-realtime-bench; benchmarks/realtime/README.md carries the results table and links there for repro. * docs: add realtime route README with pooling design + diagram Pooling is now documented as a section in src/routes/realtime/README.md next to the code (handoff diagram, sizing rule, config, notes) instead of the standalone REALTIME_POOL_DESIGN.md RFC. Update the realtime_pool.rs doc pointer to it. * fix: satisfy clippy manual_flatten on concurrent pool refill Use .into_iter().flatten() instead of an if-let-Ok in the for loop over the join_all results, and let rustfmt wrap it. Clears the CI clippy -D warnings failure; fmt + clippy + cargo test all green locally. --------- Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com> |
||
|---|---|---|
| .. | ||
| benchmarks/realtime | ||
| src | ||
| AGENTS.md | ||
| Cargo.toml | ||
| config.yaml | ||
| Dockerfile | ||
| Dockerfile.dockerignore | ||
| README.md | ||
| render.yaml | ||
LiteLLM Rust AI Gateway
A minimal Axum service that fronts OpenAI's realtime API. Clients open a
WebSocket to GET /v1/realtime; the gateway authenticates, selects a deployment,
dials OpenAI upstream, and splices the two sockets frame-by-frame.
- Client endpoint:
wss://<host>/v1/realtime?model=<model>(WebSocket) - Auth:
Authorization: Bearer $LITELLM_MASTER_KEY(fails closed if unset) - Health:
GET /health/readiness,GET /health/liveness,GET /health/gil
Realtime serving is pure Rust. Python is used at load time only — to read the config once at boot. The realtime hot path never touches Python.
Configuration (config.yaml)
The gateway loads its model_list from a config.yaml, the same as the
LiteLLM proxy. Point LITELLM_CONFIG_PATH at the file:
# config.yaml
model_list:
- model_name: gpt-realtime
litellm_params:
model: openai/gpt-realtime
api_key: os.environ/OPENAI_API_KEY
LITELLM_CONFIG_PATH=./config.yaml ./litellm-ai-gateway
At boot the gateway calls into litellm.proxy.read_model_list, which reuses the
real proxy config reader (ProxyConfig.get_config). That means everything
the proxy supports in config.yaml works here too:
include:to merge in other config files,os.environ/VARsecret references (resolved via the secret manager, never inlined),- DB-stored models (when a database is configured).
Secrets stay out of the config — reference them with os.environ/... and set
the env var at deploy time. The shipped Docker image is built with the
python-config feature and bundles litellm, so config loading works out of
the box; the default baked config lives at /app/config.yaml and can be
overridden at deploy time (e.g. a Render secret file mounted at the same path).
Environment variables
| Var | Required | Default | Purpose |
|---|---|---|---|
LITELLM_CONFIG_PATH |
yes (config mode) | — | Path to the config.yaml the gateway loads its model_list from. The Docker image defaults this to /app/config.yaml. |
LITELLM_MASTER_KEY |
yes | — | Bearer token clients must send. Unset ⇒ all /v1/realtime requests are rejected (fail closed). |
OPENAI_API_KEY |
yes | — | Upstream OpenAI key. Referenced by config.yaml as os.environ/OPENAI_API_KEY for the gateway→OpenAI dial. |
HOST |
no | 127.0.0.1 |
Set to 0.0.0.0 in any container/deploy or external traffic is refused. |
PORT |
no | 4001 |
Listen port. Render and most PaaS inject this automatically. |
Secrets (
LITELLM_MASTER_KEY,OPENAI_API_KEY) are never baked into the image orrender.yaml— inject them at deploy time only.
Lean env stand-in (fallback)
If the binary is built without python-config (default features), or
LITELLM_CONFIG_PATH is unset, the gateway falls back to a single-deployment
stand-in built from the environment:
| Var | Default | Purpose |
|---|---|---|
OPENAI_REALTIME_MODEL |
gpt-realtime |
The single deployment's model name (also the ?model= clients pass). |
This mode links no libpython and needs no config file, but it only supports one hard-coded OpenAI deployment. config.yaml is the recommended path — use the stand-in only for the leanest possible build.
Build & run with Docker
The image is built --features python-config and installs litellm from this
repo's source (the config reader is newer than any PyPI release), so the build
context is the repo root:
# from the repo root
docker build -f litellm-rust/crates/ai-gateway/Dockerfile -t litellm-ai-gateway .
docker run --rm -p 4001:4001 \
-e HOST=0.0.0.0 -e PORT=4001 \
-e LITELLM_MASTER_KEY=sk-local \
-e OPENAI_API_KEY=$OPENAI_API_KEY \
litellm-ai-gateway # LITELLM_CONFIG_PATH defaults to /app/config.yaml
# smoke test
curl -s -o /dev/null -w '%{http_code}\n' localhost:4001/health/readiness # -> 200
curl -s -o /dev/null -w '%{http_code}\n' localhost:4001/v1/realtime # -> 401 (auth fails closed)
On boot you should see loaded model_list from /app/config.yaml via python config reader — that confirms the config path (not the env stand-in fallback).
To use your own config, mount it over the default:
docker run --rm -p 4001:4001 \
-e HOST=0.0.0.0 -e LITELLM_MASTER_KEY=sk-local -e OPENAI_API_KEY=$OPENAI_API_KEY \
-v $(pwd)/my-config.yaml:/app/config.yaml:ro \
litellm-ai-gateway
Cargo-only (no Docker)
# config.yaml mode — needs litellm importable in the active python env
LITELLM_CONFIG_PATH=./crates/ai-gateway/config.yaml \
cargo run --release -p litellm-ai-gateway --features python-config
# env stand-in mode — no python, no config
cargo run --release -p litellm-ai-gateway
Deploy on Render
The service is a Docker web service; Render terminates TLS and supports
WebSockets, so the public endpoint is wss://<service>.onrender.com/v1/realtime.
Option A — Blueprint (render.yaml)
crates/ai-gateway/render.yaml describes the service (Docker runtime,
healthCheckPath: /health/readiness, repo-root dockerContext: .,
dockerfilePath: ./litellm-rust/crates/ai-gateway/Dockerfile,
LITELLM_CONFIG_PATH: /app/config.yaml). LITELLM_MASTER_KEY and
OPENAI_API_KEY are sync: false — set them in the dashboard after the first
deploy. To use a non-default model_list, mount a Render Secret File at
/app/config.yaml. Point a Render Blueprint at this repo/branch and apply.
Option B — Render API
# create a Docker web service from this repo+branch, then set env vars:
curl -X POST https://api.render.com/v1/services \
-H "Authorization: Bearer $RENDER_API_KEY" -H "Content-Type: application/json" \
-d '{
"type": "web_service", "name": "litellm-rust-ai-gateway",
"ownerId": "<owner-id>", "repo": "https://github.com/BerriAI/litellm",
"branch": "<branch-with-this-dockerfile>",
"serviceDetails": {
"env": "docker",
"envSpecificDetails": {
"dockerfilePath": "./litellm-rust/crates/ai-gateway/Dockerfile",
"dockerContext": "."
},
"healthCheckPath": "/health/readiness"
}
}'
# then set env vars LITELLM_MASTER_KEY, OPENAI_API_KEY, HOST=0.0.0.0,
# LITELLM_CONFIG_PATH=/app/config.yaml
Health check path must be /health/readiness. autoDeploy is off by default
in the blueprint — trigger deploys manually (or flip it on) to pick up new commits.
Scaling
Concurrency is what matters, not total connections: each in-flight session holds
one client socket + one upstream socket. To scale, raise the instance count /
enable autoscaling on the Render service (e.g. baseline 10, max 100). Each
instance needs file descriptors for 2 × peak_concurrent_sessions — raise
ulimit -n if you push very high concurrency.
Latency note
The gateway adds the cost of one extra hop: client→gateway, then a fresh
gateway→OpenAI realtime handshake (TLS + WS upgrade + session.created). In
benchmarks this is ~100–150 ms of added session-establishment time; first-audio
and steady-state streaming add no measurable overhead. To minimize it, deploy the
gateway in the Render region with the lowest RTT to OpenAI's realtime endpoint.