13 releases (4 stable)
Uses new Rust 2024
| new 1.2.0 | Apr 7, 2026 |
|---|---|
| 1.1.1 | Mar 29, 2026 |
| 1.0.0 | Mar 28, 2026 |
| 1.0.0-rc.3 | Mar 27, 2026 |
#28 in HTTP client
50 downloads per month
Used in 9 crates
(7 directly)
1MB
16K
SLoC
Rust
Universal LLM API client for Rust. Access 143+ LLM providers — OpenAI, Anthropic, Groq, Mistral, and more — through a single unified interface. Async/await with Tokio, streaming via BoxStream, composable Tower middleware stack, and compile-time type safety.
Installation
Package Installation
System Requirements
- See Installation Guide for requirements
Quick Start
Basic Chat
Send a message to any provider using the provider/model prefix:
use liter_llm::{
ChatCompletionRequest, ClientConfigBuilder, DefaultClient, LlmClient,
Message, UserContent, UserMessage,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ClientConfigBuilder::new(std::env::var("OPENAI_API_KEY")?)
.build();
let client = DefaultClient::new(config, Some("openai/gpt-4o"))?;
let request = ChatCompletionRequest {
model: "openai/gpt-4o".into(),
messages: vec![Message::User(UserMessage {
content: UserContent::Text("Hello!".into()),
name: None,
})],
..Default::default()
};
let response = client.chat(request).await?;
if let Some(choice) = response.choices.first() {
println!("{}", choice.message.content.as_deref().unwrap_or(""));
}
Ok(())
}
Common Use Cases
Streaming Responses
Stream tokens in real time:
use futures::StreamExt;
use liter_llm::{
ChatCompletionRequest, ClientConfigBuilder, DefaultClient, LlmClient,
Message, UserContent, UserMessage,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ClientConfigBuilder::new(std::env::var("OPENAI_API_KEY")?)
.build();
let client = DefaultClient::new(config, Some("openai/gpt-4o"))?;
let request = ChatCompletionRequest {
model: "openai/gpt-4o".into(),
messages: vec![Message::User(UserMessage {
content: UserContent::Text("Tell me a story".into()),
name: None,
})],
..Default::default()
};
let mut stream = client.chat_stream(request).await?;
while let Some(chunk) = stream.next().await {
let chunk = chunk?;
if let Some(choice) = chunk.choices.first() {
if let Some(content) = &choice.delta.content {
print!("{content}");
}
}
}
println!();
Ok(())
}
Next Steps
- Provider Registry - Full list of supported providers
- GitHub Repository - Source, issues, and discussions
Features
Supported Providers (143+)
Route to any provider using the provider/model prefix convention:
| Provider | Example Model |
|---|---|
| OpenAI | openai/gpt-4o, openai/gpt-4o-mini |
| Anthropic | anthropic/claude-3-5-sonnet-20241022 |
| Groq | groq/llama-3.1-70b-versatile |
| Mistral | mistral/mistral-large-latest |
| Cohere | cohere/command-r-plus |
| Together AI | together/meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo |
| Fireworks | fireworks/accounts/fireworks/models/llama-v3p1-70b-instruct |
| Google Vertex | vertexai/gemini-1.5-pro |
| Amazon Bedrock | bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0 |
Key Capabilities
-
Provider Routing -- Single client for 143+ LLM providers via
provider/modelprefix -
Local LLMs — Connect to locally-hosted models via Ollama, LM Studio, vLLM, llama.cpp, and other local inference servers
-
Unified API -- Consistent
chat,chat_stream,embeddings,list_modelsinterface -
Streaming -- Real-time token streaming via
chat_stream -
Tool Calling -- Function calling and tool use across all supporting providers
-
Type Safe -- Schema-driven types compiled from JSON schemas
-
Secure -- API keys never logged or serialized, managed via environment variables
-
Observability -- Built-in OpenTelemetry with GenAI semantic conventions
-
Error Handling -- Structured errors with provider context and retry hints
Performance
Built on a compiled Rust core for speed and safety:
- Provider resolution at client construction -- zero per-request overhead
- Configurable timeouts and connection pooling
- Zero-copy streaming with SSE and AWS EventStream support
- API keys wrapped in secure memory, zeroed on drop
Provider Routing
Route to 143+ providers using the provider/model prefix convention:
openai/gpt-4o
anthropic/claude-3-5-sonnet-20241022
groq/llama-3.1-70b-versatile
mistral/mistral-large-latest
See the provider registry for the full list.
Proxy Server
liter-llm also ships as an OpenAI-compatible proxy server with Docker support:
docker run -p 4000:4000 -e LITER_LLM_MASTER_KEY=sk-your-key ghcr.io/kreuzberg-dev/liter-llm
See the proxy server documentation for configuration, CLI usage, and MCP integration.
Documentation
- Documentation -- Full docs and API reference
- GitHub Repository -- Source, issues, and discussions
- Provider Registry -- 143 supported providers
Part of kreuzberg.dev.
Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
Join our Discord community for questions and discussion.
License
MIT -- see LICENSE for details.
Dependencies
~1–24MB
~295K SLoC