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): extract provider translations
Yujong Lee558022c3dd0b
diff --git a/litellm-rust/Cargo.lock b/litellm-rust/Cargo.lockindex cf8a2442397..88dc837dd95 100644--- a/litellm-rust/Cargo.lock+++ b/litellm-rust/Cargo.lock@@ -2016,6 +2016,7 @@ dependencies = ["litellm-auth-azure","litellm-auth-gcp","litellm-framing",+ "litellm-providers","mime_guess","moka","rand 0.8.7",@@ -2052,6 +2053,18 @@ dependencies = ["tokio",]+[[package]]+name = "litellm-providers"+version = "0.1.0"+dependencies = [+ "litellm-auth",+ "litellm-auth-aws",+ "rstest",+ "serde",+ "serde_json",+ "thiserror 2.0.19",+]+[[package]]name = "litellm-python-bridge"version = "0.1.0"diff --git a/litellm-rust/Cargo.toml b/litellm-rust/Cargo.tomlindex a63277d2e23..33cbd4f8b12 100644--- a/litellm-rust/Cargo.toml+++ b/litellm-rust/Cargo.toml@@ -16,6 +16,7 @@ litellm-auth = { path = "crates/auth" }litellm-auth-aws = { path = "crates/auth-aws" }litellm-auth-azure = { path = "crates/auth-azure" }litellm-auth-gcp = { path = "crates/auth-gcp" }+litellm-providers = { path = "crates/providers" }litellm-cache = { path = "crates/cache" }litellm-cache-memory = { path = "crates/cache-memory" }litellm-token-counter = { path = "crates/token-counter" }diff --git a/litellm-rust/crates/core/Cargo.toml b/litellm-rust/crates/core/Cargo.tomlindex 6eacfad9fe7..7a836b4c95a 100644--- a/litellm-rust/crates/core/Cargo.toml+++ b/litellm-rust/crates/core/Cargo.toml@@ -15,6 +15,7 @@ litellm-auth.workspace = truelitellm-auth-aws.workspace = truelitellm-auth-azure.workspace = truelitellm-auth-gcp.workspace = true+litellm-providers.workspace = truelitellm-framing.workspace = truemoka.workspace = truemime_guess = "2.0.5"diff --git a/litellm-rust/crates/core/src/audio_transcription/error.rs b/litellm-rust/crates/core/src/audio_transcription/error.rsindex f9ffb12d349..ab194173b67 100644--- a/litellm-rust/crates/core/src/audio_transcription/error.rs+++ b/litellm-rust/crates/core/src/audio_transcription/error.rs@@ -24,3 +24,23 @@ pub enum Error {#[error(transparent)]Aws(#[from] litellm_auth_aws::Error),}++impl From<litellm_providers::audio_transcription::Error> for Error {+ fn from(error: litellm_providers::audio_transcription::Error) -> Self {+ match error {+ litellm_providers::audio_transcription::Error::InvalidType { expected, actual } => {+ Self::InvalidType { expected, actual }+ }+ litellm_providers::audio_transcription::Error::MissingField(field) => {+ Self::MissingField(field)+ }+ litellm_providers::audio_transcription::Error::InvalidRequest(message) => {+ Self::InvalidRequest(message)+ }+ litellm_providers::audio_transcription::Error::InvalidResponse(message) => {+ Self::InvalidResponse(message)+ }+ litellm_providers::audio_transcription::Error::Auth(error) => Self::Auth(error),+ }+ }+}diff --git a/litellm-rust/crates/core/src/audio_transcription/mod.rs b/litellm-rust/crates/core/src/audio_transcription/mod.rsindex fafc29a2d2a..b71e8d38b8a 100644--- a/litellm-rust/crates/core/src/audio_transcription/mod.rs+++ b/litellm-rust/crates/core/src/audio_transcription/mod.rs@@ -3,7 +3,7 @@ pub use error::Error;mod client;mod handler;mod prepare;-pub mod types;+pub use litellm_providers::audio_transcription::types;pub use handler::execute_audio_transcription_provider_call;pub use prepare::prepare_audio_transcription_provider_call;diff --git a/litellm-rust/crates/core/src/chat_completions/error.rs b/litellm-rust/crates/core/src/chat_completions/error.rsindex f9ffb12d349..95da97125d7 100644--- a/litellm-rust/crates/core/src/chat_completions/error.rs+++ b/litellm-rust/crates/core/src/chat_completions/error.rs@@ -24,3 +24,19 @@ pub enum Error {#[error(transparent)]Aws(#[from] litellm_auth_aws::Error),}++impl From<litellm_providers::chat::Error> for Error {+ fn from(error: litellm_providers::chat::Error) -> Self {+ match error {+ litellm_providers::chat::Error::MissingField(field) => Self::MissingField(field),+ litellm_providers::chat::Error::InvalidRequest(message) => {+ Self::InvalidRequest(message)+ }+ litellm_providers::chat::Error::InvalidResponse(message) => {+ Self::InvalidResponse(message)+ }+ litellm_providers::chat::Error::Unsupported(reason) => Self::Unsupported(reason),+ litellm_providers::chat::Error::Auth(error) => Self::Auth(error),+ }+ }+}diff --git a/litellm-rust/crates/core/src/chat_completions/handler.rs b/litellm-rust/crates/core/src/chat_completions/handler.rsindex 5090d481f6f..2dc44e3bb26 100644--- a/litellm-rust/crates/core/src/chat_completions/handler.rs+++ b/litellm-rust/crates/core/src/chat_completions/handler.rs@@ -59,6 +59,7 @@ pub(super) async fn execute_chat_completions_provider_call(request.config.transform_response(&request.model, ProviderChatResponseData { body })+ .map_err(Error::from).map_err(as_response_error)}diff --git a/litellm-rust/crates/core/src/chat_completions/mod.rs b/litellm-rust/crates/core/src/chat_completions/mod.rsindex 5f7448bf73a..2215e1d9c5b 100644--- a/litellm-rust/crates/core/src/chat_completions/mod.rs+++ b/litellm-rust/crates/core/src/chat_completions/mod.rs@@ -10,12 +10,11 @@ mod error;pub use error::Error;mod client;mod common_utils;-pub mod conversation;+pub use litellm_providers::chat::{conversation, response_utils};pub(crate) mod handler;mod prepare;-pub mod response_utils;pub mod streaming;-pub mod types;+pub use litellm_providers::chat::types;use handler::execute_chat_completions_provider_call;use prepare::{parse_messages, resolve_provider_config, resolve_request};diff --git a/litellm-rust/crates/core/src/litellm_core_utils/get_llm_provider_logic.rs b/litellm-rust/crates/core/src/litellm_core_utils/get_llm_provider_logic.rsindex 6333eedebfc..5958e8ac613 100644--- a/litellm-rust/crates/core/src/litellm_core_utils/get_llm_provider_logic.rs+++ b/litellm-rust/crates/core/src/litellm_core_utils/get_llm_provider_logic.rs@@ -1,36 +1,4 @@-#[derive(Debug, Clone, Copy, PartialEq, Eq)]-pub struct CustomLlmProvider<'a> {- pub model: &'a str,- pub custom_llm_provider: &'a str,-}--pub fn get_custom_llm_provider<'a>(- model: &'a str,- custom_llm_provider: Option<&'a str>,-) -> Option<CustomLlmProvider<'a>> {- if let Some(custom_llm_provider) = custom_llm_provider.filter(|provider| !provider.is_empty()) {- return Some(CustomLlmProvider {- model: strip_custom_llm_provider_prefix(model, custom_llm_provider),- custom_llm_provider,- });- }-- let (custom_llm_provider, model) = model.split_once('/')?;- if custom_llm_provider.is_empty() || model.is_empty() {- return None;- }- Some(CustomLlmProvider {- model,- custom_llm_provider,- })-}--fn strip_custom_llm_provider_prefix<'a>(model: &'a str, custom_llm_provider: &str) -> &'a str {- model- .strip_prefix(custom_llm_provider)- .and_then(|model| model.strip_prefix('/'))- .unwrap_or(model)-}+pub use litellm_providers::provider_resolution::{CustomLlmProvider, get_custom_llm_provider};#[cfg(test)]mod tests {diff --git a/litellm-rust/crates/core/src/llms/anthropic/chat/mod.rs b/litellm-rust/crates/core/src/llms/anthropic/chat/mod.rsindex fa7df180f50..d80931444d9 100644--- a/litellm-rust/crates/core/src/llms/anthropic/chat/mod.rs+++ b/litellm-rust/crates/core/src/llms/anthropic/chat/mod.rs@@ -1,2 +1,2 @@pub mod streaming;-pub mod transformation;+pub use litellm_providers::anthropic::chat::transformation;diff --git a/litellm-rust/crates/core/src/llms/anthropic/experimental_pass_through/messages/mod.rs b/litellm-rust/crates/core/src/llms/anthropic/experimental_pass_through/messages/mod.rsindex 3b1da7dc069..3029d60823e 100644--- a/litellm-rust/crates/core/src/llms/anthropic/experimental_pass_through/messages/mod.rs+++ b/litellm-rust/crates/core/src/llms/anthropic/experimental_pass_through/messages/mod.rs@@ -1,4 +1,4 @@pub mod batches;pub mod count_tokens;pub mod streaming;-pub mod transformation;+pub use litellm_providers::anthropic::experimental_pass_through::messages::transformation;diff --git a/litellm-rust/crates/core/src/llms/azure_ai/anthropic/mod.rs b/litellm-rust/crates/core/src/llms/azure_ai/anthropic/mod.rsindex eb8d16a4616..9c380f98f9f 100644--- a/litellm-rust/crates/core/src/llms/azure_ai/anthropic/mod.rs+++ b/litellm-rust/crates/core/src/llms/azure_ai/anthropic/mod.rs@@ -1 +1 @@-pub mod messages_transformation;+pub use litellm_providers::azure_ai::anthropic::messages_transformation;diff --git a/litellm-rust/crates/core/src/llms/base_llm/mod.rs b/litellm-rust/crates/core/src/llms/base_llm/mod.rsindex 5cd48a21fb6..5fa2ab21564 100644--- a/litellm-rust/crates/core/src/llms/base_llm/mod.rs+++ b/litellm-rust/crates/core/src/llms/base_llm/mod.rs@@ -1,4 +1,2 @@-pub mod anthropic_messages;-pub mod audio_transcription;-pub mod chat;+pub use litellm_providers::base_llm::{anthropic_messages, audio_transcription, chat};pub(crate) mod ocr;diff --git a/litellm-rust/crates/core/src/llms/bedrock/chat/mod.rs b/litellm-rust/crates/core/src/llms/bedrock/chat/mod.rsindex a41ad86ef49..d5668e0d03b 100644--- a/litellm-rust/crates/core/src/llms/bedrock/chat/mod.rs+++ b/litellm-rust/crates/core/src/llms/bedrock/chat/mod.rs@@ -1 +1 @@-pub mod converse_transformation;+pub use litellm_providers::bedrock::chat::converse_transformation;diff --git a/litellm-rust/crates/core/src/llms/bedrock/mod.rs b/litellm-rust/crates/core/src/llms/bedrock/mod.rsindex 695aeb8af5e..fa281e5c50d 100644--- a/litellm-rust/crates/core/src/llms/bedrock/mod.rs+++ b/litellm-rust/crates/core/src/llms/bedrock/mod.rs@@ -1,2 +1,2 @@-pub mod audio_transcription;+pub use litellm_providers::bedrock::audio_transcription;pub mod chat;diff --git a/litellm-rust/crates/core/src/messages/error.rs b/litellm-rust/crates/core/src/messages/error.rsindex f5e86c4850e..cdb4de4645f 100644--- a/litellm-rust/crates/core/src/messages/error.rs+++ b/litellm-rust/crates/core/src/messages/error.rs@@ -28,6 +28,22 @@ pub enum Error {InvalidBedrockBase64(String),}+impl From<litellm_providers::messages::Error> for Error {+ fn from(error: litellm_providers::messages::Error) -> Self {+ match error {+ litellm_providers::messages::Error::MissingField(field) => Self::MissingField(field),+ litellm_providers::messages::Error::InvalidRequest(message) => {+ Self::InvalidRequest(message)+ }+ litellm_providers::messages::Error::InvalidResponse(message) => {+ Self::InvalidResponse(message)+ }+ litellm_providers::messages::Error::Unsupported(reason) => Self::Unsupported(reason),+ litellm_providers::messages::Error::Auth(error) => Self::Auth(error),+ }+ }+}+impl Error {pub fn is_request(&self) -> bool {match self {diff --git a/litellm-rust/crates/core/src/messages/handler.rs b/litellm-rust/crates/core/src/messages/handler.rsindex 36d8d2f0157..e241bc56c1e 100644--- a/litellm-rust/crates/core/src/messages/handler.rs+++ b/litellm-rust/crates/core/src/messages/handler.rs@@ -40,6 +40,7 @@ pub(super) async fn execute_messages_provider_call(request.config.transform_anthropic_messages_response(&request.model, response)+ .map_err(Error::from)}pub(super) async fn execute_messages_provider_stream(diff --git a/litellm-rust/crates/core/src/messages/mod.rs b/litellm-rust/crates/core/src/messages/mod.rsindex 8f6fffcaf7f..5149c52478d 100644--- a/litellm-rust/crates/core/src/messages/mod.rs+++ b/litellm-rust/crates/core/src/messages/mod.rs@@ -13,7 +13,7 @@ mod client;mod common_utils;mod handler;mod prepare;-pub mod types;+pub use litellm_providers::messages::types;use handler::{execute_messages_provider_call, execute_messages_provider_stream};use types::{AnthropicMessagesResponse, MessagesRequest};diff --git a/litellm-rust/crates/providers/Cargo.toml b/litellm-rust/crates/providers/Cargo.tomlnew file mode 100644index 00000000000..e1c8f2c50d4--- /dev/null+++ b/litellm-rust/crates/providers/Cargo.toml@@ -0,0 +1,16 @@+[package]+name = "litellm-providers"+version = "0.1.0"+edition.workspace = true+license.workspace = true+repository.workspace = true++[dependencies]+litellm-auth.workspace = true+litellm-auth-aws.workspace = true+serde.workspace = true+serde_json.workspace = true+thiserror.workspace = true++[dev-dependencies]+rstest.workspace = truediff --git a/litellm-rust/crates/providers/src/anthropic/chat/mod.rs b/litellm-rust/crates/providers/src/anthropic/chat/mod.rsnew file mode 100644index 00000000000..f239b6921fa--- /dev/null+++ b/litellm-rust/crates/providers/src/anthropic/chat/mod.rs@@ -0,0 +1 @@+pub mod transformation;diff --git a/litellm-rust/crates/core/src/llms/anthropic/chat/tests.rs b/litellm-rust/crates/providers/src/anthropic/chat/tests.rssimilarity index 99%rename from litellm-rust/crates/core/src/llms/anthropic/chat/tests.rsrename to litellm-rust/crates/providers/src/anthropic/chat/tests.rsindex 25c2f5e49f4..18b6efb13fd 100644--- a/litellm-rust/crates/core/src/llms/anthropic/chat/tests.rs+++ b/litellm-rust/crates/providers/src/anthropic/chat/tests.rs@@ -1,7 +1,7 @@use serde_json::json;use super::*;-use crate::chat_completions::Error;+use crate::chat::Error;fn messages(value: Value) -> Vec<ChatMessage> {serde_json::from_value(value).expect("valid messages")diff --git a/litellm-rust/crates/core/src/llms/anthropic/chat/transformation.rs b/litellm-rust/crates/providers/src/anthropic/chat/transformation.rssimilarity index 94%rename from litellm-rust/crates/core/src/llms/anthropic/chat/transformation.rsrename to litellm-rust/crates/providers/src/anthropic/chat/transformation.rsindex fc48ef6d74f..5288eebbb2f 100644--- a/litellm-rust/crates/core/src/llms/anthropic/chat/transformation.rs+++ b/litellm-rust/crates/providers/src/anthropic/chat/transformation.rs@@ -1,19 +1,19 @@use serde_json::{Map, Value, json};-use crate::chat_completions::Error;-use crate::chat_completions::conversation::{Conversation, build_conversation};-use crate::chat_completions::response_utils::{finish_reason_for, unix_now, usage_from_parts};-use crate::chat_completions::types::{- ChatCompletionsChoice, ChatCompletionsChoiceMessage, ChatCompletionsResponse, ChatMessage,- ProviderChatRequestData, ProviderChatResponseData,-};-use crate::constants::ANTHROPIC_OAUTH_TOKEN_PREFIX;-use crate::llms::anthropic::experimental_pass_through::messages::transformation::{+use crate::anthropic::ANTHROPIC_OAUTH_TOKEN_PREFIX;+use crate::anthropic::experimental_pass_through::messages::transformation::{complete_anthropic_url, resolve_anthropic_api_key,};-use crate::llms::base_llm::chat::transformation::{+use crate::base_llm::chat::transformation::{BaseConfig, ChatCompletionsAuth, Unsupported, unsupported_message, unsupported_param,};+use crate::chat::Error;+use crate::chat::conversation::{Conversation, build_conversation};+use crate::chat::response_utils::{finish_reason_for, unix_now, usage_from_parts};+use crate::chat::types::{+ ChatCompletionsChoice, ChatCompletionsChoiceMessage, ChatCompletionsResponse, ChatMessage,+ ProviderChatRequestData, ProviderChatResponseData,+};/// Anthropic parameter names, post `map_openai_params`, that the Rust path can/// place verbatim in the Messages body.diff --git a/litellm-rust/crates/providers/src/anthropic/experimental_pass_through/messages/mod.rs b/litellm-rust/crates/providers/src/anthropic/experimental_pass_through/messages/mod.rsnew file mode 100644index 00000000000..f239b6921fa--- /dev/null+++ b/litellm-rust/crates/providers/src/anthropic/experimental_pass_through/messages/mod.rs@@ -0,0 +1 @@+pub mod transformation;diff --git a/litellm-rust/crates/core/src/llms/anthropic/experimental_pass_through/messages/transformation.rs b/litellm-rust/crates/providers/src/anthropic/experimental_pass_through/messages/transformation.rssimilarity index 97%rename from litellm-rust/crates/core/src/llms/anthropic/experimental_pass_through/messages/transformation.rsrename to litellm-rust/crates/providers/src/anthropic/experimental_pass_through/messages/transformation.rsindex 6a1a1613ffc..beabe440269 100644--- a/litellm-rust/crates/core/src/llms/anthropic/experimental_pass_through/messages/transformation.rs+++ b/litellm-rust/crates/providers/src/anthropic/experimental_pass_through/messages/transformation.rs@@ -1,4 +1,4 @@-use crate::llms::base_llm::anthropic_messages::transformation::BaseAnthropicMessagesConfig;+use crate::base_llm::anthropic_messages::transformation::BaseAnthropicMessagesConfig;use crate::messages::Error;const ANTHROPIC_API_KEY_ENV: &str = "ANTHROPIC_API_KEY";diff --git a/litellm-rust/crates/providers/src/anthropic/experimental_pass_through/mod.rs b/litellm-rust/crates/providers/src/anthropic/experimental_pass_through/mod.rsnew file mode 100644index 00000000000..ba63992f3cb--- /dev/null+++ b/litellm-rust/crates/providers/src/anthropic/experimental_pass_through/mod.rs@@ -0,0 +1 @@+pub mod messages;diff --git a/litellm-rust/crates/providers/src/anthropic/mod.rs b/litellm-rust/crates/providers/src/anthropic/mod.rsnew file mode 100644index 00000000000..38a59aa6e0d--- /dev/null+++ b/litellm-rust/crates/providers/src/anthropic/mod.rs@@ -0,0 +1,4 @@+pub mod chat;+pub mod experimental_pass_through;++pub const ANTHROPIC_OAUTH_TOKEN_PREFIX: &str = "sk-ant-oat";diff --git a/litellm-rust/crates/providers/src/audio_transcription/mod.rs b/litellm-rust/crates/providers/src/audio_transcription/mod.rsnew file mode 100644index 00000000000..278b049e8f9--- /dev/null+++ b/litellm-rust/crates/providers/src/audio_transcription/mod.rs@@ -0,0 +1,31 @@+use thiserror::Error;++#[derive(Clone, Debug, PartialEq, Eq, Error)]+pub enum Error {+ #[error("expected {expected}, got {actual}")]+ InvalidType {+ expected: &'static str,+ actual: &'static str,+ },+ #[error("missing required field: {0}")]+ MissingField(&'static str),+ #[error("invalid request: {0}")]+ InvalidRequest(String),+ #[error("invalid response: {0}")]+ InvalidResponse(String),+ #[error(transparent)]+ Auth(#[from] litellm_auth::Error),+}++pub fn json_type_name(value: &serde_json::Value) -> &'static str {+ match value {+ serde_json::Value::Null => "null",+ serde_json::Value::Bool(_) => "boolean",+ serde_json::Value::Number(_) => "number",+ serde_json::Value::String(_) => "string",+ serde_json::Value::Array(_) => "array",+ serde_json::Value::Object(_) => "object",+ }+}++pub mod types;diff --git a/litellm-rust/crates/core/src/audio_transcription/types.rs b/litellm-rust/crates/providers/src/audio_transcription/types.rssimilarity index 74%rename from litellm-rust/crates/core/src/audio_transcription/types.rsrename to litellm-rust/crates/providers/src/audio_transcription/types.rsindex 1ec1f224f6b..d17d5067de5 100644--- a/litellm-rust/crates/core/src/audio_transcription/types.rs+++ b/litellm-rust/crates/providers/src/audio_transcription/types.rs@@ -3,7 +3,7 @@ use std::time::Duration;use serde::{Deserialize, Serialize};use serde_json::{Map, Value};-use crate::llms::base_llm::audio_transcription::transformation::{+use crate::base_llm::audio_transcription::transformation::{AudioTranscriptionAuth, BaseAudioTranscriptionConfig,};@@ -20,15 +20,15 @@ pub struct AudioTranscriptionRequest<'a> {#[derive(Clone)]pub struct ProviderAudioTranscriptionRequest {- pub(super) model: String,- pub(super) custom_llm_provider: String,- pub(super) config: &'static dyn BaseAudioTranscriptionConfig,- pub(super) url: String,- pub(super) body: Value,- pub(super) upstream_headers: Vec<(String, String)>,- pub(super) auth: AudioTranscriptionAuth,- pub(super) optional_params: Map<String, Value>,- pub(super) timeout: Option<Duration>,+ pub model: String,+ pub custom_llm_provider: String,+ pub config: &'static dyn BaseAudioTranscriptionConfig,+ pub url: String,+ pub body: Value,+ pub upstream_headers: Vec<(String, String)>,+ pub auth: AudioTranscriptionAuth,+ pub optional_params: Map<String, Value>,+ pub timeout: Option<Duration>,}impl ProviderAudioTranscriptionRequest {diff --git a/litellm-rust/crates/core/src/llms/azure_ai/anthropic/messages_transformation.rs b/litellm-rust/crates/providers/src/azure_ai/anthropic/messages_transformation.rssimilarity index 99%rename from litellm-rust/crates/core/src/llms/azure_ai/anthropic/messages_transformation.rsrename to litellm-rust/crates/providers/src/azure_ai/anthropic/messages_transformation.rsindex feaee0375c4..a79b9038144 100644--- a/litellm-rust/crates/core/src/llms/azure_ai/anthropic/messages_transformation.rs+++ b/litellm-rust/crates/providers/src/azure_ai/anthropic/messages_transformation.rs@@ -1,9 +1,9 @@use serde_json::{Map, Value};-use crate::llms::anthropic::experimental_pass_through::messages::transformation::{+use crate::anthropic::experimental_pass_through::messages::transformation::{ANTHROPIC_MESSAGES_CONFIG, AnthropicMessagesConfig, non_empty,};-use crate::llms::base_llm::anthropic_messages::transformation::{+use crate::base_llm::anthropic_messages::transformation::{BaseAnthropicMessagesConfig, MessagesAuthStrategy,};use crate::messages::Error;diff --git a/litellm-rust/crates/providers/src/azure_ai/anthropic/mod.rs b/litellm-rust/crates/providers/src/azure_ai/anthropic/mod.rsnew file mode 100644index 00000000000..eb8d16a4616--- /dev/null+++ b/litellm-rust/crates/providers/src/azure_ai/anthropic/mod.rs@@ -0,0 +1 @@+pub mod messages_transformation;diff --git a/litellm-rust/crates/providers/src/azure_ai/mod.rs b/litellm-rust/crates/providers/src/azure_ai/mod.rsnew file mode 100644index 00000000000..e529997219e--- /dev/null+++ b/litellm-rust/crates/providers/src/azure_ai/mod.rs@@ -0,0 +1 @@+pub mod anthropic;diff --git a/litellm-rust/crates/providers/src/base_llm/anthropic_messages/mod.rs b/litellm-rust/crates/providers/src/base_llm/anthropic_messages/mod.rsnew file mode 100644index 00000000000..f239b6921fa--- /dev/null+++ b/litellm-rust/crates/providers/src/base_llm/anthropic_messages/mod.rs@@ -0,0 +1 @@+pub mod transformation;diff --git a/litellm-rust/crates/core/src/llms/base_llm/anthropic_messages/transformation.rs b/litellm-rust/crates/providers/src/base_llm/anthropic_messages/transformation.rssimilarity index 100%rename from litellm-rust/crates/core/src/llms/base_llm/anthropic_messages/transformation.rsrename to litellm-rust/crates/providers/src/base_llm/anthropic_messages/transformation.rsdiff --git a/litellm-rust/crates/providers/src/base_llm/audio_transcription/mod.rs b/litellm-rust/crates/providers/src/base_llm/audio_transcription/mod.rsnew file mode 100644index 00000000000..f239b6921fa--- /dev/null+++ b/litellm-rust/crates/providers/src/base_llm/audio_transcription/mod.rs@@ -0,0 +1 @@+pub mod transformation;diff --git a/litellm-rust/crates/core/src/llms/base_llm/audio_transcription/transformation.rs b/litellm-rust/crates/providers/src/base_llm/audio_transcription/transformation.rssimilarity index 100%rename from litellm-rust/crates/core/src/llms/base_llm/audio_transcription/transformation.rsrename to litellm-rust/crates/providers/src/base_llm/audio_transcription/transformation.rsdiff --git a/litellm-rust/crates/providers/src/base_llm/chat/mod.rs b/litellm-rust/crates/providers/src/base_llm/chat/mod.rsnew file mode 100644index 00000000000..f239b6921fa--- /dev/null+++ b/litellm-rust/crates/providers/src/base_llm/chat/mod.rs@@ -0,0 +1 @@+pub mod transformation;diff --git a/litellm-rust/crates/core/src/llms/base_llm/chat/transformation.rs b/litellm-rust/crates/providers/src/base_llm/chat/transformation.rssimilarity index 98%rename from litellm-rust/crates/core/src/llms/base_llm/chat/transformation.rsrename to litellm-rust/crates/providers/src/base_llm/chat/transformation.rsindex cb340db7326..5d81dc1a85e 100644--- a/litellm-rust/crates/core/src/llms/base_llm/chat/transformation.rs+++ b/litellm-rust/crates/providers/src/base_llm/chat/transformation.rs@@ -1,7 +1,7 @@use serde_json::{Map, Value};-use crate::chat_completions::Error;-use crate::chat_completions::types::{+use crate::chat::Error;+use crate::chat::types::{ChatCompletionsResponse, ChatMessage, ChatMessageContent, ProviderChatRequestData,ProviderChatResponseData,};diff --git a/litellm-rust/crates/providers/src/base_llm/mod.rs b/litellm-rust/crates/providers/src/base_llm/mod.rsnew file mode 100644index 00000000000..b7a1f696440--- /dev/null+++ b/litellm-rust/crates/providers/src/base_llm/mod.rs@@ -0,0 +1,3 @@+pub mod anthropic_messages;+pub mod audio_transcription;+pub mod chat;diff --git a/litellm-rust/crates/core/src/llms/bedrock/audio_transcription/mod.rs b/litellm-rust/crates/providers/src/bedrock/audio_transcription/mod.rssimilarity index 98%rename from litellm-rust/crates/core/src/llms/bedrock/audio_transcription/mod.rsrename to litellm-rust/crates/providers/src/bedrock/audio_transcription/mod.rsindex 49397e00901..7da2aa42a51 100644--- a/litellm-rust/crates/core/src/llms/bedrock/audio_transcription/mod.rs+++ b/litellm-rust/crates/providers/src/bedrock/audio_transcription/mod.rs@@ -1,11 +1,11 @@use serde_json::{Map, Value, json};use crate::audio_transcription::Error;+use crate::audio_transcription::json_type_name;use crate::audio_transcription::types::{AudioTranscriptionRequestData, AudioTranscriptionResponseData,};-use crate::http_utils::json_type_name;-use crate::llms::base_llm::audio_transcription::transformation::{+use crate::base_llm::audio_transcription::transformation::{AudioTranscriptionAuth, BaseAudioTranscriptionConfig,};use litellm_auth_aws::constants::{BEDROCK_RUNTIME_ENDPOINT_TEMPLATE, BEDROCK_SERVICE};diff --git a/litellm-rust/crates/core/src/llms/bedrock/chat/converse_transformation.rs b/litellm-rust/crates/providers/src/bedrock/chat/converse_transformation.rssimilarity index 97%rename from litellm-rust/crates/core/src/llms/bedrock/chat/converse_transformation.rsrename to litellm-rust/crates/providers/src/bedrock/chat/converse_transformation.rsindex 525bb6d7abc..85ba3be9b07 100644--- a/litellm-rust/crates/core/src/llms/bedrock/chat/converse_transformation.rs+++ b/litellm-rust/crates/providers/src/bedrock/chat/converse_transformation.rs@@ -1,16 +1,16 @@use serde_json::{Map, Value, json};-use crate::chat_completions::Error;-use crate::chat_completions::conversation::{Conversation, TurnRole, build_conversation};-use crate::chat_completions::response_utils::{finish_reason_for, unix_now, usage_from_parts};-use crate::chat_completions::types::{+use crate::base_llm::chat::transformation::{+ BaseConfig, ChatCompletionsAuth, Unsupported, unsupported_message, unsupported_param,+};+use crate::chat::Error;+use crate::chat::conversation::{Conversation, TurnRole, build_conversation};+use crate::chat::response_utils::{finish_reason_for, unix_now, usage_from_parts};+use crate::chat::types::{ChatCompletionsChoice, ChatCompletionsChoiceMessage, ChatCompletionsResponse,ChatCompletionsUsage, ChatMessage, ChatMessageContent, ProviderChatRequestData,ProviderChatResponseData,};-use crate::llms::base_llm::chat::transformation::{- BaseConfig, ChatCompletionsAuth, Unsupported, unsupported_message, unsupported_param,-};use litellm_auth_aws::constants::{AWS_BEARER_TOKEN_BEDROCK, BEDROCK_RUNTIME_ENDPOINT_TEMPLATE};use litellm_auth_aws::{bedrock_model_id_and_region, resolve_bedrock_region};diff --git a/litellm-rust/crates/providers/src/bedrock/chat/mod.rs b/litellm-rust/crates/providers/src/bedrock/chat/mod.rsnew file mode 100644index 00000000000..a41ad86ef49--- /dev/null+++ b/litellm-rust/crates/providers/src/bedrock/chat/mod.rs@@ -0,0 +1 @@+pub mod converse_transformation;diff --git a/litellm-rust/crates/core/src/llms/bedrock/chat/tests.rs b/litellm-rust/crates/providers/src/bedrock/chat/tests.rssimilarity index 99%rename from litellm-rust/crates/core/src/llms/bedrock/chat/tests.rsrename to litellm-rust/crates/providers/src/bedrock/chat/tests.rsindex ed34a46c431..cfa0c902096 100644--- a/litellm-rust/crates/core/src/llms/bedrock/chat/tests.rs+++ b/litellm-rust/crates/providers/src/bedrock/chat/tests.rs@@ -1,7 +1,7 @@use serde_json::json;use super::*;-use crate::chat_completions::Error;+use crate::chat::Error;fn messages(value: Value) -> Vec<ChatMessage> {serde_json::from_value(value).expect("valid messages")diff --git a/litellm-rust/crates/providers/src/bedrock/mod.rs b/litellm-rust/crates/providers/src/bedrock/mod.rsnew file mode 100644index 00000000000..695aeb8af5e--- /dev/null+++ b/litellm-rust/crates/providers/src/bedrock/mod.rs@@ -0,0 +1,2 @@+pub mod audio_transcription;+pub mod chat;diff --git a/litellm-rust/crates/core/src/chat_completions/conversation.rs b/litellm-rust/crates/providers/src/chat/conversation.rssimilarity index 99%rename from litellm-rust/crates/core/src/chat_completions/conversation.rsrename to litellm-rust/crates/providers/src/chat/conversation.rsindex 1f1984ed8be..587b7ea2a16 100644--- a/litellm-rust/crates/core/src/chat_completions/conversation.rs+++ b/litellm-rust/crates/providers/src/chat/conversation.rs@@ -11,7 +11,7 @@//! accepts; anything richer is declined upstream by the capability gate.use super::types::{ChatMessage, ChatMessageContent};-use crate::constants::EMPTY_TEXT_PLACEHOLDER;+use crate::chat::EMPTY_TEXT_PLACEHOLDER;#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub enum TurnRole {diff --git a/litellm-rust/crates/providers/src/chat/mod.rs b/litellm-rust/crates/providers/src/chat/mod.rsnew file mode 100644index 00000000000..93892657c75--- /dev/null+++ b/litellm-rust/crates/providers/src/chat/mod.rs@@ -0,0 +1,21 @@+use thiserror::Error;++pub const EMPTY_TEXT_PLACEHOLDER: &str = " ";++#[derive(Clone, Debug, PartialEq, Eq, Error)]+pub enum Error {+ #[error("missing required field: {0}")]+ MissingField(&'static str),+ #[error("invalid request: {0}")]+ InvalidRequest(String),+ #[error("invalid response: {0}")]+ InvalidResponse(String),+ #[error("unsupported: {0}")]+ Unsupported(&'static str),+ #[error(transparent)]+ Auth(#[from] litellm_auth::Error),+}++pub mod conversation;+pub mod response_utils;+pub mod types;diff --git a/litellm-rust/crates/core/src/chat_completions/response_utils.rs b/litellm-rust/crates/providers/src/chat/response_utils.rssimilarity index 100%rename from litellm-rust/crates/core/src/chat_completions/response_utils.rsrename to litellm-rust/crates/providers/src/chat/response_utils.rsdiff --git a/litellm-rust/crates/core/src/chat_completions/types.rs b/litellm-rust/crates/providers/src/chat/types.rssimilarity index 88%rename from litellm-rust/crates/core/src/chat_completions/types.rsrename to litellm-rust/crates/providers/src/chat/types.rsindex 48bb0b12966..d61892624cf 100644--- a/litellm-rust/crates/core/src/chat_completions/types.rs+++ b/litellm-rust/crates/providers/src/chat/types.rs@@ -3,7 +3,7 @@ use std::time::Duration;use serde::{Deserialize, Serialize};use serde_json::{Map, Value};-use crate::llms::base_llm::chat::transformation::{BaseConfig, ChatCompletionsAuth};+use crate::base_llm::chat::transformation::{BaseConfig, ChatCompletionsAuth};/// A `/chat/completions` call as it crosses into the core.///@@ -22,26 +22,26 @@ pub struct ChatCompletionsRequest<'a> {pub timeout: Option<Duration>,}-pub(super) struct ResolvedChatCompletionsRequest<'a> {- pub(super) model: String,- pub(super) config: &'static dyn BaseConfig,- pub(super) messages: Vec<ChatMessage>,- pub(super) optional_params: Map<String, Value>,- pub(super) api_key: Option<&'a str>,- pub(super) api_base: Option<&'a str>,- pub(super) extra_headers: Option<Map<String, Value>>,- pub(super) timeout: Option<Duration>,-}--pub(super) struct ProviderChatCompletionsRequest {- pub(super) model: String,- pub(super) config: &'static dyn BaseConfig,- pub(super) url: String,- pub(super) body: Value,- pub(super) upstream_headers: Vec<(String, String)>,- pub(super) auth: ChatCompletionsAuth,- pub(super) optional_params: Map<String, Value>,- pub(super) timeout: Option<Duration>,+pub struct ResolvedChatCompletionsRequest<'a> {+ pub model: String,+ pub config: &'static dyn BaseConfig,+ pub messages: Vec<ChatMessage>,+ pub optional_params: Map<String, Value>,+ pub api_key: Option<&'a str>,+ pub api_base: Option<&'a str>,+ pub extra_headers: Option<Map<String, Value>>,+ pub timeout: Option<Duration>,+}++pub struct ProviderChatCompletionsRequest {+ pub model: String,+ pub config: &'static dyn BaseConfig,+ pub url: String,+ pub body: Value,+ pub upstream_headers: Vec<(String, String)>,+ pub auth: ChatCompletionsAuth,+ pub optional_params: Map<String, Value>,+ pub timeout: Option<Duration>,}/// The provider-shaped request body a config produces. Named rather than a barediff --git a/litellm-rust/crates/providers/src/lib.rs b/litellm-rust/crates/providers/src/lib.rsnew file mode 100644index 00000000000..5d72ffffb2b--- /dev/null+++ b/litellm-rust/crates/providers/src/lib.rs@@ -0,0 +1,8 @@+pub mod anthropic;+pub mod audio_transcription;+pub mod azure_ai;+pub mod base_llm;+pub mod bedrock;+pub mod chat;+pub mod messages;+pub mod provider_resolution;diff --git a/litellm-rust/crates/providers/src/messages/mod.rs b/litellm-rust/crates/providers/src/messages/mod.rsnew file mode 100644index 00000000000..07232b36b51--- /dev/null+++ b/litellm-rust/crates/providers/src/messages/mod.rs@@ -0,0 +1,17 @@+use thiserror::Error;++#[derive(Clone, Debug, PartialEq, Eq, Error)]+pub enum Error {+ #[error("missing required field: {0}")]+ MissingField(&'static str),+ #[error("invalid request: {0}")]+ InvalidRequest(String),+ #[error("invalid response: {0}")]+ InvalidResponse(String),+ #[error("unsupported: {0}")]+ Unsupported(&'static str),+ #[error(transparent)]+ Auth(#[from] litellm_auth::Error),+}++pub mod types;diff --git a/litellm-rust/crates/core/src/messages/types.rs b/litellm-rust/crates/providers/src/messages/types.rssimilarity index 90%rename from litellm-rust/crates/core/src/messages/types.rsrename to litellm-rust/crates/providers/src/messages/types.rsindex 32cf4b29faf..ba274ab9651 100644--- a/litellm-rust/crates/core/src/messages/types.rs+++ b/litellm-rust/crates/providers/src/messages/types.rs@@ -3,7 +3,7 @@ use std::time::Duration;use serde::{Deserialize, Serialize};use serde_json::{Map, Value};-use crate::llms::base_llm::anthropic_messages::transformation::BaseAnthropicMessagesConfig;+use crate::base_llm::anthropic_messages::transformation::BaseAnthropicMessagesConfig;pub struct MessagesRequest<'a> {pub model: &'a str,@@ -15,14 +15,14 @@ pub struct MessagesRequest<'a> {pub timeout: Option<Duration>,}-pub(super) struct ProviderMessagesRequest {- pub(super) provider: String,- pub(super) model: String,- pub(super) config: &'static dyn BaseAnthropicMessagesConfig,- pub(super) url: String,- pub(super) body: Value,- pub(super) upstream_headers: Vec<(String, String)>,- pub(super) timeout: Option<Duration>,+pub struct ProviderMessagesRequest {+ pub provider: String,+ pub model: String,+ pub config: &'static dyn BaseAnthropicMessagesConfig,+ pub url: String,+ pub body: Value,+ pub upstream_headers: Vec<(String, String)>,+ pub timeout: Option<Duration>,}#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]diff --git a/litellm-rust/crates/providers/src/provider_resolution.rs b/litellm-rust/crates/providers/src/provider_resolution.rsnew file mode 100644index 00000000000..d1ada2472e9--- /dev/null+++ b/litellm-rust/crates/providers/src/provider_resolution.rs@@ -0,0 +1,33 @@+#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub struct CustomLlmProvider<'a> {+ pub model: &'a str,+ pub custom_llm_provider: &'a str,+}++pub fn get_custom_llm_provider<'a>(+ model: &'a str,+ custom_llm_provider: Option<&'a str>,+) -> Option<CustomLlmProvider<'a>> {+ if let Some(custom_llm_provider) = custom_llm_provider.filter(|provider| !provider.is_empty()) {+ return Some(CustomLlmProvider {+ model: strip_custom_llm_provider_prefix(model, custom_llm_provider),+ custom_llm_provider,+ });+ }++ let (custom_llm_provider, model) = model.split_once('/')?;+ if custom_llm_provider.is_empty() || model.is_empty() {+ return None;+ }+ Some(CustomLlmProvider {+ model,+ custom_llm_provider,+ })+}++fn strip_custom_llm_provider_prefix<'a>(model: &'a str, custom_llm_provider: &str) -> &'a str {+ model+ .strip_prefix(custom_llm_provider)+ .and_then(|model| model.strip_prefix('/'))+ .unwrap_or(model)+}