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
refactor(litellm-rust): dissolve providers into core + ai-gateway (strict 3-crate layers) (#31218)
ishaan-berribd759182ca05
diff --git a/litellm-rust/.cargo/config.toml b/litellm-rust/.cargo/config.tomlnew file mode 100644index 00000000000..c7fb2592542--- /dev/null+++ b/litellm-rust/.cargo/config.toml@@ -0,0 +1,10 @@+# PyO3 cdylib (`litellm-python-bridge`) links against the host interpreter's+# symbols, which are not present at link time when building an extension module.+# On macOS, tell the linker to resolve undefined `_Py*` symbols dynamically at+# load time (the standard pyo3 extension-module flag) so the cdylib links without+# a libpython on the link line.+[target.x86_64-apple-darwin]+rustflags = ["-C", "link-arg=-undefined", "-C", "link-arg=dynamic_lookup"]++[target.aarch64-apple-darwin]+rustflags = ["-C", "link-arg=-undefined", "-C", "link-arg=dynamic_lookup"]diff --git a/litellm-rust/AGENTS.md b/litellm-rust/AGENTS.mdnew file mode 100644index 00000000000..86dd2c92744--- /dev/null+++ b/litellm-rust/AGENTS.md@@ -0,0 +1,17 @@+# AGENTS.md++litellm-rust has exactly THREE crates. A crate is a LAYER, not a route. Routes (ocr, realtime, chat) and providers (mistral, openai) are MODULES inside the layers.++## Crates++| Crate | Role | Pure / I/O |+|-------|------|------------|+| litellm-core | Translation layer — types, route contracts (traits), provider transforms (modules under providers/), and the router. Builds requests/responses; no network. | Pure |+| litellm-ai-gateway | Routes + host — the only crate that touches the network. HTTP/WebSocket I/O (modules under io/) plus the axum server binary (behind the `server` feature). | I/O |+| litellm-python-bridge | PyO3 cdylib exposing Rust to the litellm Python SDK — a thin adapter over litellm-ai-gateway's I/O. | Binding |++Dependency direction (acyclic): litellm-core ← litellm-ai-gateway ← litellm-python-bridge.++Adding a crate: default to a MODULE. New crate ONLY on a real trigger — separate artifact (binary/cdylib), proc-macro, shared foundation, or publishable standalone. A new provider or route is none of these.++Adding a crate fails crates/core/tests/workspace_crate_allowlist.rs until you update its allowlist and this file — intentional.diff --git a/litellm-rust/CLAUDE.md b/litellm-rust/CLAUDE.mdindex 1d2987e0a1a..0a985b833f3 100644--- a/litellm-rust/CLAUDE.md+++ b/litellm-rust/CLAUDE.md@@ -2,27 +2,32 @@This file defines the rules for Rust work in LiteLLM.+## Crates (exactly three — see AGENTS.md)++`litellm-core` describes work; `litellm-ai-gateway` executes it; `litellm-python-bridge`+exposes it to the Python SDK. A crate is a **layer**, not a route — add modules, not crates.+## Core Boundary-The `core` and `providers` crates describe work; hosts execute work.+`litellm-core` is the pure translation layer; the `litellm-ai-gateway` host executes work.Route-level Rust structure mirrors LiteLLM's Python responsibilities:- `core/src/<route>/` owns the route contract, shared types, and providertemplate traits. For OCR, this means `core/src/ocr`.-- `providers/src/<provider>/<route>/transformation.rs` owns the+- `core/src/providers/<provider>/<route>/transformation.rs` owns theprovider-specific transform. For Mistral OCR, this means- `providers/src/mistral/ocr/transformation.rs`.-- Future network execution belongs in a host/transport layer such as- `llm_http_handler`, not inside `core` or `providers`.+ `core/src/providers/mistral/ocr/transformation.rs`.+- Network execution lives in the host crate `ai-gateway` (`ai-gateway/src/io/`),+ never inside `core`.-Allowed in `core` and `providers`:+Allowed in `core`:- Pure request transforms- Pure response transforms- Pure stream chunk normalization- Shared data types and validation errors- Deterministic token/cost helper logic-Not allowed in `core` or `providers`:+Not allowed in `core`:- Network calls- Environment variable or secret reads- Filesystem access@@ -80,7 +85,9 @@ for changes under `litellm-rust/`.```bashcd litellm-rustcargo fmt --check-cargo clippy --workspace --all-targets -- -D warnings+# the ai-gateway binary + server code is behind the `server` feature+cargo clippy -p litellm-ai-gateway --all-targets --features server -- -D warnings+cargo clippy -p litellm-core -p litellm-python-bridge --all-targets -- -D warningscargo test --workspace```diff --git a/litellm-rust/Cargo.lock b/litellm-rust/Cargo.lockindex a269a224d97..3b8c83aac16 100644--- a/litellm-rust/Cargo.lock+++ b/litellm-rust/Cargo.lock@@ -564,14 +564,16 @@ name = "litellm-ai-gateway"version = "0.1.0"dependencies = ["axum",+ "futures-channel","futures-util","litellm-core",- "litellm-providers","pyo3",+ "reqwest","serde","serde_json","subtle","tokio",+ "tokio-tungstenite",][[package]]@@ -584,25 +586,12 @@ dependencies = ["thiserror 2.0.18",]-[[package]]-name = "litellm-providers"-version = "0.1.0"-dependencies = [- "futures-channel",- "futures-util",- "litellm-core",- "reqwest",- "serde_json",- "tokio",- "tokio-tungstenite",-]-[[package]]name = "litellm-python-bridge"version = "0.1.0"dependencies = [+ "litellm-ai-gateway","litellm-core",- "litellm-providers","pyo3","serde_json",]diff --git a/litellm-rust/Cargo.toml b/litellm-rust/Cargo.tomlindex 06289e5a46f..785404c38f1 100644--- a/litellm-rust/Cargo.toml+++ b/litellm-rust/Cargo.toml@@ -1,9 +1,8 @@[workspace]members = ["crates/core",- "crates/providers",- "crates/python-bridge","crates/ai-gateway",+ "crates/python-bridge",]resolver = "2"@@ -14,7 +13,7 @@ repository = "https://github.com/BerriAI/litellm"[workspace.dependencies]litellm-core = { path = "crates/core" }-litellm-providers = { path = "crates/providers" }+litellm-ai-gateway = { path = "crates/ai-gateway", default-features = false }axum = "0.7"pyo3 = "0.23.5"rand = "0.8"diff --git a/litellm-rust/README.md b/litellm-rust/README.mdindex 15ad1855420..1646c90ad76 100644--- a/litellm-rust/README.md+++ b/litellm-rust/README.md@@ -7,6 +7,16 @@ continues to own auth, configuration, network I/O, retries, routing, logging,callbacks, spend tracking, and customer plugins until each Rust path has paritycoverage and production evidence.+## Crates++| Crate | Role | Pure / I/O |+|-------|------|------------|+| litellm-core | Translation layer — types, route contracts (traits), provider transforms (modules under providers/), and the router. Builds requests/responses; no network. | Pure |+| litellm-ai-gateway | Routes + host — the only crate that touches the network. HTTP/WebSocket I/O (modules under io/) plus the axum server binary (behind the `server` feature). | I/O |+| litellm-python-bridge | PyO3 cdylib exposing Rust to the litellm Python SDK — a thin adapter over litellm-ai-gateway's I/O. | Binding |++Dependency direction (acyclic): litellm-core ← litellm-ai-gateway ← litellm-python-bridge.+## Layout```textdiff --git a/litellm-rust/crates/ai-gateway/Cargo.toml b/litellm-rust/crates/ai-gateway/Cargo.tomlindex 79bdc4bdb26..c829333a4b1 100644--- a/litellm-rust/crates/ai-gateway/Cargo.toml+++ b/litellm-rust/crates/ai-gateway/Cargo.toml@@ -5,22 +5,32 @@ edition.workspace = truelicense.workspace = truerepository.workspace = true+[lib]+name = "litellm_ai_gateway"+[[bin]]name = "litellm-ai-gateway"path = "src/main.rs"+required-features = ["server"][dependencies]litellm-core.workspace = true-litellm-providers.workspace = true-axum = { workspace = true, features = ["ws"] }-futures-util.workspace = true+reqwest.workspace = truetokio = { workspace = true, features = ["rt-multi-thread", "macros", "net", "time"] }-serde.workspace = true+tokio-tungstenite.workspace = true+futures-util.workspace = trueserde_json.workspace = true-subtle.workspace = true+axum = { workspace = true, features = ["ws"], optional = true }+serde = { workspace = true, optional = true }+subtle = { workspace = true, optional = true }pyo3 = { workspace = true, features = ["auto-initialize"], optional = true }[features]+default = []+server = ["dep:axum", "dep:subtle", "dep:serde"]# Build the gateway's config from the proxy YAML via an embedded Python# interpreter (links libpython; requires `litellm` importable at runtime).python-config = ["dep:pyo3"]++[dev-dependencies]+futures-channel = "0.3"diff --git a/litellm-rust/crates/ai-gateway/README.md b/litellm-rust/crates/ai-gateway/README.mdindex 3662ce2584a..649b9b07942 100644--- a/litellm-rust/crates/ai-gateway/README.md+++ b/litellm-rust/crates/ai-gateway/README.md@@ -4,6 +4,18 @@ A minimal Axum service that fronts OpenAI's realtime API. Clients open aWebSocket to `GET /v1/realtime`; the gateway authenticates, selects a deployment,dials OpenAI upstream, and splices the two sockets frame-by-frame.+## Crates++`litellm-rust` is exactly three crates (a crate is a **layer**, not a route):++| Crate | Role | Pure / I/O |+|-------|------|------------|+| litellm-core | Translation layer — types, route contracts (traits), provider transforms (modules under `providers/`), and the router. Builds requests/responses; no network. | Pure |+| litellm-ai-gateway | Routes + host — the only crate that touches the network. HTTP/WebSocket I/O (modules under `io/`) plus the Axum server binary (behind the `server` feature). | I/O |+| litellm-python-bridge | PyO3 cdylib exposing Rust to the litellm Python SDK — a thin adapter over litellm-ai-gateway's I/O. | Binding |++Dependency direction (acyclic): litellm-core ← litellm-ai-gateway ← litellm-python-bridge.+- **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`diff --git a/litellm-rust/crates/providers/src/lib.rs b/litellm-rust/crates/ai-gateway/src/io/mod.rssimilarity index 62%rename from litellm-rust/crates/providers/src/lib.rsrename to litellm-rust/crates/ai-gateway/src/io/mod.rsindex 40e18961f43..3b566027646 100644--- a/litellm-rust/crates/providers/src/lib.rs+++ b/litellm-rust/crates/ai-gateway/src/io/mod.rs@@ -1,5 +1,3 @@-pub mod mistral;pub mod ocr;-pub mod openai;pub mod realtime;pub mod realtime_pool;diff --git a/litellm-rust/crates/providers/src/ocr.rs b/litellm-rust/crates/ai-gateway/src/io/ocr.rssimilarity index 96%rename from litellm-rust/crates/providers/src/ocr.rsrename to litellm-rust/crates/ai-gateway/src/io/ocr.rsindex dcd56a5f0b4..5c32157bc6f 100644--- a/litellm-rust/crates/providers/src/ocr.rs+++ b/litellm-rust/crates/ai-gateway/src/io/ocr.rs@@ -12,8 +12,8 @@ use litellm_core::ocr::transformation::OcrProviderConfig;use litellm_core::CoreResult;use serde_json::{Map, Value};-use crate::mistral::ocr::transformation as mistral;-use crate::mistral::ocr::transformation::MISTRAL_OCR_CONFIG;+use litellm_core::providers::mistral::ocr::transformation as mistral;+use litellm_core::providers::mistral::ocr::transformation::MISTRAL_OCR_CONFIG;/// OCR over large documents can take a while; bound it generously rather than/// hanging forever on an unresponsive upstream. The client-level limit is thediff --git a/litellm-rust/crates/providers/src/realtime.rs b/litellm-rust/crates/ai-gateway/src/io/realtime.rssimilarity index 96%rename from litellm-rust/crates/providers/src/realtime.rsrename to litellm-rust/crates/ai-gateway/src/io/realtime.rsindex 398158f6dba..5d538d95fa4 100644--- a/litellm-rust/crates/providers/src/realtime.rs+++ b/litellm-rust/crates/ai-gateway/src/io/realtime.rs@@ -1,13 +1,13 @@//! End-to-end OpenAI realtime invocation.//!-//! The host-facing entry point, mirroring `providers::ocr::run_ocr`: open the+//! The host-facing entry point, mirroring `crate::io::ocr::run_ocr`: open the//! WebSocket to OpenAI, then splice a client realtime stream to the upstream,//! driving typed events through the pure `OPENAI_REALTIME_CONFIG` transforms.//! Network, auth header, key resolution, and wire (de)serialization live here so//! the `transformation` module stays pure and typed.//!//! The dial and splice steps are factored out ([`dial_upstream`], [`splice`]) so-//! the connection pool ([`crate::realtime_pool`]) can pre-establish an upstream,+//! the connection pool ([`crate::io::realtime_pool`]) can pre-establish an upstream,//! buffer its `session.created`, and later hand the live socket to the same//! splice loop a fresh dial uses.@@ -26,7 +26,7 @@ use tokio_tungstenite::tungstenite::http::HeaderValue;use tokio_tungstenite::tungstenite::Message;use tokio_tungstenite::{connect_async, MaybeTlsStream, WebSocketStream};-use crate::openai::realtime::transformation::OPENAI_REALTIME_CONFIG;+use litellm_core::providers::openai::realtime::transformation::OPENAI_REALTIME_CONFIG;/// Environment variable holding the OpenAI API key (last-resort fallback).const OPENAI_API_KEY_ENV: &str = "OPENAI_API_KEY";@@ -235,12 +235,12 @@ where.await}-/// Splice a pre-warmed upstream (taken from [`crate::realtime_pool`]) to the+/// Splice a pre-warmed upstream (taken from [`crate::io::realtime_pool`]) to the/// client. Relays the buffered `session.created` first, then splices exactly like/// the fresh-dial path — so a warm session is indistinguishable from a fresh one.pub async fn realtime_warm<In, Out>(model: &str,- handoff: crate::realtime_pool::WarmHandoff,+ handoff: crate::io::realtime_pool::WarmHandoff,idle_timeout: Option<Duration>,client_in: In,client_out: Out,@@ -281,7 +281,7 @@ mod tests {/// Live end-to-end check against OpenAI. Ignored by default (CI never runs/// it); run explicitly with `OPENAI_API_KEY` set:- /// `cargo test -p litellm-providers realtime_invokes_openai -- --ignored --nocapture`+ /// `cargo test -p litellm-ai-gateway --features server realtime_invokes_openai -- --ignored --nocapture`#[tokio::test]#[ignore = "hits the live OpenAI realtime API; needs OPENAI_API_KEY"]async fn realtime_invokes_openai_and_responds() {diff --git a/litellm-rust/crates/providers/src/realtime_pool.rs b/litellm-rust/crates/ai-gateway/src/io/realtime_pool.rssimilarity index 99%rename from litellm-rust/crates/providers/src/realtime_pool.rsrename to litellm-rust/crates/ai-gateway/src/io/realtime_pool.rsindex 1b1fc8112c5..bf8041f31d7 100644--- a/litellm-rust/crates/providers/src/realtime_pool.rs+++ b/litellm-rust/crates/ai-gateway/src/io/realtime_pool.rs@@ -6,7 +6,7 @@//! sockets **already connected and already past `session.created`** so a connect//! can be served from a warm socket and the handshake is off the critical path.//!-//! Layering: this stays in `providers` (axum-free) next to the dial/splice it+//! Layering: this lives in the gateway's `io` module next to the dial/splice it//! reuses. The gateway holds an `Arc<RealtimePool>` in its state and asks for a//! warm socket per connect; on a miss it fresh-dials exactly as before. The pool//! is a latency optimization, never a correctness dependency — see the gateway's@@ -31,7 +31,7 @@ use futures_util::StreamExt;use litellm_core::realtime::types::RealtimeEvent;use litellm_core::CoreResult;-use crate::realtime::{+use crate::io::realtime::{dial_upstream, read_event, resolve_api_key, UpstreamRx, UpstreamTx, UpstreamWs,};diff --git a/litellm-rust/crates/ai-gateway/src/lib.rs b/litellm-rust/crates/ai-gateway/src/lib.rsnew file mode 100644index 00000000000..a2c228aeb30--- /dev/null+++ b/litellm-rust/crates/ai-gateway/src/lib.rs@@ -0,0 +1,28 @@+//! LiteLLM AI Gateway library.+//!+//! Two layers, split by feature so the Python `cdylib` can depend on the I/O+//! without pulling in the HTTP server:+//!+//! - [`io`]: all network I/O (OCR HTTP call, realtime WebSocket splice, the+//! pre-warmed realtime pool). Always available — no feature required. The+//! Python bridge links this for `run_ocr`.+//! - The server modules ([`auth`], [`routes`], [`state`]) and anything pulling+//! `axum` are gated behind the `server` feature, which the `litellm-ai-gateway`+//! binary turns on. The `python-config` feature additionally pulls in [`python`]+//! for the load-time config reader.++pub mod io;++/// GIL-activity tracking. Pure (atomics only); shared by the `server` routes and+/// the `python-config` reader, so it is available without either feature.+pub mod gil;++#[cfg(feature = "server")]+pub mod auth;+#[cfg(feature = "server")]+pub mod routes;+#[cfg(feature = "server")]+pub mod state;++#[cfg(feature = "python-config")]+pub mod python;diff --git a/litellm-rust/crates/ai-gateway/src/main.rs b/litellm-rust/crates/ai-gateway/src/main.rsindex 71e4a6836ad..a0105b3f000 100644--- a/litellm-rust/crates/ai-gateway/src/main.rs+++ b/litellm-rust/crates/ai-gateway/src/main.rs@@ -1,22 +1,23 @@//! LiteLLM AI Gateway — a minimal Axum server fronting the Rust router.//!//! Flow: client → `POST /v1/realtime` → `router.realtime()` selects a deployment-//! (simple-shuffle) → `providers::realtime::realtime()` invokes OpenAI. The+//! (simple-shuffle) → `io::realtime::realtime()` invokes OpenAI. The//! server owns transport + config; routing lives in the `router` crate.--mod auth;-mod gil;-#[cfg(feature = "python-config")]-mod python;-mod routes;-mod state;+//!+//! The binary requires the `server` feature (declared in `Cargo.toml` via+//! `required-features`), so cargo skips it unless that feature is on. Everything+//! the binary needs lives in the library (`litellm_ai_gateway`); `main` just+//! wires startup.use std::sync::Arc;+use litellm_ai_gateway::io::realtime_pool::{upstream_key, PoolConfig, RealtimePool};+use litellm_ai_gateway::routes;+use litellm_ai_gateway::state::AppState;use litellm_core::router::{Deployment, LiteLLMParams, Router};-use litellm_providers::realtime_pool::{upstream_key, PoolConfig, RealtimePool};-use crate::state::AppState;+#[cfg(feature = "python-config")]+use litellm_ai_gateway::python;/// Bind to localhost by default so the gateway is not a public, unauthenticated/// provider proxy out of the box. Override with `HOST` (e.g. `0.0.0.0`).diff --git a/litellm-rust/crates/ai-gateway/src/routes/realtime/mod.rs b/litellm-rust/crates/ai-gateway/src/routes/realtime/mod.rsindex 695e0c6bb39..658fa8d2dbe 100644--- a/litellm-rust/crates/ai-gateway/src/routes/realtime/mod.rs+++ b/litellm-rust/crates/ai-gateway/src/routes/realtime/mod.rs@@ -8,6 +8,7 @@ mod service;use std::sync::Arc;+use crate::io::realtime_pool::RealtimePool;use axum::extract::ws::{Message, WebSocket, WebSocketUpgrade};use axum::extract::{Query, State};use axum::http::StatusCode;@@ -17,7 +18,6 @@ use axum::Router;use futures_util::{SinkExt, StreamExt};use litellm_core::realtime::types::RealtimeEvent;use litellm_core::router::Router as ModelRouter;-use litellm_providers::realtime_pool::RealtimePool;use serde::Deserialize;use crate::auth::RequireMasterKey;diff --git a/litellm-rust/crates/ai-gateway/src/routes/realtime/service.rs b/litellm-rust/crates/ai-gateway/src/routes/realtime/service.rsindex 0cbd00d664f..c78ca8df446 100644--- a/litellm-rust/crates/ai-gateway/src/routes/realtime/service.rs+++ b/litellm-rust/crates/ai-gateway/src/routes/realtime/service.rs@@ -1,6 +1,6 @@//! Business logic: select a deployment with the (pure) core router, then call the//! provider splice. The seam between `core::router` (selection only) and-//! `providers` (the actual WebSocket I/O).+//! `io` (the actual WebSocket I/O).//!//! On connect we try a pre-warmed upstream from the pool (handshake already paid,//! `session.created` buffered) and relay it instantly. On a pool miss or dead warm@@ -9,12 +9,12 @@use std::time::Duration;+use crate::io::realtime_pool::{upstream_key, RealtimePool};use futures_util::{Sink, Stream};use litellm_core::error::CoreError;use litellm_core::realtime::types::RealtimeEvent;use litellm_core::router::Router;use litellm_core::CoreResult;-use litellm_providers::realtime_pool::{upstream_key, RealtimePool};/// Select a deployment for `model` and splice the client stream to the provider.///@@ -52,7 +52,7 @@ whereparams.api_base.as_deref(),) {if let Some(handoff) = pool.take(&key) {- return litellm_providers::realtime::realtime_warm(+ return crate::io::realtime::realtime_warm(provider_model,handoff,idle_timeout,@@ -64,7 +64,7 @@ where}// Cold path: fresh dial (the original behavior).- litellm_providers::realtime::realtime(+ crate::io::realtime::realtime(provider_model,params.api_key.as_deref(),params.api_base.as_deref(),diff --git a/litellm-rust/crates/ai-gateway/src/state.rs b/litellm-rust/crates/ai-gateway/src/state.rsindex ef96037d477..c7ba92d9cbc 100644--- a/litellm-rust/crates/ai-gateway/src/state.rs+++ b/litellm-rust/crates/ai-gateway/src/state.rs@@ -1,7 +1,7 @@use std::sync::Arc;+use crate::io::realtime_pool::RealtimePool;use litellm_core::router::Router;-use litellm_providers::realtime_pool::RealtimePool;/// Shared application state handed to every route handler.#[derive(Clone)]diff --git a/litellm-rust/crates/core/AGENTS.md b/litellm-rust/crates/core/AGENTS.mdnew file mode 100644index 00000000000..8740dccaf01--- /dev/null+++ b/litellm-rust/crates/core/AGENTS.md@@ -0,0 +1,3 @@+litellm-core is the PURE translation layer — types, route contracts (traits), provider transforms (modules under `providers/`), and the router. No network, no I/O, no env reads.++Routes (ocr, realtime) and providers (mistral, openai) are modules, not crates.diff --git a/litellm-rust/crates/core/src/lib.rs b/litellm-rust/crates/core/src/lib.rsindex 9d686626edc..2ac479cc725 100644--- a/litellm-rust/crates/core/src/lib.rs+++ b/litellm-rust/crates/core/src/lib.rs@@ -1,5 +1,6 @@pub mod error;pub mod ocr;+pub mod providers;pub mod realtime;pub mod router;diff --git a/litellm-rust/crates/providers/src/mistral/mod.rs b/litellm-rust/crates/core/src/providers/mistral/mod.rssimilarity index 100%rename from litellm-rust/crates/providers/src/mistral/mod.rsrename to litellm-rust/crates/core/src/providers/mistral/mod.rsdiff --git a/litellm-rust/crates/providers/src/mistral/ocr/mod.rs b/litellm-rust/crates/core/src/providers/mistral/ocr/mod.rssimilarity index 100%rename from litellm-rust/crates/providers/src/mistral/ocr/mod.rsrename to litellm-rust/crates/core/src/providers/mistral/ocr/mod.rsdiff --git a/litellm-rust/crates/providers/src/mistral/ocr/transformation.rs b/litellm-rust/crates/core/src/providers/mistral/ocr/transformation.rssimilarity index 98%rename from litellm-rust/crates/providers/src/mistral/ocr/transformation.rsrename to litellm-rust/crates/core/src/providers/mistral/ocr/transformation.rsindex fd691177783..d5155991448 100644--- a/litellm-rust/crates/providers/src/mistral/ocr/transformation.rs+++ b/litellm-rust/crates/core/src/providers/mistral/ocr/transformation.rs@@ -1,6 +1,6 @@-use litellm_core::error::{json_type_name, CoreError, CoreResult};-use litellm_core::ocr::transformation::OcrProviderConfig;-use litellm_core::ocr::types::{OcrRequestData, OcrResponseData};+use crate::error::{json_type_name, CoreError, CoreResult};+use crate::ocr::transformation::OcrProviderConfig;+use crate::ocr::types::{OcrRequestData, OcrResponseData};use serde_json::{Map, Value};const SUPPORTED_OCR_PARAMS: &[&str] = &[diff --git a/litellm-rust/crates/core/src/providers/mod.rs b/litellm-rust/crates/core/src/providers/mod.rsnew file mode 100644index 00000000000..42207f0de0a--- /dev/null+++ b/litellm-rust/crates/core/src/providers/mod.rs@@ -0,0 +1,2 @@+pub mod mistral;+pub mod openai;diff --git a/litellm-rust/crates/providers/src/openai/mod.rs b/litellm-rust/crates/core/src/providers/openai/mod.rssimilarity index 100%rename from litellm-rust/crates/providers/src/openai/mod.rsrename to litellm-rust/crates/core/src/providers/openai/mod.rsdiff --git a/litellm-rust/crates/providers/src/openai/realtime/mod.rs b/litellm-rust/crates/core/src/providers/openai/realtime/mod.rssimilarity index 100%rename from litellm-rust/crates/providers/src/openai/realtime/mod.rsrename to litellm-rust/crates/core/src/providers/openai/realtime/mod.rsdiff --git a/litellm-rust/crates/providers/src/openai/realtime/transformation.rs b/litellm-rust/crates/core/src/providers/openai/realtime/transformation.rssimilarity index 97%rename from litellm-rust/crates/providers/src/openai/realtime/transformation.rsrename to litellm-rust/crates/core/src/providers/openai/realtime/transformation.rsindex 2e127c699e0..626e4014ff9 100644--- a/litellm-rust/crates/providers/src/openai/realtime/transformation.rs+++ b/litellm-rust/crates/core/src/providers/openai/realtime/transformation.rs@@ -1,6 +1,6 @@-use litellm_core::realtime::transformation::RealtimeProviderConfig;-use litellm_core::realtime::types::{RealtimeEvent, RealtimeTransformResult};-use litellm_core::CoreResult;+use crate::realtime::transformation::RealtimeProviderConfig;+use crate::realtime::types::{RealtimeEvent, RealtimeTransformResult};+use crate::CoreResult;/// Default OpenAI API base, used when the caller does not override `api_base`.pub const OPENAI_REALTIME_DEFAULT_API_BASE: &str = "https://api.openai.com";diff --git a/litellm-rust/crates/core/tests/workspace_crate_allowlist.rs b/litellm-rust/crates/core/tests/workspace_crate_allowlist.rsnew file mode 100644index 00000000000..a56d19b8242--- /dev/null+++ b/litellm-rust/crates/core/tests/workspace_crate_allowlist.rs@@ -0,0 +1,93 @@+//! Enforcement: the litellm-rust workspace has exactly three crates.+//!+//! `core` (pure translation), `ai-gateway` (routes + all network I/O), and+//! `python-bridge` (the PyO3 cdylib). Adding or removing a crate must be a+//! deliberate act: this test fails until the allowlist here is updated, forcing+//! whoever changes the crate set to justify the new crate per the rule that a+//! crate is a layer needing independent compilation / its own deps / a separate+//! artifact — and to keep `litellm-rust/AGENTS.md` in sync.+//!+//! Std-only (no toml crate): we scan the workspace manifest's `members = [...]`+//! block and the `crates/` directory directly.++use std::collections::BTreeSet;+use std::fs;+use std::path::{Path, PathBuf};++/// The one true crate set. Update BOTH this and `litellm-rust/AGENTS.md` when the+/// workspace legitimately gains or loses a crate.+const EXPECTED_MEMBERS: &[&str] = &["crates/core", "crates/ai-gateway", "crates/python-bridge"];++/// The crate subdirectory names that must exist under `crates/`.+const EXPECTED_CRATE_DIRS: &[&str] = &["core", "ai-gateway", "python-bridge"];++const MISMATCH: &str = "litellm-rust crate set changed — update this allowlist AND litellm-rust/AGENTS.md, and justify the crate per the rule (crate = layer needing independent compilation / its own deps / a separate artifact).";++/// Absolute path to the workspace root (`litellm-rust/`).+fn workspace_root() -> PathBuf {+ // CARGO_MANIFEST_DIR is `.../litellm-rust/crates/core`; the workspace root is+ // two levels up.+ Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/../.."))+ .canonicalize()+ .expect("workspace root should resolve")+}++/// Parse the `members = [ ... ]` array out of the workspace `[workspace]` table.+///+/// Minimal hand-rolled scan: find `members`, then collect every double-quoted+/// string up to the closing `]`. Good enough for our fixed manifest shape and+/// keeps this test dependency-free.+fn parse_members(manifest: &str) -> BTreeSet<String> {+ let after_members = manifest+ .split_once("members")+ .map(|(_, rest)| rest)+ .expect("workspace manifest should declare members");+ let open = after_members.find('[').expect("members should be an array");+ let close = after_members[open..]+ .find(']')+ .map(|offset| open + offset)+ .expect("members array should be closed");+ let body = &after_members[open + 1..close];++ let mut members = BTreeSet::new();+ let mut rest = body;+ while let Some(start) = rest.find('"') {+ let after_quote = &rest[start + 1..];+ let end = after_quote+ .find('"')+ .expect("opening quote should be matched");+ members.insert(after_quote[..end].to_string());+ rest = &after_quote[end + 1..];+ }+ members+}++/// The immediate subdirectory names under `crates/`.+fn crate_dirs(root: &Path) -> BTreeSet<String> {+ fs::read_dir(root.join("crates"))+ .expect("crates/ directory should exist")+ .filter_map(Result::ok)+ .filter(|entry| entry.file_type().map(|ty| ty.is_dir()).unwrap_or(false))+ .map(|entry| entry.file_name().to_string_lossy().into_owned())+ .collect()+}++#[test]+fn workspace_members_match_allowlist() {+ let root = workspace_root();+ let manifest = fs::read_to_string(root.join("Cargo.toml"))+ .expect("workspace Cargo.toml should be readable");++ let actual = parse_members(&manifest);+ let expected: BTreeSet<String> = EXPECTED_MEMBERS.iter().map(|s| s.to_string()).collect();+ assert_eq!(actual, expected, "{MISMATCH}");+}++#[test]+fn crates_directory_matches_allowlist() {+ let root = workspace_root();++ let actual = crate_dirs(&root);+ let expected: BTreeSet<String> = EXPECTED_CRATE_DIRS.iter().map(|s| s.to_string()).collect();+ assert_eq!(actual, expected, "{MISMATCH}");+}diff --git a/litellm-rust/crates/providers/CLAUDE.md b/litellm-rust/crates/providers/CLAUDE.mddeleted file mode 100644index 0f7fdcda2aa..00000000000--- a/litellm-rust/crates/providers/CLAUDE.md+++ /dev/null@@ -1,53 +0,0 @@-# CLAUDE.md--Rules for `litellm-rust/crates/providers`.--## Responsibility--`providers` owns provider-specific pure transforms. It mirrors the existing-Python provider modules closely enough that parity review is mechanical.--Provider files should map to the Python provider tree:--```text-providers/src/<provider>/<route>/transformation.rs-```--For example, Mistral OCR lives at-`providers/src/mistral/ocr/transformation.rs`, matching-`litellm/llms/mistral/ocr/transformation.py`.--Allowed:-- Provider request transforms.-- Provider response normalization.-- Supported-parameter filtering.-- Provider-specific validation that does not require I/O or secrets.--Not allowed:-- HTTP clients or provider SDK calls.-- Environment variable reads.-- API key resolution or auth header construction.-- Logging, callbacks, spend tracking, retries, routing, cooldowns, or fallbacks.-- Panics on bad user/provider input.--## Required Tests--Every provider transform must include focused unit tests for:-- Supported params matching the Python provider config.-- Unknown params being dropped or transformed the same way as Python.-- Request body shape matching Python output.-- Response normalization with complete, missing, null, and extra fields.-- Bad input returning typed errors.--For OCR specifically, assume documents can contain personal data. Tests should-prove transforms do not copy document contents into error messages.--## Implementation Rules--- Prefer static supported-parameter lists over allocating strings on every call.-- Keep transforms deterministic and allocation-conscious, but choose clarity over- premature micro-optimization for tiny parameter lists.-- Use typed errors from `core`; avoid stringly-typed error plumbing.-- Add comments only when they explain Python-parity decisions or provider quirks.-- Put route-level provider dispatch in a route file such as `providers/src/ocr.rs`.- Do not move provider-specific transform logic into the Python bridge.diff --git a/litellm-rust/crates/providers/Cargo.toml b/litellm-rust/crates/providers/Cargo.tomldeleted file mode 100644index c5b41424d66..00000000000--- a/litellm-rust/crates/providers/Cargo.toml+++ /dev/null@@ -1,18 +0,0 @@-[package]-name = "litellm-providers"-version = "0.1.0"-edition.workspace = true-license.workspace = true-repository.workspace = true--[dependencies]-litellm-core.workspace = true-reqwest.workspace = true-serde_json.workspace = true-tokio.workspace = true-tokio-tungstenite.workspace = true-futures-util.workspace = true--[dev-dependencies]-serde_json.workspace = true-futures-channel = "0.3"diff --git a/litellm-rust/crates/python-bridge/AGENTS.md b/litellm-rust/crates/python-bridge/AGENTS.mdnew file mode 100644index 00000000000..d6d3d90e6ab--- /dev/null+++ b/litellm-rust/crates/python-bridge/AGENTS.md@@ -0,0 +1,3 @@+litellm-python-bridge is the PyO3 cdylib that exposes Rust to the litellm Python SDK — a thin adapter (Python objects → Rust calls → Python results) over litellm-ai-gateway.++Keep it thin: no business logic, no transforms, no I/O orchestration — just marshal in/out and call into litellm-ai-gateway.diff --git a/litellm-rust/crates/python-bridge/Cargo.toml b/litellm-rust/crates/python-bridge/Cargo.tomlindex 80b6478daac..f5b29f49cfd 100644--- a/litellm-rust/crates/python-bridge/Cargo.toml+++ b/litellm-rust/crates/python-bridge/Cargo.toml@@ -11,6 +11,6 @@ crate-type = ["cdylib"][dependencies]litellm-core.workspace = true-litellm-providers.workspace = true+litellm-ai-gateway = { workspace = true, default-features = false }pyo3 = { workspace = true, features = ["extension-module"] }serde_json.workspace = truediff --git a/litellm-rust/crates/python-bridge/src/lib.rs b/litellm-rust/crates/python-bridge/src/lib.rsindex 15e93f7b00c..50ec7fceeac 100644--- a/litellm-rust/crates/python-bridge/src/lib.rs+++ b/litellm-rust/crates/python-bridge/src/lib.rs@@ -1,7 +1,7 @@use std::time::Duration;+use litellm_ai_gateway::io::ocr::run_ocr;use litellm_core::error::CoreError;-use litellm_providers::ocr::run_ocr;use pyo3::exceptions::{PyRuntimeError, PyValueError};use pyo3::prelude::*;use pyo3::types::{PyAny, PyDict};