#![allow(missing_docs)]
#![warn(clippy::all)]
#[cfg(feature = "gateway")]
mod auth;
pub mod config;
pub mod core;
#[cfg(feature = "gateway")]
pub mod monitoring;
pub mod sdk; #[cfg(feature = "gateway")]
pub mod server;
pub mod services; #[cfg(feature = "gateway")]
pub mod storage;
pub mod utils;
pub mod version;
pub use config::Config;
pub use utils::error::gateway_error::{GatewayError, Result};
pub use version::{BuildInfo, GIT_HASH, VERSION, build_info, full_version};
pub use core::completion::{
Choice, CompletionOptions, CompletionResponse, ContentPart, LiteLLMError, Message, Router,
Usage, acompletion, assistant_message, completion, completion_stream, system_message,
user_message,
};
pub use core::embedding::{
EmbeddingInput, EmbeddingOptions, EmbeddingResponse, aembedding, cosine_similarity,
dot_product, embed_text, embed_texts, embed_texts_with_options, embedding, euclidean_distance,
normalize,
};
pub use core::streaming::types::{
ChatCompletionChunk, ChatCompletionChunkChoice, ChatCompletionDelta,
};
pub use core::types::message::{MessageContent, MessageRole};
pub use core::models::RequestContext;
pub use core::models::openai::{
AudioContent, AudioDelta, AudioParams, CacheControl, ChatChoice, ChatChoiceDelta,
ChatCompletionChoice, ChatCompletionRequest, ChatCompletionResponse, ChatMessage,
ChatMessageDelta, CompletionChoice, CompletionRequest, CompletionTokensDetails, ContentLogprob,
DocumentSource, EmbeddingObject, EmbeddingRequest, EmbeddingUsage, Function, FunctionCall,
FunctionCallDelta, ImageGenerationRequest, ImageGenerationResponse, ImageObject, ImageSource,
ImageUrl, Logprobs, Model, ModelListResponse, PromptTokensDetails, ResponseFormat,
StreamOptions, Tool, ToolCall, ToolCallDelta, ToolChoice, ToolChoiceFunction,
ToolChoiceFunctionSpec, TopLogprob,
};
pub use core::providers::{Provider, ProviderError, ProviderRegistry, ProviderType};
pub use core::router::{
CooldownReason, Deployment, DeploymentConfig, FallbackConfig, FallbackType, RouterConfig,
RouterError, UnifiedRouter, UnifiedRoutingStrategy as RoutingStrategy,
};
#[cfg(feature = "gateway")]
use tracing::info;
#[cfg(feature = "gateway")]
pub struct Gateway {
config: Config,
server: server::HttpServer,
}
#[cfg(feature = "gateway")]
impl Gateway {
pub async fn new(config: Config) -> Result<Self> {
info!("Creating new gateway instance");
let server = server::HttpServer::new(&config).await?;
Ok(Self { config, server })
}
fn startup_summary(&self) -> String {
let gateway = &self.config.gateway;
format!(
"server={{host:{}, port:{}, workers:{:?}}}, providers={}, features={{jwt_auth:{}, api_key_auth:{}, metrics:{}, tracing:{}, caching:{}, semantic_cache:{}, rate_limiting:{}, enterprise:{}}}",
gateway.server.host,
gateway.server.port,
gateway.server.workers,
gateway.providers.len(),
gateway.auth.enable_jwt,
gateway.auth.enable_api_key,
gateway.monitoring.metrics.enabled,
gateway.monitoring.tracing.enabled,
gateway.cache.enabled,
gateway.cache.semantic_cache,
gateway.rate_limit.enabled,
gateway.enterprise.enabled,
)
}
pub async fn run(self) -> Result<()> {
info!("Starting LiteLLM Gateway");
info!("Configuration: {}", self.startup_summary());
self.server.start().await?;
Ok(())
}
}
pub const NAME: &str = env!("CARGO_PKG_NAME");
pub const DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_build_info() {
let info = build_info();
assert!(!info.version.is_empty());
assert_eq!(info.version, VERSION);
}
#[test]
fn test_constants() {
assert_eq!(VERSION, env!("CARGO_PKG_VERSION"));
assert_eq!(NAME, env!("CARGO_PKG_NAME"));
assert_eq!(DESCRIPTION, env!("CARGO_PKG_DESCRIPTION"));
}
}