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(rust): split custom_httpx into litellm-http and the OCR handler
Yujong Leed77c144c6cb8
diff --git a/litellm-rust/Cargo.lock b/litellm-rust/Cargo.lockindex 83cdbc6a782..5fbddcaffcf 100644--- a/litellm-rust/Cargo.lock+++ b/litellm-rust/Cargo.lock@@ -2141,6 +2141,7 @@ dependencies = ["reqwest 0.12.28","rstest","rustls 0.23.42",+ "serde_json","thiserror 2.0.19","tokio","webpki-roots",diff --git a/litellm-rust/crates/core/AGENTS.md b/litellm-rust/crates/core/AGENTS.mdindex 449c3e647f7..0c8a747019d 100644--- a/litellm-rust/crates/core/AGENTS.md+++ b/litellm-rust/crates/core/AGENTS.md@@ -5,10 +5,11 @@ litellm-core is the LiteLLM SDK in Rust — it makes the LLM call. Each top-leveEach crate mirrors one top-level Python package, so a Rust path reads as its Python path with the crate name in place of the package directory. Dependencies only point down:- `litellm-types` mirrors `litellm/types/`: pure serde data, no I/O-- `litellm-core-utils` mirrors `litellm/litellm_core_utils/`: pure helpers (provider resolution, prompt factory, call arguments), no network I/O-- `litellm-llms` mirrors `litellm/llms/`: `base_llm/<api>/transformation.rs`, `<provider>/<api>/transformation.rs`, and `custom_httpx/` (HTTP helpers and the OCR request handler)+- `litellm-core-utils` mirrors `litellm/litellm_core_utils/`: pure helpers (provider resolution, prompt factory, call arguments, settings lookup and layer merge), no network I/O+- `litellm-http` is Rust-only and route-neutral: settings resolution, the pooled `reqwest` clients, TLS, proxies, the SSRF-safe media fetcher, request and header helpers, and transport errors. Python's `litellm/llms/custom_httpx/` is split by responsibility instead of mirrored: its transport half lives here, its OCR handler in `litellm-llms`+- `litellm-llms` mirrors `litellm/llms/`: `base_llm/<api>/transformation.rs`, `<provider>/<api>/transformation.rs`, and `base_llm/ocr/handler.rs` (the OCR request handler)- `litellm-core` mirrors the route packages (`litellm/ocr/`, `litellm/messages/`, ...): entrypoints, route request types, provider dispatch, the route machine, and hooks-A route module owns the call entrypoint, route request types (`*Request<'a>`), credential fallback, provider dispatch, and the handler glue that runs a provider config. Provider code never imports from core; when it needs the caller's hooks mid-call it goes through `litellm_llms::custom_httpx::llm_http_handler::CallHooks`, which each route implements over its host. Import every item from its canonical path. Never re-export another crate's items or give an item a second public path; the only re-export allowed is a private submodule surfacing its item at its module root (`mod error; pub use error::Error;`). Handlers belong in core or llms, never in a host crate+A route module owns the call entrypoint, route request types (`*Request<'a>`), credential fallback, provider dispatch, and the handler glue that runs a provider config. Provider code never imports from core; when it needs the caller's hooks mid-call it goes through `litellm_llms::base_llm::ocr::handler::CallHooks`, which each route implements over its host. Import every item from its canonical path. Never re-export another crate's items or give an item a second public path; the only re-export allowed is a private submodule surfacing its item at its module root (`mod error; pub use error::Error;`). Handlers belong in core or llms, never in a host crateNot here: serving HTTP (axum routes, extractors), config file reading, rollout state, databases, or callback execution of any kind. Core runs each route as a machine that yields host operations and call events; which integrations consume those events is the host's business.diff --git a/litellm-rust/crates/core/Cargo.toml b/litellm-rust/crates/core/Cargo.tomlindex ab04fb8d4ae..69ae8004d46 100644--- a/litellm-rust/crates/core/Cargo.toml+++ b/litellm-rust/crates/core/Cargo.toml@@ -15,6 +15,7 @@ futures-util.workspace = truebase64.workspace = truelitellm-auth.workspace = truelitellm-auth-aws.workspace = true+litellm-http.workspace = truelitellm-llms.workspace = truemoka.workspace = truemime_guess = "2.0.5"@@ -36,7 +37,6 @@ veil.workspace = true[dev-dependencies]litellm-auth-gcp.workspace = true-litellm-http.workspace = truelitellm-llms = { workspace = true, features = ["test-support"] }rstest.workspace = truerstest_reuse.workspace = truediff --git a/litellm-rust/crates/core/src/audio_transcription/error.rs b/litellm-rust/crates/core/src/audio_transcription/error.rsindex 39b08e882f5..122cbab358f 100644--- a/litellm-rust/crates/core/src/audio_transcription/error.rs+++ b/litellm-rust/crates/core/src/audio_transcription/error.rs@@ -20,9 +20,9 @@ pub enum Error {#[error(transparent)]Auth(#[from] litellm_auth::Error),#[error(transparent)]- Transport(#[from] litellm_llms::custom_httpx::transport::Error),+ Transport(#[from] litellm_http::transport::Error),#[error(transparent)]- Headers(#[from] litellm_llms::custom_httpx::http_handler::HeaderError),+ Headers(#[from] litellm_http::request::HeaderError),#[error(transparent)]Aws(#[from] litellm_auth_aws::Error),}diff --git a/litellm-rust/crates/core/src/audio_transcription/handler.rs b/litellm-rust/crates/core/src/audio_transcription/handler.rsindex 0704f9391b0..503cc922966 100644--- a/litellm-rust/crates/core/src/audio_transcription/handler.rs+++ b/litellm-rust/crates/core/src/audio_transcription/handler.rs@@ -1,4 +1,4 @@-use litellm_llms::custom_httpx::http_handler::{http_request, truncate_error_body};+use litellm_http::request::{http_request, truncate_error_body};use serde_json::Value;use super::{Error, client::http_client};@@ -18,23 +18,17 @@ pub async fn execute_audio_transcription_provider_call(request_builder = request_builder.timeout(duration);}let response = http_request(request_builder).await.map_err(|error| {- Error::Transport(litellm_llms::custom_httpx::transport::Error::Network(- error.to_string(),- ))+ Error::Transport(litellm_http::transport::Error::Network(error.to_string()))})?;let status = response.status();let text = response.text().await.map_err(|error| {- Error::Transport(litellm_llms::custom_httpx::transport::Error::Network(- error.to_string(),- ))+ Error::Transport(litellm_http::transport::Error::Network(error.to_string()))})?;if !status.is_success() {- return Err(Error::Transport(- litellm_llms::custom_httpx::transport::Error::Http {- status: status.as_u16(),- body: truncate_error_body(&text),- },- ));+ return Err(Error::Transport(litellm_http::transport::Error::Http {+ status: status.as_u16(),+ body: truncate_error_body(&text),+ }));}let response_json = serde_json::from_str(&text).map_err(|error| Error::InvalidResponse(format!("invalid audio response JSON: {error}")))?;diff --git a/litellm-rust/crates/core/src/audio_transcription/prepare.rs b/litellm-rust/crates/core/src/audio_transcription/prepare.rsindex 193122db733..829617d26bd 100644--- a/litellm-rust/crates/core/src/audio_transcription/prepare.rs+++ b/litellm-rust/crates/core/src/audio_transcription/prepare.rs@@ -1,10 +1,10 @@use litellm_core_utils::get_llm_provider_logic::{CustomLlmProvider, get_custom_llm_provider};+use litellm_http::request::{has_header, string_headers};use litellm_llms::{base_llm::audio_transcription::transformation::{AudioTranscriptionAuth, BaseAudioTranscriptionConfig,},bedrock::audio_transcription::BEDROCK_AUDIO_TRANSCRIPTION_CONFIG,- custom_httpx::http_handler::{has_header, string_headers},};use super::Error;diff --git a/litellm-rust/crates/core/src/chat_completions/common_utils.rs b/litellm-rust/crates/core/src/chat_completions/common_utils.rsindex cc9459793df..4ed39a90366 100644--- a/litellm-rust/crates/core/src/chat_completions/common_utils.rs+++ b/litellm-rust/crates/core/src/chat_completions/common_utils.rs@@ -1,8 +1,8 @@+use litellm_http::request::string_headers as shared_string_headers;use litellm_llms::{anthropic::chat::transformation::ANTHROPIC_CHAT_COMPLETIONS_CONFIG,base_llm::chat::transformation::BaseConfig,bedrock::chat::converse_transformation::BEDROCK_CHAT_COMPLETIONS_CONFIG,- custom_httpx::http_handler::string_headers as shared_string_headers,};use serde_json::{Map, Value};diff --git a/litellm-rust/crates/core/src/chat_completions/error.rs b/litellm-rust/crates/core/src/chat_completions/error.rsindex 39b08e882f5..122cbab358f 100644--- a/litellm-rust/crates/core/src/chat_completions/error.rs+++ b/litellm-rust/crates/core/src/chat_completions/error.rs@@ -20,9 +20,9 @@ pub enum Error {#[error(transparent)]Auth(#[from] litellm_auth::Error),#[error(transparent)]- Transport(#[from] litellm_llms::custom_httpx::transport::Error),+ Transport(#[from] litellm_http::transport::Error),#[error(transparent)]- Headers(#[from] litellm_llms::custom_httpx::http_handler::HeaderError),+ Headers(#[from] litellm_http::request::HeaderError),#[error(transparent)]Aws(#[from] litellm_auth_aws::Error),}diff --git a/litellm-rust/crates/core/src/chat_completions/handler.rs b/litellm-rust/crates/core/src/chat_completions/handler.rsindex 034408bdf17..b73d4838760 100644--- a/litellm-rust/crates/core/src/chat_completions/handler.rs+++ b/litellm-rust/crates/core/src/chat_completions/handler.rs@@ -1,7 +1,5 @@-use litellm_llms::{- base_llm::chat::transformation::{ChatCompletionsAuth, ProviderChatResponseData},- custom_httpx::http_handler::{http_request, truncate_error_body},-};+use litellm_http::request::{http_request, truncate_error_body};+use litellm_llms::base_llm::chat::transformation::{ChatCompletionsAuth, ProviderChatResponseData};use litellm_types::utils::ChatCompletionsResponse;use serde_json::Value;@@ -34,30 +32,22 @@ pub(super) async fn execute_chat_completions_provider_call(// so the host can still serve it. Everything else here, a timeout// above all, may have reached the provider and been answered.if err.is_connect() || err.is_builder() {- Error::Transport(litellm_llms::custom_httpx::transport::Error::Connect(- err.to_string(),- ))+ Error::Transport(litellm_http::transport::Error::Connect(err.to_string()))} else {- Error::Transport(litellm_llms::custom_httpx::transport::Error::Network(- err.to_string(),- ))+ Error::Transport(litellm_http::transport::Error::Network(err.to_string()))}})?;let status = response.status();let text = response.text().await.map_err(|err| {- Error::Transport(litellm_llms::custom_httpx::transport::Error::Network(- err.to_string(),- ))+ Error::Transport(litellm_http::transport::Error::Network(err.to_string()))})?;if !status.is_success() {- return Err(Error::Transport(- litellm_llms::custom_httpx::transport::Error::Http {- status: status.as_u16(),- body: truncate_error_body(&text),- },- ));+ return Err(Error::Transport(litellm_http::transport::Error::Http {+ status: status.as_u16(),+ body: truncate_error_body(&text),+ }));}let body: Value = serde_json::from_str(&text).map_err(|err| {@@ -82,9 +72,7 @@ pub(super) async fn execute_chat_completions_provider_call(pub(super) fn as_response_error(err: Error) -> Error {match err {already @ (Error::InvalidResponse(_)- | Error::Transport(litellm_llms::custom_httpx::transport::Error::Http {- ..- })) => already,+ | Error::Transport(litellm_http::transport::Error::Http { .. })) => already,other => Error::InvalidResponse(other.to_string()),}}diff --git a/litellm-rust/crates/core/src/chat_completions/prepare.rs b/litellm-rust/crates/core/src/chat_completions/prepare.rsindex d408ea6574e..d0aa1e88011 100644--- a/litellm-rust/crates/core/src/chat_completions/prepare.rs+++ b/litellm-rust/crates/core/src/chat_completions/prepare.rs@@ -1,8 +1,6 @@use litellm_core_utils::get_llm_provider_logic::{CustomLlmProvider, get_custom_llm_provider};-use litellm_llms::{- base_llm::chat::transformation::{BaseConfig, ChatCompletionsAuth},- custom_httpx::http_handler::has_header,-};+use litellm_http::request::has_header;+use litellm_llms::base_llm::chat::transformation::{BaseConfig, ChatCompletionsAuth};use litellm_types::llms::openai::ChatMessage;use serde_json::Value;diff --git a/litellm-rust/crates/core/src/chat_completions/tests.rs b/litellm-rust/crates/core/src/chat_completions/tests.rsindex cbc4995ce0d..dcaa3397add 100644--- a/litellm-rust/crates/core/src/chat_completions/tests.rs+++ b/litellm-rust/crates/core/src/chat_completions/tests.rs@@ -265,7 +265,7 @@ fn rejects_non_string_extra_headers() {call.extra_headers = Some(Map::from_iter([("x-trace".to_string(), json!(7))]));assert_eq!(decline(call),- Error::Headers(litellm_llms::custom_httpx::http_handler::HeaderError {+ Error::Headers(litellm_http::request::HeaderError {context: "chat completions",name: "x-trace".to_string(),actual: "number",@@ -771,10 +771,7 @@ mod round_trip {assert!(matches!(err,- Error::Transport(litellm_llms::custom_httpx::transport::Error::Http {- status: 429,- ..- })+ Error::Transport(litellm_http::transport::Error::Http { status: 429, .. })),"expected a 429, got {err:?}");@@ -801,7 +798,7 @@ mod round_trip {assert!(matches!(err,- Error::Transport(litellm_llms::custom_httpx::transport::Error::Connect(_))+ Error::Transport(litellm_http::transport::Error::Connect(_))),"expected a pre-send connect failure, got {err:?}");@@ -825,16 +822,11 @@ mod round_trip {}// An upstream status is already unambiguous, so it survives intact.assert!(matches!(- as_response_error(Error::Transport(- litellm_llms::custom_httpx::transport::Error::Http {- status: 500,- body: "boom".to_string()- }- )),- Error::Transport(litellm_llms::custom_httpx::transport::Error::Http {+ as_response_error(Error::Transport(litellm_http::transport::Error::Http {status: 500,- ..- })+ body: "boom".to_string()+ })),+ Error::Transport(litellm_http::transport::Error::Http { status: 500, .. })));}}diff --git a/litellm-rust/crates/core/src/messages/common_utils.rs b/litellm-rust/crates/core/src/messages/common_utils.rsindex ec392324784..dcefa3ebffc 100644--- a/litellm-rust/crates/core/src/messages/common_utils.rs+++ b/litellm-rust/crates/core/src/messages/common_utils.rs@@ -1,11 +1,9 @@-pub(super) use litellm_llms::custom_httpx::http_handler::{- has_bearer_auth, has_header, truncate_error_body,-};+use litellm_http::request::string_headers as shared_string_headers;+pub(super) use litellm_http::request::{has_bearer_auth, has_header, truncate_error_body};use litellm_llms::{anthropic::experimental_pass_through::messages::transformation::ANTHROPIC_MESSAGES_CONFIG,azure_ai::anthropic::messages_transformation::AZURE_ANTHROPIC_MESSAGES_CONFIG,base_llm::anthropic_messages::transformation::BaseAnthropicMessagesConfig,- custom_httpx::http_handler::string_headers as shared_string_headers,};use serde_json::{Map, Value};diff --git a/litellm-rust/crates/core/src/messages/error.rs b/litellm-rust/crates/core/src/messages/error.rsindex 71bb748c50d..51fb764032c 100644--- a/litellm-rust/crates/core/src/messages/error.rs+++ b/litellm-rust/crates/core/src/messages/error.rs@@ -15,9 +15,9 @@ pub enum Error {#[error(transparent)]Auth(#[from] litellm_auth::Error),#[error(transparent)]- Transport(#[from] litellm_llms::custom_httpx::transport::Error),+ Transport(#[from] litellm_http::transport::Error),#[error(transparent)]- Headers(#[from] litellm_llms::custom_httpx::http_handler::HeaderError),+ Headers(#[from] litellm_http::request::HeaderError),}impl From<LlmError> for Error {diff --git a/litellm-rust/crates/core/src/messages/handler.rs b/litellm-rust/crates/core/src/messages/handler.rsindex 22e2c398ff7..fe7e8bb4b80 100644--- a/litellm-rust/crates/core/src/messages/handler.rs+++ b/litellm-rust/crates/core/src/messages/handler.rs@@ -1,9 +1,7 @@use std::time::Duration;-use litellm_llms::{- base_llm::anthropic_messages::transformation::BaseAnthropicMessagesConfig,- custom_httpx::{http_handler::http_request, transport::Error as TransportError},-};+use litellm_http::{request::http_request, transport::Error as TransportError};+use litellm_llms::base_llm::anthropic_messages::transformation::BaseAnthropicMessagesConfig;use litellm_types::llms::anthropic_messages::anthropic_response::AnthropicMessagesResponse;use serde_json::Value;diff --git a/litellm-rust/crates/core/src/messages/tests.rs b/litellm-rust/crates/core/src/messages/tests.rsindex 55d8ead8e8b..057b42a316c 100644--- a/litellm-rust/crates/core/src/messages/tests.rs+++ b/litellm-rust/crates/core/src/messages/tests.rs@@ -82,7 +82,7 @@ fn string_headers_rejects_non_string_values() {let err = string_headers(Some(headers)).expect_err("non-string header rejected");assert_eq!(err,- Error::Headers(litellm_llms::custom_httpx::http_handler::HeaderError {+ Error::Headers(litellm_http::request::HeaderError {context: "messages",name: "x-count".to_string(),actual: "number",@@ -432,7 +432,7 @@ async fn messages_maps_provider_error_status_to_http_error() {assert!(matches!(err,- Error::Transport(litellm_llms::custom_httpx::transport::Error::Http { status: 401, .. })+ Error::Transport(litellm_http::transport::Error::Http { status: 401, .. })));}diff --git a/litellm-rust/crates/core/src/ocr/client.rs b/litellm-rust/crates/core/src/ocr/client.rsindex c7b4751bd9e..e635f93a294 100644--- a/litellm-rust/crates/core/src/ocr/client.rs+++ b/litellm-rust/crates/core/src/ocr/client.rs@@ -1,6 +1,5 @@-use litellm_llms::{- base_llm::ocr::{error::Error, transformation::LiteLLMOcrResponse},- custom_httpx::llm_http_handler::OcrClient,+use litellm_llms::base_llm::ocr::{+ error::Error, handler::OcrClient, transformation::LiteLLMOcrResponse,};use crate::ocr::{diff --git a/litellm-rust/crates/core/src/ocr/handler.rs b/litellm-rust/crates/core/src/ocr/handler.rsindex bbf9cfa0e02..f49976de043 100644--- a/litellm-rust/crates/core/src/ocr/handler.rs+++ b/litellm-rust/crates/core/src/ocr/handler.rs@@ -1,12 +1,10 @@use futures_util::future::BoxFuture;use litellm_auth::SecretValue;use litellm_host::event::{MachineEvent, RawResponse, RequestContext, WireRequest};-use litellm_llms::{- base_llm::ocr::{- error::Error,- transformation::{LiteLLMOcrResponse, PreparedOcrRequest},- },- custom_httpx::llm_http_handler::{CallHooks, OcrClient},+use litellm_llms::base_llm::ocr::{+ error::Error,+ handler::{CallHooks, OcrClient},+ transformation::{LiteLLMOcrResponse, PreparedOcrRequest},};use serde_json::Value;diff --git a/litellm-rust/crates/core/src/ocr/provider_config.rs b/litellm-rust/crates/core/src/ocr/provider_config.rsindex 14b34ea4564..ee9ba76928d 100644--- a/litellm-rust/crates/core/src/ocr/provider_config.rs+++ b/litellm-rust/crates/core/src/ocr/provider_config.rs@@ -7,13 +7,13 @@ use litellm_llms::{},base_llm::ocr::{error::Error,+ handler::{self, CallHooks, OcrClient},transformation::{BaseOcrConfig, LiteLLMOcrResponse, OcrCredentialInputs, OcrDocument,PreparedOcrRequest, ResolvedOcrCredentials,},},cohere::ocr::transformation::CohereParseConfig,- custom_httpx::llm_http_handler::{self, CallHooks, OcrClient},mistral::ocr::transformation::MistralOcrConfig,reducto::ocr::transformation::{ReductoParseLegacyConfig, ReductoParseV3Config},vertex_ai::ocr::{@@ -116,7 +116,7 @@ impl OcrConfigKind {request: &PreparedOcrRequest,hooks: &dyn CallHooks<Error>,) -> Result<LiteLLMOcrResponse, Error> {- with_config!(self, config => llm_http_handler::ocr(&config, client, request, hooks).await)+ with_config!(self, config => handler::ocr(&config, client, request, hooks).await)}}diff --git a/litellm-rust/crates/core/src/ocr/route.rs b/litellm-rust/crates/core/src/ocr/route.rsindex bfc8c5ca965..26c9ac27102 100644--- a/litellm-rust/crates/core/src/ocr/route.rs+++ b/litellm-rust/crates/core/src/ocr/route.rs@@ -6,9 +6,8 @@ use litellm_host::{machine::{HostChannel, HostTokenProvider, MachineFault, RouteMachine, TokenRoute},route::Route,};-use litellm_llms::{- base_llm::ocr::{error::Error, transformation::LiteLLMOcrResponse},- custom_httpx::llm_http_handler::OcrClient,+use litellm_llms::base_llm::ocr::{+ error::Error, handler::OcrClient, transformation::LiteLLMOcrResponse,};use super::handler::perform_ocr_request;diff --git a/litellm-rust/crates/core/src/responses/error.rs b/litellm-rust/crates/core/src/responses/error.rsindex 677db2e08de..1c940d8ed9b 100644--- a/litellm-rust/crates/core/src/responses/error.rs+++ b/litellm-rust/crates/core/src/responses/error.rs@@ -11,7 +11,7 @@ pub enum Error {#[error(transparent)]Auth(#[from] litellm_auth::Error),#[error(transparent)]- Transport(#[from] litellm_llms::custom_httpx::transport::Error),+ Transport(#[from] litellm_http::transport::Error),#[error(transparent)]- Headers(#[from] litellm_llms::custom_httpx::http_handler::HeaderError),+ Headers(#[from] litellm_http::request::HeaderError),}diff --git a/litellm-rust/crates/core/src/responses/websocket.rs b/litellm-rust/crates/core/src/responses/websocket.rsindex ccf4aa75149..f57ba65a6fb 100644--- a/litellm-rust/crates/core/src/responses/websocket.rs+++ b/litellm-rust/crates/core/src/responses/websocket.rs@@ -95,9 +95,7 @@ impl ResponsesWebSocketConnection {timeout: Option<Duration>,) -> Result<Self, Error> {let mut request = url.into_client_request().map_err(|error| {- Error::Transport(litellm_llms::custom_httpx::transport::Error::Network(- error.to_string(),- ))+ Error::Transport(litellm_http::transport::Error::Network(error.to_string()))})?;for (name, value) in headers {let header_name = name@@ -110,7 +108,7 @@ impl ResponsesWebSocketConnection {let connect = connect_upstream(request);let result = match timeout {Some(timeout) => tokio::time::timeout(timeout, connect).await.map_err(|_| {- Error::Transport(litellm_llms::custom_httpx::transport::Error::Network(+ Error::Transport(litellm_http::transport::Error::Network("Responses WebSocket connection timed out".into(),))})?,@@ -118,14 +116,12 @@ impl ResponsesWebSocketConnection {};let (socket, _) = result.map_err(|error| match *error {tokio_tungstenite::tungstenite::Error::Http(response) => {- Error::Transport(litellm_llms::custom_httpx::transport::Error::Http {+ Error::Transport(litellm_http::transport::Error::Http {status: response.status().as_u16(),body: String::new(),})}- other => Error::Transport(litellm_llms::custom_httpx::transport::Error::Network(- other.to_string(),- )),+ other => Error::Transport(litellm_http::transport::Error::Network(other.to_string())),})?;Ok(Self {socket: Arc::new(Mutex::new(Some(socket))),@@ -135,16 +131,12 @@ impl ResponsesWebSocketConnection {pub async fn send_text(&self, text: String) -> Result<(), Error> {let mut socket = self.socket.lock().await;let Some(socket) = socket.as_mut() else {- return Err(Error::Transport(- litellm_llms::custom_httpx::transport::Error::Network(- "Responses WebSocket is closed".into(),- ),- ));+ return Err(Error::Transport(litellm_http::transport::Error::Network(+ "Responses WebSocket is closed".into(),+ )));};socket.send(Message::Text(text)).await.map_err(|error| {- Error::Transport(litellm_llms::custom_httpx::transport::Error::Network(- error.to_string(),- ))+ Error::Transport(litellm_http::transport::Error::Network(error.to_string()))})}@@ -160,9 +152,9 @@ impl ResponsesWebSocketConnection {.map_err(|error| Error::InvalidResponse(error.to_string())),Some(Ok(Message::Close(_))) | None => Ok(None),Some(Ok(_)) => Ok(None),- Some(Err(error)) => Err(Error::Transport(- litellm_llms::custom_httpx::transport::Error::Network(error.to_string()),- )),+ Some(Err(error)) => Err(Error::Transport(litellm_http::transport::Error::Network(+ error.to_string(),+ ))),}}@@ -170,9 +162,7 @@ impl ResponsesWebSocketConnection {let mut socket = self.socket.lock().await;if let Some(socket) = socket.as_mut() {socket.close(None).await.map_err(|error| {- Error::Transport(litellm_llms::custom_httpx::transport::Error::Network(- error.to_string(),- ))+ Error::Transport(litellm_http::transport::Error::Network(error.to_string()))})?;}*socket = None;diff --git a/litellm-rust/crates/core/tests/ocr.rs b/litellm-rust/crates/core/tests/ocr.rsindex e7a8fc0abc1..b999c43de8b 100644--- a/litellm-rust/crates/core/tests/ocr.rs+++ b/litellm-rust/crates/core/tests/ocr.rs@@ -6,16 +6,14 @@ use litellm_host::{host::{Host, HostOp, HostResult},machine::{HostFailure, Machine, MachineStep},};-use litellm_http::{HttpClientPool, HttpSettings, Resolution};-use litellm_llms::{- base_llm::ocr::{- error::Error as OcrError,- transformation::{LiteLLMOcrResponse, OCR_RESPONSE_MAX_BYTES, OcrTransportConfig},- },- custom_httpx::{- llm_http_handler::OcrClient,- media::{PublicDnsResolver, UrlPolicy},- },+use litellm_http::{+ HttpClientPool, HttpSettings, Resolution,+ media::{PublicDnsResolver, UrlPolicy},+};+use litellm_llms::base_llm::ocr::{+ error::Error as OcrError,+ handler::OcrClient,+ transformation::{LiteLLMOcrResponse, OCR_RESPONSE_MAX_BYTES, OcrTransportConfig},};use rstest::rstest;use serde_json::{Value, json};@@ -624,7 +622,7 @@ async fn read_bounded_response(response: Vec<u8>, limit: usize) -> Result<bytes:.unwrap();let result = tokio::time::timeout(std::time::Duration::from_secs(2),- litellm_llms::custom_httpx::llm_http_handler::read_response_bytes(response, limit),+ litellm_llms::base_llm::ocr::handler::read_response_bytes(response, limit),).await;server.abort();@@ -676,10 +674,7 @@ async fn oversized_error_retains_http_status_and_bounded_diagnostics_without_dra.await.unwrap_err();match error {- OcrError::Transport(litellm_llms::custom_httpx::transport::Error::Http {- status,- body,- }) => {+ OcrError::Transport(litellm_http::transport::Error::Http { status, body }) => {assert_eq!(status, 429);assert_eq!(body, prefix);}diff --git a/litellm-rust/crates/core/tests/ocr/support.rs b/litellm-rust/crates/core/tests/ocr/support.rsindex b368a754656..974fa3d6655 100644--- a/litellm-rust/crates/core/tests/ocr/support.rs+++ b/litellm-rust/crates/core/tests/ocr/support.rs@@ -2,9 +2,10 @@ use std::sync::{Arc, Mutex};use futures_util::future::BoxFuture;use litellm_host::event::WireRequest;-use litellm_llms::{- base_llm::ocr::{error::Error, transformation::LiteLLMOcrResponse},- custom_httpx::llm_http_handler::{CallHooks, OcrClient},+use litellm_llms::base_llm::ocr::{+ error::Error,+ handler::{CallHooks, OcrClient},+ transformation::LiteLLMOcrResponse,};use serde_json::{Value, json};use tokio::{diff --git a/litellm-rust/crates/http/Cargo.toml b/litellm-rust/crates/http/Cargo.tomlindex b0dc7693840..4f94f37a8d5 100644--- a/litellm-rust/crates/http/Cargo.toml+++ b/litellm-rust/crates/http/Cargo.toml@@ -5,13 +5,18 @@ edition.workspace = truelicense.workspace = truerepository.workspace = true+[features]+test-support = []+[dependencies]http.workspace = truelitellm-core-utils.workspace = truehyper-util.workspace = truereqwest.workspace = truerustls.workspace = true+serde_json.workspace = truethiserror.workspace = true+tokio.workspace = truewebpki-roots.workspace = true[dev-dependencies]diff --git a/litellm-rust/crates/http/src/lib.rs b/litellm-rust/crates/http/src/lib.rsindex ddbc3b63b08..c6d9959348d 100644--- a/litellm-rust/crates/http/src/lib.rs+++ b/litellm-rust/crates/http/src/lib.rs@@ -1,9 +1,12 @@mod config;mod error;+pub mod media;mod pool;mod proxy;+pub mod request;mod settings;mod tls;+pub mod transport;pub use config::{HttpClientConfig, Resolution, Verify};pub use error::Error;diff --git a/litellm-rust/crates/llms/src/custom_httpx/media.rs b/litellm-rust/crates/http/src/media.rssimilarity index 97%rename from litellm-rust/crates/llms/src/custom_httpx/media.rsrename to litellm-rust/crates/http/src/media.rsindex 059d0a05010..ae3f55b476a 100644--- a/litellm-rust/crates/llms/src/custom_httpx/media.rs+++ b/litellm-rust/crates/http/src/media.rs@@ -7,12 +7,13 @@ use std::{time::Duration,};-use litellm_http::{ClientVariant, HttpClientConfig, HttpClientPool};use reqwest::{Url,dns::{Addrs, Name, Resolve, Resolving},};+use crate::{ClientVariant, HttpClientConfig, HttpClientPool};+#[derive(Debug, thiserror::Error)]pub enum Error {#[error("media URL rejected by network policy")]@@ -32,7 +33,7 @@ pub enum Error {#[error("media download timed out")]Timeout,#[error("{0}")]- Transport(#[from] crate::custom_httpx::transport::Error),+ Transport(#[from] crate::transport::Error),}#[derive(Clone, Debug, PartialEq, Eq)]@@ -101,7 +102,7 @@ impl MediaFetcher {pool: &HttpClientPool,config: &HttpClientConfig,url_policy: UrlPolicy,- ) -> Result<Self, litellm_http::Error> {+ ) -> Result<Self, crate::Error> {let proxies = config.proxies.clone();let uses_proxy: ProxyMatch = Arc::new(move |url| proxies.apply_to(url));Self::with_resolution(@@ -119,7 +120,7 @@ impl MediaFetcher {url_policy: UrlPolicy,address_resolver: Arc<dyn AddressResolver>,uses_proxy: ProxyMatch,- ) -> Result<Self, litellm_http::Error> {+ ) -> Result<Self, crate::Error> {Ok(Self {pinned: pool.client(config, ClientVariant::Media)?,unpinned: pool.client(config, ClientVariant::UnpinnedMedia)?,@@ -164,7 +165,7 @@ impl MediaFetcher {.get(url.clone()).send().await- .map_err(crate::custom_httpx::transport::Error::from)?;+ .map_err(crate::transport::Error::from)?;if response.status().is_redirection() {if redirects_followed == policy.max_redirects {return Err(Error::TooManyRedirects);@@ -195,7 +196,7 @@ impl MediaFetcher {while let Some(chunk) = response.chunk().await- .map_err(crate::custom_httpx::transport::Error::from)?+ .map_err(crate::transport::Error::from)?{enforce_download_size(bytes.len() as u64 + chunk.len() as u64, policy.max_bytes)?;bytes.extend_from_slice(&chunk);@@ -245,7 +246,7 @@ impl MediaFetcher {.address_resolver.resolve(host, port).await- .map_err(|error| crate::custom_httpx::transport::Error::Network(error.to_string()))?;+ .map_err(|error| crate::transport::Error::Network(error.to_string()))?;validate_addresses(&addresses)}}@@ -346,13 +347,13 @@ impl Resolve for PublicDnsResolver {mod tests {use std::collections::HashSet;- use litellm_http::{HttpSettings, Resolution};use tokio::{io::{AsyncReadExt, AsyncWriteExt},net::TcpListener,};use super::*;+ use crate::{HttpSettings, Resolution};async fn serve(response: &'static [u8]) -> (Url, tokio::task::JoinHandle<()>) {let listener = TcpListener::bind("127.0.0.1:0")diff --git a/litellm-rust/crates/llms/src/custom_httpx/http_handler.rs b/litellm-rust/crates/http/src/request.rssimilarity index 93%rename from litellm-rust/crates/llms/src/custom_httpx/http_handler.rsrename to litellm-rust/crates/http/src/request.rsindex e629be37336..874a0f3abf9 100644--- a/litellm-rust/crates/llms/src/custom_httpx/http_handler.rs+++ b/litellm-rust/crates/http/src/request.rs@@ -13,20 +13,12 @@ use serde_json::{Map, Value};/// before truncation, so provider bodies are bounded and data-minimized.const UPSTREAM_ERROR_BODY_MAX_CHARS: usize = 256;-#[allow(- dead_code,- reason = "used by the OCR architecture in the next stacked PR"-)]pub enum HeaderPolicy<'a> {All,Only(&'a [&'a str]),Except(&'a [&'a str]),}-#[allow(- dead_code,- reason = "used by the OCR architecture in the next stacked PR"-)]pub fn with_headers(builder: reqwest::RequestBuilder,headers: &[(String, String)],@@ -107,18 +99,6 @@ pub fn has_bearer_auth(headers: &[(String, String)]) -> bool {})}-#[allow(- dead_code,- reason = "used by the OCR architecture in the next stacked PR"-)]-pub fn deserialize_optional_param<'de, D, T>(deserializer: D) -> Result<Option<Option<T>>, D::Error>-where- D: serde::Deserializer<'de>,- T: serde::Deserialize<'de>,-{- <Option<T> as serde::Deserialize>::deserialize(deserializer).map(Some)-}-#[cfg(test)]mod tests {use serde_json::json;diff --git a/litellm-rust/crates/llms/src/custom_httpx/transport.rs b/litellm-rust/crates/http/src/transport.rssimilarity index 88%rename from litellm-rust/crates/llms/src/custom_httpx/transport.rsrename to litellm-rust/crates/http/src/transport.rsindex c42cdf410f6..8814925bbf2 100644--- a/litellm-rust/crates/llms/src/custom_httpx/transport.rs+++ b/litellm-rust/crates/http/src/transport.rs@@ -46,11 +46,8 @@ mod tests {.send().await.expect_err("invalid port");- let error = crate::custom_httpx::transport::Error::from_reqwest_before_dispatch(error);- assert!(matches!(- error,- crate::custom_httpx::transport::Error::Connect(_)- ));+ let error = crate::transport::Error::from_reqwest_before_dispatch(error);+ assert!(matches!(error, crate::transport::Error::Connect(_)));assert!(!error.to_string().contains("secret"));assert!(!error.to_string().contains("private"));}@@ -76,7 +73,7 @@ mod tests {.await.expect_err("nothing listens on the port");let root_cause = root_cause(&error).expect("reqwest reports a cause");- let message = crate::custom_httpx::transport::Error::from(error).to_string();+ let message = crate::transport::Error::from(error).to_string();assert!(message.contains(&root_cause), "{message}");assert!(!message.contains("secret"));}@@ -105,8 +102,8 @@ mod tests {let error = response.expect_err("server does not respond");assert!(error.is_timeout());assert!(matches!(- crate::custom_httpx::transport::Error::from_reqwest_before_dispatch(error),- crate::custom_httpx::transport::Error::Network(_)+ crate::transport::Error::from_reqwest_before_dispatch(error),+ crate::transport::Error::Network(_)));}}diff --git a/litellm-rust/crates/llms/AGENTS.md b/litellm-rust/crates/llms/AGENTS.mdindex 09fe20cd9d6..bd1c58142fd 100644--- a/litellm-rust/crates/llms/AGENTS.md+++ b/litellm-rust/crates/llms/AGENTS.md@@ -1,4 +1,4 @@-litellm-llms mirrors `litellm/llms/`: base config traits, provider transformations, and the `custom_httpx` handlers. See `../core/AGENTS.md` for how the crates layer.+litellm-llms mirrors `litellm/llms/`: base config traits, provider transformations, and the OCR request handler in `base_llm/ocr/handler.rs`. Transport code (clients, media fetching, header helpers, transport errors) lives in `litellm-http`. See `../core/AGENTS.md` for how the crates layer.## Python/Rust transformation pairsdiff --git a/litellm-rust/crates/llms/Cargo.toml b/litellm-rust/crates/llms/Cargo.tomlindex a81a4427b4d..7afc4171ca8 100644--- a/litellm-rust/crates/llms/Cargo.toml+++ b/litellm-rust/crates/llms/Cargo.toml@@ -6,7 +6,7 @@ license.workspace = truerepository.workspace = true[features]-test-support = []+test-support = ["litellm-http/test-support"][dependencies]litellm-types.workspace = truediff --git a/litellm-rust/crates/llms/src/azure_ai/ocr/cohere_parse_transformation.rs b/litellm-rust/crates/llms/src/azure_ai/ocr/cohere_parse_transformation.rsindex f55f6b067e4..86ee0d96895 100644--- a/litellm-rust/crates/llms/src/azure_ai/ocr/cohere_parse_transformation.rs+++ b/litellm-rust/crates/llms/src/azure_ai/ocr/cohere_parse_transformation.rs@@ -5,6 +5,7 @@ use crate::{base_llm::ocr::{document::{inline_remote_document, validate_inline_document},error::Error,+ handler::OcrClient,transformation::{BaseOcrConfig, LiteLLMOcrResponse, OcrDocument, OcrRequestContext, OcrResponseFormat,PreparedOcrRequest,@@ -13,7 +14,6 @@ use crate::{cohere::ocr::transformation::{CohereOptions, CohereParseConfig, CohereRequest, validate_document,},- custom_httpx::llm_http_handler::OcrClient,};#[derive(Default)]@@ -108,7 +108,7 @@ impl BaseOcrConfig for AzureAICohereParseConfig {}fn validate_request_body(&self, body: &Value) -> Result<(), Error> {- let document = crate::custom_httpx::llm_http_handler::body_document(body)?;+ let document = crate::base_llm::ocr::handler::body_document(body)?;validate_document(&document)?;validate_inline_document(&document)}diff --git a/litellm-rust/crates/llms/src/azure_ai/ocr/document_intelligence/transformation.rs b/litellm-rust/crates/llms/src/azure_ai/ocr/document_intelligence/transformation.rsindex 2e398d0287e..a347375510d 100644--- a/litellm-rust/crates/llms/src/azure_ai/ocr/document_intelligence/transformation.rs+++ b/litellm-rust/crates/llms/src/azure_ai/ocr/document_intelligence/transformation.rs@@ -14,19 +14,16 @@ use serde_json::{Map, Value};use serde_with::serde_as;use tokio::time::Instant;-use crate::{- base_llm::ocr::{- document::InlineDocument,- error::Error,- transformation::{- BaseOcrConfig, DecodedOcrResponse, LiteLLMOcrResponse, OCR_INLINE_MAX_BYTES,- OCR_POLL_RETRY_SECS, OcrConnection, OcrCredentialInputs, OcrDocument, OcrPage,- OcrPageDimensions, OcrResponseContext, OcrResponseFormat, OcrUsageInfo,- PreparedOcrRequest, ResolvedOcrCredentials, credential_env,- decode_and_normalize_response, decode_response,- },+use crate::base_llm::ocr::{+ document::InlineDocument,+ error::Error,+ handler::{CallHooks, OcrClient, read_json_response},+ transformation::{+ BaseOcrConfig, DecodedOcrResponse, LiteLLMOcrResponse, OCR_INLINE_MAX_BYTES,+ OCR_POLL_RETRY_SECS, OcrConnection, OcrCredentialInputs, OcrDocument, OcrPage,+ OcrPageDimensions, OcrResponseContext, OcrResponseFormat, OcrUsageInfo, PreparedOcrRequest,+ ResolvedOcrCredentials, credential_env, decode_and_normalize_response, decode_response,},- custom_httpx::llm_http_handler::{CallHooks, OcrClient, read_json_response},};const AZURE_DI_API_VERSION: &str = "2024-11-30";@@ -440,7 +437,7 @@ async fn read_operation_response(hooks: &dyn CallHooks<Error>,) -> Result<DecodedOcrResponse<AzureDocumentIntelligenceOperation>, Error> {if response.status() != reqwest::StatusCode::ACCEPTED {- let bytes = crate::custom_httpx::llm_http_handler::read_response_bytes(+ let bytes = crate::base_llm::ocr::handler::read_response_bytes(response,connection.max_response_bytes,)@@ -462,11 +459,9 @@ async fn read_operation_response({return Err(Error::PollOrigin);}- let bytes = crate::custom_httpx::llm_http_handler::read_response_bytes(- response,- connection.max_response_bytes,- )- .await?;+ let bytes =+ crate::base_llm::ocr::handler::read_response_bytes(response, connection.max_response_bytes)+ .await?;hooks.response_received(&bytes).await?;poll_operation(http_client, operation, headers, connection, native, hooks).await}@@ -491,21 +486,19 @@ async fn poll_operation(let builder = http_client.get(url.clone()).timeout(remaining.min(connection.timeout));- let builder = crate::custom_httpx::http_handler::with_headers(+ let builder = litellm_http::request::with_headers(builder,headers,- crate::custom_httpx::http_handler::HeaderPolicy::Only(&[+ litellm_http::request::HeaderPolicy::Only(&[AZURE_DI_SUBSCRIPTION_HEADER,"authorization",]),);- let response = tokio::time::timeout_at(- deadline,- crate::custom_httpx::http_handler::http_request(builder),- )- .await- .map_err(|_| Error::PollTimeout)?- .map_err(crate::custom_httpx::transport::Error::from)?;+ let response =+ tokio::time::timeout_at(deadline, litellm_http::request::http_request(builder))+ .await+ .map_err(|_| Error::PollTimeout)?+ .map_err(litellm_http::transport::Error::from)?;let retry = response.headers().get(reqwest::header::RETRY_AFTER)@@ -580,8 +573,8 @@ impl AzureDocumentIntelligenceOcrConfig {config: &AzureAuthInputs,env_lookup: &(dyn Fn(&str) -> Option<String> + Sync),) -> Result<Vec<(String, String)>, Error> {- if crate::custom_httpx::http_handler::has_header(&connection.extra_headers, "authorization")- || crate::custom_httpx::http_handler::has_header(+ if litellm_http::request::has_header(&connection.extra_headers, "authorization")+ || litellm_http::request::has_header(&connection.extra_headers,AZURE_DI_SUBSCRIPTION_HEADER,)diff --git a/litellm-rust/crates/llms/src/azure_ai/ocr/transformation.rs b/litellm-rust/crates/llms/src/azure_ai/ocr/transformation.rsindex 7ef051e8986..4a04910aa9a 100644--- a/litellm-rust/crates/llms/src/azure_ai/ocr/transformation.rs+++ b/litellm-rust/crates/llms/src/azure_ai/ocr/transformation.rs@@ -7,12 +7,12 @@ use crate::{base_llm::ocr::{document::{inline_remote_document, validate_inline_document},error::Error,+ handler::OcrClient,transformation::{BaseOcrConfig, LiteLLMOcrResponse, OcrConnection, OcrDocument, OcrRequestContext,OcrResponseFormat, PreparedOcrRequest, credential_env,},},- custom_httpx::llm_http_handler::OcrClient,mistral::ocr::transformation::{MistralOcrConfig, MistralOcrRequest},};@@ -107,7 +107,7 @@ impl BaseOcrConfig for AzureAiOcrConfig {}fn validate_request_body(&self, body: &Value) -> Result<(), Error> {- validate_inline_document(&crate::custom_httpx::llm_http_handler::body_document(body)?)+ validate_inline_document(&crate::base_llm::ocr::handler::body_document(body)?)}}@@ -134,8 +134,7 @@ impl AzureAiOcrConfig {env_lookup: &(dyn Fn(&str) -> Option<String> + Sync),) -> Result<Vec<(String, String)>, Error> {Self::resolve_api_base(connection.api_base.as_deref(), env_lookup)?;- if crate::custom_httpx::http_handler::has_header(&connection.extra_headers, "authorization")- {+ if litellm_http::request::has_header(&connection.extra_headers, "authorization") {if config.azure_ad_token_provider.is_some() {super::common_utils::resolve_entra(config, env_lookup).await?;}diff --git a/litellm-rust/crates/llms/src/base_llm/ocr/document.rs b/litellm-rust/crates/llms/src/base_llm/ocr/document.rsindex 8737232a075..7ff88c6b843 100644--- a/litellm-rust/crates/llms/src/base_llm/ocr/document.rs+++ b/litellm-rust/crates/llms/src/base_llm/ocr/document.rs@@ -1,18 +1,14 @@use base64::{Engine, engine::general_purpose::STANDARD};use data_url::{DataUrl, DataUrlError, forgiving_base64::DecodeError, mime::Mime};+use litellm_http::{+ media::{DownloadPolicy, Error as MediaError, MediaFetcher},+ transport::Error as TransportError,+};use reqwest::Url;-use crate::{- base_llm::ocr::{- error::Error,- transformation::{- OCR_INLINE_MAX_BYTES, OCR_MAX_FETCH_REDIRECTS, OcrConnection, OcrDocument,- },- },- custom_httpx::{- media::{DownloadPolicy, Error as MediaError, MediaFetcher},- transport::Error as TransportError,- },+use crate::base_llm::ocr::{+ error::Error,+ transformation::{OCR_INLINE_MAX_BYTES, OCR_MAX_FETCH_REDIRECTS, OcrConnection, OcrDocument},};pub struct InlineDocument<'a>(DataUrl<'a>);@@ -196,10 +192,8 @@ mod tests {.redirect(reqwest::redirect::Policy::none()).build().unwrap();- let client = crate::custom_httpx::llm_http_handler::OcrClient::for_test(- provider_http,- document_http,- );+ let client =+ crate::base_llm::ocr::handler::OcrClient::for_test(provider_http, document_http);let converted = inline_remote_document(client.document_fetcher(),OcrDocument::ImageUrl {diff --git a/litellm-rust/crates/llms/src/base_llm/ocr/error.rs b/litellm-rust/crates/llms/src/base_llm/ocr/error.rsindex 3061a9fe2b2..9fce387beb5 100644--- a/litellm-rust/crates/llms/src/base_llm/ocr/error.rs+++ b/litellm-rust/crates/llms/src/base_llm/ocr/error.rs@@ -95,11 +95,11 @@ pub enum Error {#[error(transparent)]Auth(#[from] litellm_auth::Error),#[error(transparent)]- Transport(#[from] crate::custom_httpx::transport::Error),+ Transport(#[from] litellm_http::transport::Error),#[error(transparent)]Params(#[from] litellm_core_utils::params::Error),#[error(transparent)]- Headers(#[from] crate::custom_httpx::http_handler::HeaderError),+ Headers(#[from] litellm_http::request::HeaderError),}impl From<litellm_host::machine::MachineFault> for Error {@@ -125,9 +125,7 @@ impl Error {pub fn http_status_code(&self) -> Option<u16> {match self {Self::Provider { status, .. }- | Self::Transport(crate::custom_httpx::transport::Error::Http { status, .. }) => {- Some(*status)- }+ | Self::Transport(litellm_http::transport::Error::Http { status, .. }) => Some(*status),error if error.is_request() => Some(400),_ => None,}diff --git a/litellm-rust/crates/llms/src/custom_httpx/llm_http_handler.rs b/litellm-rust/crates/llms/src/base_llm/ocr/handler.rssimilarity index 94%rename from litellm-rust/crates/llms/src/custom_httpx/llm_http_handler.rsrename to litellm-rust/crates/llms/src/base_llm/ocr/handler.rsindex 58dc03eea2d..b6f266928b1 100644--- a/litellm-rust/crates/llms/src/custom_httpx/llm_http_handler.rs+++ b/litellm-rust/crates/llms/src/base_llm/ocr/handler.rs@@ -2,22 +2,20 @@ use bytes::{Bytes, BytesMut};use futures_util::future::BoxFuture;use litellm_auth_gcp::VertexAuth;use litellm_host::event::WireRequest;-use litellm_http::{ClientVariant, HttpClientConfig, HttpClientPool};+use litellm_http::{+ ClientVariant, HttpClientConfig, HttpClientPool,+ media::{MediaFetcher, UrlPolicy},+ request::{HeaderPolicy, execute_http_request, with_headers},+ transport,+};use serde::{Serialize, de::DeserializeOwned};use serde_json::Value;-use crate::{- base_llm::ocr::{- error::Error,- transformation::{- BaseOcrConfig, DecodedOcrResponse, LiteLLMOcrResponse, OcrDocument, OcrResponseContext,- PreparedOcrRequest, decode_request_value, decode_response,- },- },- custom_httpx::{- http_handler::{HeaderPolicy, execute_http_request, with_headers},- media::{MediaFetcher, UrlPolicy},- transport,+use crate::base_llm::ocr::{+ error::Error,+ transformation::{+ BaseOcrConfig, DecodedOcrResponse, LiteLLMOcrResponse, OcrDocument, OcrResponseContext,+ PreparedOcrRequest, decode_request_value, decode_response,},};diff --git a/litellm-rust/crates/llms/src/base_llm/ocr/mod.rs b/litellm-rust/crates/llms/src/base_llm/ocr/mod.rsindex 7194efbb203..1231633431e 100644--- a/litellm-rust/crates/llms/src/base_llm/ocr/mod.rs+++ b/litellm-rust/crates/llms/src/base_llm/ocr/mod.rs@@ -1,3 +1,4 @@pub mod document;pub mod error;+pub mod handler;pub mod transformation;diff --git a/litellm-rust/crates/llms/src/base_llm/ocr/transformation.rs b/litellm-rust/crates/llms/src/base_llm/ocr/transformation.rsindex f215546849d..be4551709a1 100644--- a/litellm-rust/crates/llms/src/base_llm/ocr/transformation.rs+++ b/litellm-rust/crates/llms/src/base_llm/ocr/transformation.rs@@ -12,11 +12,9 @@ use serde::{use serde_json::{Map, Value};use serde_with::serde_as;-use crate::{- base_llm::ocr::error::Error,- custom_httpx::llm_http_handler::{- CallHooks, OcrClient, read_response_bytes, transform_request_body,- },+use crate::base_llm::ocr::{+ error::Error,+ handler::{CallHooks, OcrClient, read_response_bytes, transform_request_body},};pub const OCR_RESPONSE_MAX_BYTES: usize = 64 * 1024 * 1024;diff --git a/litellm-rust/crates/llms/src/cohere/ocr/transformation.rs b/litellm-rust/crates/llms/src/cohere/ocr/transformation.rsindex 2528c967f41..da6cf90ffcf 100644--- a/litellm-rust/crates/llms/src/cohere/ocr/transformation.rs+++ b/litellm-rust/crates/llms/src/cohere/ocr/transformation.rs@@ -7,17 +7,15 @@ use serde::{Deserialize, Serialize};use serde_json::{Map, Value};use serde_with::serde_as;-use crate::{- base_llm::ocr::{- document::InlineDocument,- error::Error,- transformation::{- BaseOcrConfig, LiteLLMOcrResponse, OCR_INLINE_MAX_BYTES, OcrConnection, OcrDocument,- OcrPage, OcrPageImage, OcrResponseFormat, OcrUsageInfo, PreparedOcrRequest,- credential_env, decode_and_normalize_response, decode_response_value,- },+use crate::base_llm::ocr::{+ document::InlineDocument,+ error::Error,+ handler::OcrClient,+ transformation::{+ BaseOcrConfig, LiteLLMOcrResponse, OCR_INLINE_MAX_BYTES, OcrConnection, OcrDocument,+ OcrPage, OcrPageImage, OcrResponseFormat, OcrUsageInfo, PreparedOcrRequest, credential_env,+ decode_and_normalize_response, decode_response_value,},- custom_httpx::llm_http_handler::OcrClient,};const COHERE_PARSE_API_BASE: &str = "https://api.cohere.com";@@ -163,7 +161,7 @@ impl BaseOcrConfig for CohereParseConfig {}fn validate_request_body(&self, body: &Value) -> Result<(), Error> {- validate_document(&crate::custom_httpx::llm_http_handler::body_document(body)?)+ validate_document(&crate::base_llm::ocr::handler::body_document(body)?)}}@@ -173,8 +171,7 @@ impl CohereParseConfig {connection: &OcrConnection,env_lookup: &(dyn Fn(&str) -> Option<String> + Sync),) -> Result<Vec<(String, String)>, Error> {- if crate::custom_httpx::http_handler::has_header(&connection.extra_headers, "authorization")- {+ if litellm_http::request::has_header(&connection.extra_headers, "authorization") {return Ok(connection.extra_headers.clone());}let key = connectiondiff --git a/litellm-rust/crates/llms/src/custom_httpx/mod.rs b/litellm-rust/crates/llms/src/custom_httpx/mod.rsdeleted file mode 100644index 057cb796c09..00000000000--- a/litellm-rust/crates/llms/src/custom_httpx/mod.rs+++ /dev/null@@ -1,4 +0,0 @@-pub mod http_handler;-pub mod llm_http_handler;-pub mod media;-pub mod transport;diff --git a/litellm-rust/crates/llms/src/lib.rs b/litellm-rust/crates/llms/src/lib.rsindex 884fa739992..8d1bb366ed4 100644--- a/litellm-rust/crates/llms/src/lib.rs+++ b/litellm-rust/crates/llms/src/lib.rs@@ -3,7 +3,6 @@ pub mod azure_ai;pub mod base_llm;pub mod bedrock;pub mod cohere;-pub mod custom_httpx;pub mod mistral;pub mod openai;pub mod reducto;diff --git a/litellm-rust/crates/llms/src/mistral/ocr/transformation.rs b/litellm-rust/crates/llms/src/mistral/ocr/transformation.rsindex 9028f09c5ab..95658837fc3 100644--- a/litellm-rust/crates/llms/src/mistral/ocr/transformation.rs+++ b/litellm-rust/crates/llms/src/mistral/ocr/transformation.rs@@ -2,16 +2,13 @@ use litellm_core_utils::{call_arguments::CallArguments, params::OpaqueParams, uruse serde::{Deserialize, Serialize};use serde_json::Value;-use crate::{- base_llm::ocr::{- error::Error,- transformation::{- BaseOcrConfig, LiteLLMOcrResponse, OcrConnection, OcrDocument, OcrPage,- OcrResponseFormat, OcrUsageInfo, PreparedOcrRequest, credential_env,- decode_and_normalize_response,- },+use crate::base_llm::ocr::{+ error::Error,+ handler::OcrClient,+ transformation::{+ BaseOcrConfig, LiteLLMOcrResponse, OcrConnection, OcrDocument, OcrPage, OcrResponseFormat,+ OcrUsageInfo, PreparedOcrRequest, credential_env, decode_and_normalize_response,},- custom_httpx::llm_http_handler::OcrClient,};const MISTRAL_OCR_API_BASE: &str = "https://api.mistral.ai/v1";@@ -129,8 +126,7 @@ impl MistralOcrConfig {connection: &OcrConnection,env_lookup: &(dyn Fn(&str) -> Option<String> + Sync),) -> Result<Vec<(String, String)>, Error> {- if crate::custom_httpx::http_handler::has_header(&connection.extra_headers, "authorization")- {+ if litellm_http::request::has_header(&connection.extra_headers, "authorization") {return Ok(connection.extra_headers.clone());}let api_key = connectiondiff --git a/litellm-rust/crates/llms/src/reducto/ocr/transformation.rs b/litellm-rust/crates/llms/src/reducto/ocr/transformation.rsindex ec876fafb8f..740f0ced090 100644--- a/litellm-rust/crates/llms/src/reducto/ocr/transformation.rs+++ b/litellm-rust/crates/llms/src/reducto/ocr/transformation.rs@@ -8,18 +8,14 @@ use litellm_core_utils::{use serde::{Deserialize, Deserializer, Serialize};use serde_json::{Map, Value, json};-use crate::{- base_llm::ocr::{- document::InlineDocument,- error::Error,- transformation::{- BaseOcrConfig, LiteLLMOcrResponse, OCR_INLINE_MAX_BYTES, OcrConnection, OcrDocument,- OcrPage, OcrRequestContext, OcrResponseFormat, OcrUsageInfo, PreparedOcrRequest,- credential_env, decode_and_normalize_response,- },- },- custom_httpx::llm_http_handler::{- CallHooks, OcrClient, build_http_request, guardrail_document,+use crate::base_llm::ocr::{+ document::InlineDocument,+ error::Error,+ handler::{CallHooks, OcrClient, build_http_request, guardrail_document},+ transformation::{+ BaseOcrConfig, LiteLLMOcrResponse, OCR_INLINE_MAX_BYTES, OcrConnection, OcrDocument,+ OcrPage, OcrRequestContext, OcrResponseFormat, OcrUsageInfo, PreparedOcrRequest,+ credential_env, decode_and_normalize_response,},};@@ -437,7 +433,7 @@ fn resolve_headers(connection: &OcrConnection,env_lookup: &(dyn Fn(&str) -> Option<String> + Sync),) -> Result<Vec<(String, String)>, Error> {- if crate::custom_httpx::http_handler::has_header(&connection.extra_headers, "authorization") {+ if litellm_http::request::has_header(&connection.extra_headers, "authorization") {return Ok(connection.extra_headers.clone());}let api_key = connection@@ -515,25 +511,21 @@ async fn upload_bytes_async()?).multipart(reqwest::multipart::Form::new().part("file", part)).timeout(connection.timeout);- let builder = crate::custom_httpx::http_handler::with_headers(+ let builder = litellm_http::request::with_headers(builder,headers,- crate::custom_httpx::http_handler::HeaderPolicy::Except(&[- "content-type",- "content-length",- ]),+ litellm_http::request::HeaderPolicy::Except(&["content-type", "content-length"]),);- let response = crate::custom_httpx::http_handler::http_request(builder)+ let response = litellm_http::request::http_request(builder).await- .map_err(crate::custom_httpx::transport::Error::from)?;- let uploaded =- crate::custom_httpx::llm_http_handler::read_json_response::<ReductoUploadResponse>(- response,- false,- connection.max_response_bytes,- )- .await?- .data;+ .map_err(litellm_http::transport::Error::from)?;+ let uploaded = crate::base_llm::ocr::handler::read_json_response::<ReductoUploadResponse>(+ response,+ false,+ connection.max_response_bytes,+ )+ .await?+ .data;let file_id = uploaded.file_id.as_deref()diff --git a/litellm-rust/crates/llms/src/vertex_ai/ocr/deepseek_transformation.rs b/litellm-rust/crates/llms/src/vertex_ai/ocr/deepseek_transformation.rsindex 588b5243004..8009a65ff77 100644--- a/litellm-rust/crates/llms/src/vertex_ai/ocr/deepseek_transformation.rs+++ b/litellm-rust/crates/llms/src/vertex_ai/ocr/deepseek_transformation.rs@@ -4,16 +4,14 @@ use serde::{Deserialize, Serialize};use serde_json::{Map, Value};use super::transformation::VertexAiOcrConfig;-use crate::{- base_llm::ocr::{- error::Error,- transformation::{- BaseOcrConfig, LiteLLMOcrResponse, OcrDocument, OcrPage, OcrPageDimensions,- OcrPageImage, OcrRequestContext, OcrResponseFormat, OcrUsageInfo, PreparedOcrRequest,- credential_env, decode_and_normalize_response, decode_response_value,- },+use crate::base_llm::ocr::{+ error::Error,+ handler::OcrClient,+ transformation::{+ BaseOcrConfig, LiteLLMOcrResponse, OcrDocument, OcrPage, OcrPageDimensions, OcrPageImage,+ OcrRequestContext, OcrResponseFormat, OcrUsageInfo, PreparedOcrRequest, credential_env,+ decode_and_normalize_response, decode_response_value,},- custom_httpx::llm_http_handler::OcrClient,};const DEFAULT_API_BASE: &str = "https://aiplatform.googleapis.com";diff --git a/litellm-rust/crates/llms/src/vertex_ai/ocr/transformation.rs b/litellm-rust/crates/llms/src/vertex_ai/ocr/transformation.rsindex c2cb23d0010..a50e8261aa3 100644--- a/litellm-rust/crates/llms/src/vertex_ai/ocr/transformation.rs+++ b/litellm-rust/crates/llms/src/vertex_ai/ocr/transformation.rs@@ -7,12 +7,12 @@ use crate::{base_llm::ocr::{document::{inline_remote_document, validate_inline_document},error::Error,+ handler::OcrClient,transformation::{BaseOcrConfig, LiteLLMOcrResponse, OcrConnection, OcrDocument, OcrEnvironment,OcrRequestContext, OcrResponseFormat, PreparedOcrRequest, credential_env,},},- custom_httpx::llm_http_handler::OcrClient,mistral::ocr::transformation::{MistralOcrConfig, MistralOcrRequest},};@@ -112,7 +112,7 @@ impl BaseOcrConfig for VertexAiOcrConfig {}fn validate_request_body(&self, body: &Value) -> Result<(), Error> {- validate_inline_document(&crate::custom_httpx::llm_http_handler::body_document(body)?)+ validate_inline_document(&crate::base_llm::ocr::handler::body_document(body)?)}}diff --git a/litellm-rust/crates/python-bridge/src/errors.rs b/litellm-rust/crates/python-bridge/src/errors.rsindex 61c5947ed9e..19d28f76b6f 100644--- a/litellm-rust/crates/python-bridge/src/errors.rs+++ b/litellm-rust/crates/python-bridge/src/errors.rs@@ -1,7 +1,6 @@use litellm_core::{Error, audio_transcription, chat_completions, messages, responses};-use litellm_llms::{- base_llm::ocr::error::Error as OcrError, custom_httpx::transport::Error as TransportError,-};+use litellm_http::transport::Error as TransportError;+use litellm_llms::base_llm::ocr::error::Error as OcrError;use pyo3::{exceptions::{PyRuntimeError, PyValueError},prelude::*,diff --git a/litellm-rust/crates/python-bridge/src/http.rs b/litellm-rust/crates/python-bridge/src/http.rsindex 1fc3e4a60f1..7e9a5f093b4 100644--- a/litellm-rust/crates/python-bridge/src/http.rs+++ b/litellm-rust/crates/python-bridge/src/http.rs@@ -8,8 +8,8 @@ use litellm_core_utils::settings::ProcessEnvironment;use litellm_http::{HttpClientConfig, HttpClientPool, HttpSettings, HttpSettingsLayer, Resolution, SslVerify,Unsupported,+ media::{PublicDnsResolver, UrlPolicy},};-use litellm_llms::custom_httpx::media::{PublicDnsResolver, UrlPolicy};use pyo3::{prelude::*, types::PyDict};use crate::{errors::RustBridgeDeclined, python_settings::PythonSettings};diff --git a/litellm-rust/crates/python-bridge/src/routes/messages/host.rs b/litellm-rust/crates/python-bridge/src/routes/messages/host.rsindex c1b3f59df58..1a9b170f661 100644--- a/litellm-rust/crates/python-bridge/src/routes/messages/host.rs+++ b/litellm-rust/crates/python-bridge/src/routes/messages/host.rs@@ -4,7 +4,7 @@ use litellm_core::messages::{route::{Messages, MessagesCall, MessagesOp, MessagesOpResult, MessagesOutput},};use litellm_host_python::{InvokeError, RouteHost, from_py, lookup, to_py};-use litellm_llms::custom_httpx::transport::Error as TransportError;+use litellm_http::transport::Error as TransportError;use pyo3::{exceptions::{PyException, PyValueError},gc::{PyTraverseError, PyVisit},diff --git a/litellm-rust/crates/python-bridge/src/routes/ocr/errors.rs b/litellm-rust/crates/python-bridge/src/routes/ocr/errors.rsindex 0ae56efbf02..b0a6acdebfd 100644--- a/litellm-rust/crates/python-bridge/src/routes/ocr/errors.rs+++ b/litellm-rust/crates/python-bridge/src/routes/ocr/errors.rs@@ -15,10 +15,9 @@ pub(super) fn to_pyerr(error: Error) -> PyErr {body,headers,} => upstream_error(py, status, body, headers)?,- Error::Transport(litellm_llms::custom_httpx::transport::Error::Http {- status,- body,- }) => upstream_error(py, status, body, Vec::new())?,+ Error::Transport(litellm_http::transport::Error::Http { status, body }) => {+ upstream_error(py, status, body, Vec::new())?+ }Error::RequestFormat => {let error = core_error_to_pyerr(Error::RequestFormat.into());errordiff --git a/litellm-rust/crates/python-bridge/src/routes/ocr/mod.rs b/litellm-rust/crates/python-bridge/src/routes/ocr/mod.rsindex f9d7024c824..190f37d075d 100644--- a/litellm-rust/crates/python-bridge/src/routes/ocr/mod.rs+++ b/litellm-rust/crates/python-bridge/src/routes/ocr/mod.rs@@ -9,7 +9,7 @@ use host::OcrRouteHost;use litellm_auth_gcp::VertexAuth;use litellm_callbacks_legacy::{LegacySurface, PublicCall, run_legacy_call};use litellm_core::ocr::route::ocr_machine;-use litellm_llms::custom_httpx::llm_http_handler::OcrClient;+use litellm_llms::base_llm::ocr::handler::OcrClient;use pyo3::{prelude::*,types::{PyDict, PyTuple},