The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
build: add Dockerfile + render blueprint for rust ai-gateway (#31154)
ishaan-berria6b7dcc7d639
diff --git a/litellm-rust/crates/ai-gateway/Dockerfile b/litellm-rust/crates/ai-gateway/Dockerfilenew file mode 100644index 00000000000..adf6fca0741--- /dev/null+++ b/litellm-rust/crates/ai-gateway/Dockerfile@@ -0,0 +1,86 @@+# Multi-stage build for the LiteLLM Rust AI Gateway (realtime WebSocket proxy).+#+# Build context is the **repo root** so we can install `litellm` from this repo's+# source (the gateway loads its model_list via litellm.proxy.read_model_list,+# which is not in any PyPI release yet) AND build the rust workspace under+# litellm-rust/.+#+# docker build -f litellm-rust/crates/ai-gateway/Dockerfile -t litellm-ai-gateway .+#+# No secrets live in this file. Runtime config (LITELLM_MASTER_KEY,+# OPENAI_API_KEY referenced by config.yaml, etc.) is injected as environment+# variables at deploy time.++# ---- Chef -------------------------------------------------------------------+# cargo-chef caches the dependency build so only the gateway crate recompiles on+# a source-only change. python3-dev is present in every rust stage because the+# `python-config` feature links libpython via pyo3 (even in the cook step).+FROM rust:1.90-slim-bookworm AS chef+ENV PYO3_PYTHON=python3.11+RUN apt-get update \+ && apt-get install -y --no-install-recommends \+ python3 python3-dev pkg-config libssl-dev clang \+ && rm -rf /var/lib/apt/lists/* \+ && cargo install cargo-chef --locked --version 0.1.77+WORKDIR /build/litellm-rust++# ---- Planner ----------------------------------------------------------------+# Produce the dependency recipe from the rust workspace manifests + Cargo.lock.+FROM chef AS planner+COPY litellm-rust/ .+RUN cargo chef prepare --recipe-path recipe.json++# ---- Builder ----------------------------------------------------------------+FROM chef AS builder+# Cook (compile) just the dependencies first — this layer is cached and reused+# whenever only gateway source changes.+COPY --from=planner /build/litellm-rust/recipe.json recipe.json+RUN cargo chef cook --locked --release \+ -p litellm-ai-gateway --features python-config \+ --recipe-path recipe.json+# Now copy the real sources and build the gateway binary. Deps are already cooked+# above, so this step only recompiles the gateway crate.+COPY litellm-rust/ .+RUN cargo build --locked --release -p litellm-ai-gateway --features python-config++# ---- Runtime ----------------------------------------------------------------+# python:3.11-slim-bookworm ships libpython3.11, matching the builder's PyO3+# 3.11 ABI so the embedded interpreter links and imports cleanly.+FROM python:3.11-slim-bookworm AS runtime++# CA certificates for outbound TLS to the OpenAI realtime endpoint.+RUN apt-get update \+ && apt-get install -y --no-install-recommends ca-certificates \+ && rm -rf /var/lib/apt/lists/*++WORKDIR /app++# Install litellm (with proxy extras) FROM THIS REPO'S SOURCE so+# `import litellm.proxy.read_model_list` works — it is not on PyPI yet. Copy the+# package + packaging metadata, then pip install the proxy extra.+COPY pyproject.toml README.md LICENSE ./+COPY litellm/ ./litellm/+RUN pip install --no-cache-dir ".[proxy]"++# The compiled gateway binary (pure-Rust realtime hot path; Python is load-time+# only).+COPY --from=builder /build/litellm-rust/target/release/litellm-ai-gateway /usr/local/bin/litellm-ai-gateway++# Default config.yaml. A real deploy can override this (e.g. mount a Render+# secret file at the same path) — never bake secrets into the image.+COPY litellm-rust/crates/ai-gateway/config.yaml /app/config.yaml++# Bind to all interfaces (Render routes to 0.0.0.0:$PORT) and load the model_list+# from config.yaml via the embedded python config reader.+ENV HOST=0.0.0.0 \+ LITELLM_CONFIG_PATH=/app/config.yaml++# Drop to a non-root user. The realtime hot path needs no root privileges, so+# running unprivileged limits blast radius if the process is ever compromised.+# The binary in /usr/local/bin is world-executable (COPY default mode 755); we+# only need /app (and the config.yaml it reads) owned by the unprivileged user.+RUN useradd --system --no-create-home --uid 10001 appuser \+ && chown -R appuser:appuser /app+USER appuser++ENTRYPOINT ["/usr/local/bin/litellm-ai-gateway"]diff --git a/litellm-rust/crates/ai-gateway/Dockerfile.dockerignore b/litellm-rust/crates/ai-gateway/Dockerfile.dockerignorenew file mode 100644index 00000000000..030ee6a37c5--- /dev/null+++ b/litellm-rust/crates/ai-gateway/Dockerfile.dockerignore@@ -0,0 +1,45 @@+# Dockerfile-specific ignore-file for the Rust AI Gateway build.+#+# The build context is the repo root (so the image can pip install litellm from+# source AND build the rust workspace). BuildKit honors `<Dockerfile>.dockerignore`+# next to the Dockerfile and it takes precedence over the repo-root `.dockerignore`,+# so this file shrinks the (large) repo-root context for THIS build only without+# touching the root `.dockerignore` used by the main litellm images.+#+# Strategy: ignore everything, then re-include only what the build needs:+# - litellm/ (pip install . needs the full package + proxy reader)+# - litellm-rust/ (the rust workspace; Cargo.lock + crate sources)+# - pyproject.toml / README.md / LICENSE (packaging metadata for pip install)+*++# --- re-include the build inputs ---+!litellm/+!litellm-rust/+!pyproject.toml+!README.md+!LICENSE++# --- prune heavy / irrelevant subpaths back out of the re-included trees ---+# Rust build artifacts (huge; regenerated in the builder).+**/target/+# Python caches and compiled bytecode.+**/__pycache__/+**/*.pyc+**/*.pyo+**/.pytest_cache/+**/.ruff_cache/+**/.mypy_cache/+# Node / UI build output bundled under the python package (not needed to import+# litellm.proxy.read_model_list).+**/node_modules/+litellm/proxy/_experimental/out/+# Tests, logs, and local scratch.+**/tests/+**/test/+*.log+log.txt+*.tgz+# VCS / editor / CI metadata that may live under re-included trees.+**/.git/+.git/+**/.DS_Storediff --git a/litellm-rust/crates/ai-gateway/README.md b/litellm-rust/crates/ai-gateway/README.mdnew file mode 100644index 00000000000..3662ce2584a--- /dev/null+++ b/litellm-rust/crates/ai-gateway/README.md@@ -0,0 +1,172 @@+# 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:++```yaml+# config.yaml+model_list:+ - model_name: gpt-realtime+ litellm_params:+ model: openai/gpt-realtime+ api_key: os.environ/OPENAI_API_KEY+```++```bash+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/VAR` secret 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+> or `render.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**:++```bash+# 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:++```bash+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)++```bash+# 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++```bash+# 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.diff --git a/litellm-rust/crates/ai-gateway/config.yaml b/litellm-rust/crates/ai-gateway/config.yamlnew file mode 100644index 00000000000..ac598c220dd--- /dev/null+++ b/litellm-rust/crates/ai-gateway/config.yaml@@ -0,0 +1,13 @@+# Sample realtime config for the LiteLLM Rust AI Gateway.+#+# The gateway loads this model_list at boot via the embedded python config+# reader (litellm.proxy.read_model_list), which reuses the proxy's own reader —+# so include:, os.environ/ secrets, and DB-stored models all work here too.+#+# Secrets are referenced (never inlined) via os.environ/. A real deploy can+# override this file (e.g. mount a Render secret file at LITELLM_CONFIG_PATH).+model_list:+ - model_name: gpt-realtime+ litellm_params:+ model: openai/gpt-realtime+ api_key: os.environ/OPENAI_API_KEYdiff --git a/litellm-rust/crates/ai-gateway/render.yaml b/litellm-rust/crates/ai-gateway/render.yamlnew file mode 100644index 00000000000..4170849f65d--- /dev/null+++ b/litellm-rust/crates/ai-gateway/render.yaml@@ -0,0 +1,35 @@+# Render blueprint for the LiteLLM Rust AI Gateway (realtime WebSocket proxy).+#+# Single instance for now (no autoscaling). The public endpoint is a+# WebSocket served over TLS: wss://<service>.onrender.com/v1/realtime+#+# Paths are relative to the **repo root** (Render's convention). The build+# context is the repo root so the image can install litellm from source — the+# gateway loads its model_list via litellm.proxy.read_model_list at boot.+#+# Secrets (LITELLM_MASTER_KEY, OPENAI_API_KEY) are marked sync: false — set+# them in the Render dashboard or via the API, never inline here.+services:+ - type: web+ name: litellm-rust-ai-gateway+ runtime: docker+ plan: standard+ dockerfilePath: ./litellm-rust/crates/ai-gateway/Dockerfile+ dockerContext: .+ healthCheckPath: /health/readiness+ numInstances: 1+ envVars:+ # The gateway loads its model_list from this config.yaml via the embedded+ # python config reader. The image bakes a default config at /app/config.yaml;+ # a real deploy can override it by mounting a Render secret file at this+ # same path (Dashboard → Environment → Secret Files) — never inline secrets.+ - key: LITELLM_CONFIG_PATH+ value: /app/config.yaml+ - key: HOST+ value: 0.0.0.0+ # Bearer token clients must send on /v1/realtime (fail closed if unset).+ - key: LITELLM_MASTER_KEY+ sync: false+ # Referenced by config.yaml as os.environ/OPENAI_API_KEY for the upstream dial.+ - key: OPENAI_API_KEY+ sync: false