Skip to content

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]

refactor(rust): rename legacy callback adapter crate

Yujong Leedf84fef96e80
diff --git a/litellm-rust/Cargo.lock b/litellm-rust/Cargo.lock
index ebab2a118fc..2720cf01f2e 100644
--- a/litellm-rust/Cargo.lock
+++ b/litellm-rust/Cargo.lock
@@ -2030,7 +2030,7 @@ dependencies = [
]
[[package]]
-name = "litellm-callbacks-legacy"
+name = "litellm-callbacks-legacy-python"
version = "0.1.0"
dependencies = [
"litellm-auth",
@@ -2192,7 +2192,7 @@ dependencies = [
"futures-util",
"litellm-auth",
"litellm-auth-gcp",
- "litellm-callbacks-legacy",
+ "litellm-callbacks-legacy-python",
"litellm-core",
"litellm-core-utils",
"litellm-host-python",
diff --git a/litellm-rust/Cargo.toml b/litellm-rust/Cargo.toml
index fa2bdb4224c..a6185632871 100644
--- a/litellm-rust/Cargo.toml
+++ b/litellm-rust/Cargo.toml
@@ -11,7 +11,7 @@ repository = "https://github.com/BerriAI/litellm"
[workspace.dependencies]
litellm-core = { path = "crates/core" }
litellm-host = { path = "crates/host" }
-litellm-callbacks-legacy = { path = "crates/callbacks-legacy" }
+litellm-callbacks-legacy-python = { path = "crates/callbacks-legacy-python" }
litellm-framing = { path = "crates/framer" }
litellm-auth = { path = "crates/auth" }
litellm-auth-aws = { path = "crates/auth-aws" }
diff --git a/litellm-rust/crates/callbacks-legacy/AGENTS.md b/litellm-rust/crates/callbacks-legacy-python/AGENTS.md
similarity index 100%
rename from litellm-rust/crates/callbacks-legacy/AGENTS.md
rename to litellm-rust/crates/callbacks-legacy-python/AGENTS.md
diff --git a/litellm-rust/crates/callbacks-legacy/Cargo.toml b/litellm-rust/crates/callbacks-legacy-python/Cargo.toml
similarity index 90%
rename from litellm-rust/crates/callbacks-legacy/Cargo.toml
rename to litellm-rust/crates/callbacks-legacy-python/Cargo.toml
index 023c13d912b..fe19578e04d 100644
--- a/litellm-rust/crates/callbacks-legacy/Cargo.toml
+++ b/litellm-rust/crates/callbacks-legacy-python/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-name = "litellm-callbacks-legacy"
+name = "litellm-callbacks-legacy-python"
version = "0.1.0"
edition.workspace = true
license.workspace = true
diff --git a/litellm-rust/crates/callbacks-legacy/python_contract.json b/litellm-rust/crates/callbacks-legacy-python/python_contract.json
similarity index 100%
rename from litellm-rust/crates/callbacks-legacy/python_contract.json
rename to litellm-rust/crates/callbacks-legacy-python/python_contract.json
diff --git a/litellm-rust/crates/callbacks-legacy/src/adapter.rs b/litellm-rust/crates/callbacks-legacy-python/src/adapter.rs
similarity index 99%
rename from litellm-rust/crates/callbacks-legacy/src/adapter.rs
rename to litellm-rust/crates/callbacks-legacy-python/src/adapter.rs
index 883a35f0df5..28d5c08736f 100644
--- a/litellm-rust/crates/callbacks-legacy/src/adapter.rs
+++ b/litellm-rust/crates/callbacks-legacy-python/src/adapter.rs
@@ -20,7 +20,7 @@ use crate::{
DeploymentHooks, LegacyCallbacks, PublicCall, PythonLogger,
deferred::{PendingLogging, PendingSuccess},
finalize, is_internal_call,
- legacy_python::Streaming,
+ python::Streaming,
prepare, setup,
};
diff --git a/litellm-rust/crates/callbacks-legacy/src/call.rs b/litellm-rust/crates/callbacks-legacy-python/src/call.rs
similarity index 100%
rename from litellm-rust/crates/callbacks-legacy/src/call.rs
rename to litellm-rust/crates/callbacks-legacy-python/src/call.rs
diff --git a/litellm-rust/crates/callbacks-legacy/src/callbacks.rs b/litellm-rust/crates/callbacks-legacy-python/src/callbacks.rs
similarity index 99%
rename from litellm-rust/crates/callbacks-legacy/src/callbacks.rs
rename to litellm-rust/crates/callbacks-legacy-python/src/callbacks.rs
index 5f04224e6d7..d36523d6b94 100644
--- a/litellm-rust/crates/callbacks-legacy/src/callbacks.rs
+++ b/litellm-rust/crates/callbacks-legacy-python/src/callbacks.rs
@@ -6,7 +6,7 @@ use litellm_host::event::{RequestContext, WireRequest};
use litellm_host_python::to_py;
use pyo3::{exceptions::PyBaseException, prelude::*, types::PyDict};
-use crate::legacy_python::{Logging, Wrapper};
+use crate::python::{Logging, Wrapper};
use crate::logger::PythonLogger;
pub trait LegacyCallbacks {
diff --git a/litellm-rust/crates/callbacks-legacy/src/deferred.rs b/litellm-rust/crates/callbacks-legacy-python/src/deferred.rs
similarity index 100%
rename from litellm-rust/crates/callbacks-legacy/src/deferred.rs
rename to litellm-rust/crates/callbacks-legacy-python/src/deferred.rs
diff --git a/litellm-rust/crates/callbacks-legacy/src/lib.rs b/litellm-rust/crates/callbacks-legacy-python/src/lib.rs
similarity index 98%
rename from litellm-rust/crates/callbacks-legacy/src/lib.rs
rename to litellm-rust/crates/callbacks-legacy-python/src/lib.rs
index eaa1a8b714e..514713d988b 100644
--- a/litellm-rust/crates/callbacks-legacy/src/lib.rs
+++ b/litellm-rust/crates/callbacks-legacy-python/src/lib.rs
@@ -13,7 +13,7 @@ mod adapter;
mod call;
mod callbacks;
mod deferred;
-mod legacy_python;
+mod python;
mod logger;
mod preparation;
#[cfg(test)]
diff --git a/litellm-rust/crates/callbacks-legacy/src/logger.rs b/litellm-rust/crates/callbacks-legacy-python/src/logger.rs
similarity index 94%
rename from litellm-rust/crates/callbacks-legacy/src/logger.rs
rename to litellm-rust/crates/callbacks-legacy-python/src/logger.rs
index 061941f05b9..38f3bf29828 100644
--- a/litellm-rust/crates/callbacks-legacy/src/logger.rs
+++ b/litellm-rust/crates/callbacks-legacy-python/src/logger.rs
@@ -5,7 +5,7 @@ use pyo3::{
types::{PyDict, PyTuple},
};
-use crate::legacy_python::{self, Wrapper};
+use crate::python::{self, Wrapper};
/// The `Logging` instance one call fans out through.
pub struct PythonLogger {
@@ -90,7 +90,7 @@ impl DeploymentHooks {
kwargs: &Py<PyDict>,
call_type: &str,
) -> PyResult<Py<PyAny>> {
- legacy_python::DeploymentHooks::BeforeDeploymentCall
+ python::DeploymentHooks::BeforeDeploymentCall
.call(py, (kwargs, call_type))
.map(Bound::unbind)
}
@@ -101,7 +101,7 @@ impl DeploymentHooks {
response: &Option<Py<PyAny>>,
call_type: &str,
) -> PyResult<Py<PyAny>> {
- legacy_python::DeploymentHooks::AfterDeploymentSuccess
+ python::DeploymentHooks::AfterDeploymentSuccess
.call(py, (kwargs, response, call_type))
.map(Bound::unbind)
}
@@ -112,7 +112,7 @@ impl DeploymentHooks {
error: &Py<PyBaseException>,
call_type: &str,
) -> PyResult<Py<PyAny>> {
- legacy_python::DeploymentHooks::AfterDeploymentFailure
+ python::DeploymentHooks::AfterDeploymentFailure
.call(py, (kwargs, error, call_type))
.map(Bound::unbind)
}
diff --git a/litellm-rust/crates/callbacks-legacy/src/preparation.rs b/litellm-rust/crates/callbacks-legacy-python/src/preparation.rs
similarity index 99%
rename from litellm-rust/crates/callbacks-legacy/src/preparation.rs
rename to litellm-rust/crates/callbacks-legacy-python/src/preparation.rs
index fa1ff9acd4d..aab654c9893 100644
--- a/litellm-rust/crates/callbacks-legacy/src/preparation.rs
+++ b/litellm-rust/crates/callbacks-legacy-python/src/preparation.rs
@@ -3,7 +3,7 @@ use pyo3::{
types::{PyDict, PyList},
};
-use crate::legacy_python::Wrapper;
+use crate::python::Wrapper;
struct CredentialEntry<'py>(Bound<'py, PyAny>);
diff --git a/litellm-rust/crates/callbacks-legacy/src/legacy_python.rs b/litellm-rust/crates/callbacks-legacy-python/src/python.rs
similarity index 97%
rename from litellm-rust/crates/callbacks-legacy/src/legacy_python.rs
rename to litellm-rust/crates/callbacks-legacy-python/src/python.rs
index 7f5c77c1735..cb609d52878 100644
--- a/litellm-rust/crates/callbacks-legacy/src/legacy_python.rs
+++ b/litellm-rust/crates/callbacks-legacy-python/src/python.rs
@@ -1,7 +1,7 @@
use pyo3::prelude::*;
use strum::{IntoStaticStr, VariantArray};
-const MODULE: &str = "litellm.rust_bridge.legacy_callbacks";
+const MODULE: &str = "litellm.rust_bridge.callbacks_legacy_python";
/// Every litellm Python internal the native call still borrows, grouped by the subsystem it
/// belongs to. Rust drives the call; these exist only so behaviour that Python owns today
@@ -9,7 +9,7 @@ const MODULE: &str = "litellm.rust_bridge.legacy_callbacks";
/// A group is deleted once Rust owns that subsystem, so this enum only shrinks. Calling a
/// user's own callback is not borrowing and does not belong here.
///
-/// `litellm/rust_bridge/legacy_callbacks.py` is the only Python module behind it, and
+/// `litellm/rust_bridge/callbacks_legacy_python.py` is the only Python module behind it, and
/// `python_contract.json` pins each function's parameters on both sides.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum LegacyPython {
diff --git a/litellm-rust/crates/callbacks-legacy/tests/deferred.rs b/litellm-rust/crates/callbacks-legacy-python/tests/deferred.rs
similarity index 100%
rename from litellm-rust/crates/callbacks-legacy/tests/deferred.rs
rename to litellm-rust/crates/callbacks-legacy-python/tests/deferred.rs
diff --git a/litellm-rust/crates/callbacks-legacy/tests/deployment_hooks.rs b/litellm-rust/crates/callbacks-legacy-python/tests/deployment_hooks.rs
similarity index 100%
rename from litellm-rust/crates/callbacks-legacy/tests/deployment_hooks.rs
rename to litellm-rust/crates/callbacks-legacy-python/tests/deployment_hooks.rs
diff --git a/litellm-rust/crates/callbacks-legacy/tests/payload.rs b/litellm-rust/crates/callbacks-legacy-python/tests/payload.rs
similarity index 100%
rename from litellm-rust/crates/callbacks-legacy/tests/payload.rs
rename to litellm-rust/crates/callbacks-legacy-python/tests/payload.rs
diff --git a/litellm-rust/crates/callbacks-legacy/tests/support.rs b/litellm-rust/crates/callbacks-legacy-python/tests/support.rs
similarity index 95%
rename from litellm-rust/crates/callbacks-legacy/tests/support.rs
rename to litellm-rust/crates/callbacks-legacy-python/tests/support.rs
index d3cc32e301f..d0c02fa6da5 100644
--- a/litellm-rust/crates/callbacks-legacy/tests/support.rs
+++ b/litellm-rust/crates/callbacks-legacy-python/tests/support.rs
@@ -5,12 +5,12 @@ use pyo3::types::{PyDict, PyTuple};
use crate::{LegacyLogging, LegacySurface, PublicCall};
-/// The parameters of every `legacy_callbacks` function, as the real module declares them.
-/// `tests/test_litellm/rust_bridge/test_legacy_callbacks.py` pins this file to the Python
+/// The parameters of every `callbacks_legacy_python` function, as the real module declares them.
+/// `tests/test_litellm/rust_bridge/test_callbacks_legacy_python.py` pins this file to the Python
/// signatures, and [`namespace`] binds every fake call against it.
pub(crate) const PYTHON_CONTRACT: &str = include_str!("../python_contract.json");
-/// Stand-ins for `legacy_callbacks`, the only Python module the crate calls. Tests
+/// Stand-ins for `callbacks_legacy_python`, the only Python module the crate calls. Tests
/// share one interpreter and run concurrently, so each fake is installed idempotently and
/// forwards to the per-test `StubLogger` it is handed (directly, or as `kwargs['logger']`).
/// Every fake is bound against the contract first, so a call the real module would reject
@@ -23,10 +23,10 @@ import sys
import traceback
import types
-for name in ('litellm', 'litellm.rust_bridge', 'litellm.rust_bridge.legacy_callbacks'):
+for name in ('litellm', 'litellm.rust_bridge', 'litellm.rust_bridge.callbacks_legacy_python'):
sys.modules.setdefault(name, types.ModuleType(name))
-legacy = sys.modules['litellm.rust_bridge.legacy_callbacks']
+legacy = sys.modules['litellm.rust_bridge.callbacks_legacy_python']
CONTRACT = json.loads(python_contract)
diff --git a/litellm-rust/crates/callbacks-legacy/tests/terminal.rs b/litellm-rust/crates/callbacks-legacy-python/tests/terminal.rs
similarity index 100%
rename from litellm-rust/crates/callbacks-legacy/tests/terminal.rs
rename to litellm-rust/crates/callbacks-legacy-python/tests/terminal.rs
diff --git a/litellm-rust/crates/python-bridge/AGENTS.md b/litellm-rust/crates/python-bridge/AGENTS.md
index a19a709e60c..79e78d150e0 100644
--- a/litellm-rust/crates/python-bridge/AGENTS.md
+++ b/litellm-rust/crates/python-bridge/AGENTS.md
@@ -1,9 +1,9 @@
- Target invariants, not completion claims; these supersede the crate guidance below where they conflict
- Keep this crate the product-specific PyO3 consumer of `litellm-host-python`
- Own registration, input projection, the route host and the caller callables it answers operations with (file readers, token providers), public response/error construction and the per-call composition of machine, route host and callback contract
- - Legacy callback sharing (the caller's args, kwargs and request object, body/header roots, re-aliasing unchanged body keys) lives in `litellm-callbacks-legacy` behind `PublicCall` and `run_legacy_call`; the bridge hands the public call over and keeps no copy
+ - Legacy callback sharing (the caller's args, kwargs and request object, body/header roots, re-aliasing unchanged body keys) lives in `litellm-callbacks-legacy-python` behind `PublicCall` and `run_legacy_call`; the bridge hands the public call over and keeps no copy
- Value-oriented execution, sync waiting, nested-runtime checks, signal polling and panic containment live in `litellm-host-python`; native async work uses `pyo3-async-runtimes`, Serde output uses `Pythonized<T>`
- - Core owns typed native state, the route machine, provider preparation/I/O and normalization; the host driver owns terminal events; the legacy adapter in `litellm-callbacks-legacy` owns `Logging` dispatch policy
+ - Core owns typed native state, the route machine, provider preparation/I/O and normalization; the host driver owns terminal events; the legacy adapter in `litellm-callbacks-legacy-python` owns `Logging` dispatch policy
- Python, Rust SDK and gateway use one lifecycle-bearing core route entrypoint; provider helpers stay private, never bridge-accessible transport drivers
- Built-in provider/config/secret/auth/document preparation stays in Rust; caller-authored callbacks and focused Python-file reads run only at core-selected points
- Target GIL-enabled CPython explicitly with `#[pymodule(gil_used = true)]`; detach Rust-only work
diff --git a/litellm-rust/crates/python-bridge/Cargo.toml b/litellm-rust/crates/python-bridge/Cargo.toml
index 8d31855f2fa..3a4a579efa3 100644
--- a/litellm-rust/crates/python-bridge/Cargo.toml
+++ b/litellm-rust/crates/python-bridge/Cargo.toml
@@ -18,7 +18,7 @@ panic-test = []
[dependencies]
bytes.workspace = true
litellm-auth.workspace = true
-litellm-callbacks-legacy.workspace = true
+litellm-callbacks-legacy-python.workspace = true
litellm-core.workspace = true
litellm-core-utils.workspace = true
litellm-auth-gcp.workspace = true
diff --git a/litellm-rust/crates/python-bridge/src/routes/messages/mod.rs b/litellm-rust/crates/python-bridge/src/routes/messages/mod.rs
index 8c42315ac59..91591e302b3 100644
--- a/litellm-rust/crates/python-bridge/src/routes/messages/mod.rs
+++ b/litellm-rust/crates/python-bridge/src/routes/messages/mod.rs
@@ -1,7 +1,7 @@
mod host;
use host::MessagesRouteHost;
-use litellm_callbacks_legacy::{LegacySurface, PassThroughStream, PublicCall, run_legacy_call};
+use litellm_callbacks_legacy_python::{LegacySurface, PassThroughStream, PublicCall, run_legacy_call};
use litellm_core::messages::route::{messages_machine, supports};
use pyo3::{
prelude::*,
diff --git a/litellm-rust/crates/python-bridge/src/routes/ocr/mod.rs b/litellm-rust/crates/python-bridge/src/routes/ocr/mod.rs
index 9be3171f70b..e518f972bac 100644
--- a/litellm-rust/crates/python-bridge/src/routes/ocr/mod.rs
+++ b/litellm-rust/crates/python-bridge/src/routes/ocr/mod.rs
@@ -7,7 +7,7 @@ use std::sync::{Arc, LazyLock};
use host::OcrRouteHost;
use litellm_auth_gcp::VertexAuth;
-use litellm_callbacks_legacy::{LegacySurface, PublicCall, run_legacy_call};
+use litellm_callbacks_legacy_python::{LegacySurface, PublicCall, run_legacy_call};
use litellm_core::ocr::route::ocr_machine;
use litellm_core_utils::settings::ProcessEnvironment;
use litellm_llms::base_llm::ocr::{
diff --git a/litellm/rust_bridge/legacy_callbacks.py b/litellm/rust_bridge/callbacks_legacy_python.py
similarity index 100%
rename from litellm/rust_bridge/legacy_callbacks.py
rename to litellm/rust_bridge/callbacks_legacy_python.py
diff --git a/tests/test_litellm/rust_bridge/test_legacy_callbacks.py b/tests/test_litellm/rust_bridge/test_callbacks_legacy_python.py
similarity index 91%
rename from tests/test_litellm/rust_bridge/test_legacy_callbacks.py
rename to tests/test_litellm/rust_bridge/test_callbacks_legacy_python.py
index a0906c7c5be..1f6a214398a 100644
--- a/tests/test_litellm/rust_bridge/test_legacy_callbacks.py
+++ b/tests/test_litellm/rust_bridge/test_callbacks_legacy_python.py
@@ -10,8 +10,8 @@ from pydantic import TypeAdapter
import litellm
from litellm.litellm_core_utils.litellm_logging import Logging
-from litellm.rust_bridge import legacy_callbacks as legacy
-from litellm.rust_bridge.legacy_callbacks import check_limits, setup
+from litellm.rust_bridge import callbacks_legacy_python as legacy
+from litellm.rust_bridge.callbacks_legacy_python import check_limits, setup
_OCR_KWARGS: Final = MappingProxyType(
{
@@ -81,7 +81,9 @@ def test_setup_builds_a_logger_when_none_is_supplied(call_type: str, kwargs: Map
assert result.logger.litellm_call_id == result.kwargs["litellm_call_id"]
-CONTRACT_PATH: Final = Path(__file__).parents[3] / "litellm-rust/crates/callbacks-legacy/python_contract.json"
+CONTRACT_PATH: Final = (
+ Path(__file__).parents[3] / "litellm-rust/crates/callbacks-legacy-python/python_contract.json"
+)
def test_the_rust_contract_matches_the_shim_signatures() -> None: