LLM Kit
A unified Rust SDK for building AI-powered applications with multiple model providers. Build with type safety, async/await, and ergonomic APIs designed for the Rust ecosystem.
Status: All 12 providers standardized with comprehensive documentation and examples. Ready for production use.
Features
- Unified Interface: Single API for all providers - write once, switch providers easily
- Multiple Providers: 12 standardized providers including OpenAI, Anthropic, Azure, Groq, DeepSeek, and more
- Builder Pattern APIs: Ergonomic, fluent APIs for all operations
- Type Safety: Leverages Rust's type system for compile-time safety
- Async/Await: Built on Tokio for efficient async operations
- Streaming Support: Real-time streaming with callbacks and transforms
- Tool Calling: Dynamic and type-safe tool integration for function calling
- Multi-step Execution: Automatic tool execution with multiple reasoning steps
- Agent System: Reusable AI agents with persistent configuration
- Storage Integration: Persistent conversation history with automatic loading
- Multiple Capabilities: Text generation, embeddings, images, speech, transcription, reranking
Quick Start
Installation
Add the core library and a provider to your Cargo.toml:
[]
= "0.1"
= "0.1" # Or any other provider
= { = "1", = ["full"] }
Basic Example
use ;
use OpenAIClient;
async
Supported Providers
All providers follow the same standardized builder pattern and API:
| Provider | Chat | Embed | Image | Speech | Transcription | Reranking | Status |
|---|---|---|---|---|---|---|---|
| OpenAI | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ Standardized |
| Anthropic | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ Standardized |
| Azure | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ Standardized |
| Groq | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ Standardized |
| DeepSeek | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ Standardized |
| xAI | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ Standardized |
| TogetherAI | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ Standardized |
| Baseten | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ Standardized |
| Hugging Face | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ Standardized |
| ElevenLabs | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ Standardized |
| AssemblyAI | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ✅ Standardized |
| OpenAI-Compatible | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ Standardized |
Legend:
- ✅ = Feature supported and implemented
- ❌ = Feature not supported by provider
Using Different Providers
All providers use the same builder pattern:
// OpenAI
use OpenAIClient;
let provider = new
.api_key
.build;
// Anthropic (Claude)
use AnthropicClient;
let provider = new
.api_key
.build;
// Azure OpenAI
use AzureClient;
let provider = new
.api_key
.resource_name
.deployment_id
.build;
// Groq (ultra-fast inference)
use GroqClient;
let provider = new
.api_key
.build;
// DeepSeek (reasoning models)
use DeepSeekClient;
let provider = new
.api_key
.build;
// And more...
Switch providers by changing just 2-3 lines of code. The rest of your application remains the same.
Core Capabilities
Text Generation
Generate text with comprehensive configuration options:
use ;
let result = new
.temperature
.max_output_tokens
.top_p
.frequency_penalty
.presence_penalty
.seed
.execute
.await?;
println!;
Streaming
Stream responses in real-time:
use ;
use StreamExt;
let result = new
.temperature
.on_chunk
.execute
.await?;
let mut stream = result.text_stream;
while let Some = stream.next.await
Tool Calling
Define tools with dynamic or type-safe APIs:
Dynamic Tools:
use ;
use ;
use json;
use Arc;
let tool = function
.with_description
.with_execute;
let mut tools = new;
tools.insert;
let result = new
.tools
.execute
.await?;
Type-Safe Tools:
use TypeSafeTool;
use JsonSchema;
use ;
Agent System
Create reusable AI agents with persistent configuration:
use ;
use AgentInterface;
// Configure agent once
let settings = new
.with_tools
.with_temperature
.with_max_output_tokens;
let agent = new;
// Use multiple times
let result1 = agent.generate?
.execute
.await?;
let result2 = agent.generate?
.temperature // Override settings per call
.execute
.await?;
// Streaming also supported
let stream_result = agent.stream?
.execute
.await?;
Conversation Storage
Persist conversation history with automatic loading:
use FilesystemStorage;
use Storage;
use Arc;
let storage: = new;
storage.initialize.await?;
let session_id = storage.generate_session_id;
// First message - no history
new
.with_storage
.with_session_id
.without_history // Important!
.execute
.await?;
// Follow-up - history loaded automatically
new
.with_storage
.with_session_id
.execute
.await?; // Previous messages included
Enable storage feature:
= { = "0.1", = ["storage"] }
= "0.1"
= "0.1"
Embeddings
Generate embeddings for single or multiple texts:
use ;
// Single embedding
let result = new
.execute
.await?;
// Batch embeddings
let texts = vec!;
let results = new
.max_parallel_calls
.execute
.await?;
Image Generation
Generate images from text prompts:
use GenerateImage;
let result = new
.n
.size
.seed
.execute
.await?;
Speech & Transcription
Convert between text and speech:
use ;
// Text to speech
let result = new
.voice
.output_format
.speed
.execute
.await?;
// Speech to text
let result = new
.execute
.await?;
Reranking
Rerank documents based on relevance:
use Rerank;
let documents = vec!;
let result = new
.top_n
.execute
.await?;
Project Structure
This is a Cargo workspace organized into layers:
Core Layer
- llm-kit-core - Core functionality with builder APIs, agent system, tool integration, and storage
- llm-kit-provider - Provider interface and traits for implementing new providers
- llm-kit-provider-utils - Shared utilities for providers
Storage Layer
- llm-kit-storage - Storage trait and types for conversation persistence
- llm-kit-storage-filesystem - Filesystem-based storage implementation
Provider Implementations
Language Model Providers:
- llm-kit-openai - OpenAI (GPT models)
- llm-kit-anthropic - Anthropic (Claude models) with extended thinking and citations
- llm-kit-deepseek - DeepSeek (reasoning models)
- llm-kit-huggingface - Hugging Face Inference API (Llama, Mistral, Qwen, and more)
- llm-kit-xai - xAI (Grok models)
Multi-Feature Providers:
- llm-kit-azure - Azure OpenAI (chat, embeddings, images)
- llm-kit-groq - Groq (ultra-fast chat, speech, transcription)
- llm-kit-togetherai - TogetherAI (chat, embeddings, images, reranking)
- llm-kit-baseten - Baseten (chat, embeddings)
- llm-kit-openai-compatible - Base for OpenAI-compatible APIs
Specialized Providers:
- llm-kit-elevenlabs - ElevenLabs (speech generation, transcription)
- llm-kit-assemblyai - AssemblyAI (transcription)
Examples
The repository includes 29 comprehensive examples demonstrating all features:
Setup
- Copy the example environment file:
- Add your API key to
.env:
OPENAI_API_KEY=your-api-key-here
Running Examples
# Set API key
# Basic Examples
# Agent Examples
# Tool Calling Examples
# Streaming Examples
# Storage Examples (require --features storage)
# Provider-Specific Examples
See the examples/ directory for all available examples.
Architecture
The SDK follows a three-layer architecture:
1. Core Layer (llm-kit-core)
Provides builder pattern APIs and core functionality:
- Builders:
GenerateText,StreamText,Embed,EmbedMany,GenerateImage,GenerateSpeech,Transcribe,Rerank - Agent System: Reusable AI agents with persistent configuration
- Tool System: Dynamic and type-safe tool integration
- Prompt Management: Standardized message types and conversions
- Storage Integration: Conversation persistence
2. Provider Layer (llm-kit-provider)
Defines traits for implementing providers:
Providertrait: Top-level provider interface- Model traits:
LanguageModel,EmbeddingModel,ImageModel,SpeechModel,TranscriptionModel,RerankingModel - Standardized types:
CallOptions,Content,FinishReason,Usage,ToolCall
3. Implementation Layer (Provider Crates)
Concrete implementations for each provider:
- API-specific request/response handling
- HTTP client management
- Format conversions
- Provider-specific features
Documentation
- Core Library Documentation - Builder APIs, agent system, tools
- Provider Implementation Guide - How to implement new providers
- Provider Standardization - Provider standardization process
- Provider Examples Guide - Required examples for each provider
- Contributing Guide - How to contribute
- Development Guide - Development workflow and tools
Provider Documentation
Each provider has comprehensive README documentation:
- OpenAI
- Anthropic
- Azure
- Groq
- DeepSeek
- xAI
- TogetherAI
- Baseten
- Hugging Face
- ElevenLabs
- AssemblyAI
- OpenAI-Compatible
Development
Prerequisites
This project uses just as a command runner:
Pre-Commit Hooks
Install pre-commit hooks for automatic code quality checks:
This automatically runs:
- ✅
rustfmt- Code formatting (auto-fixes) - ✅
clippy- Linting (blocks commit if issues found) - ✅
cargo check- Compilation verification
Available Commands
See DEVELOPMENT.md for detailed development guidelines.
Running Tests
# Run all tests
# Run tests for a specific crate
# Run with output
# Run storage tests
Building
# Build all crates
# Build in release mode
# Check without building (faster)
# Check examples
Project Status
✅ Completed
Core Functionality:
- ✅ Builder APIs:
GenerateText,StreamText,Embed,EmbedMany,GenerateImage,GenerateSpeech,Transcribe,Rerank - ✅ Agent system with persistent configuration
- ✅ Tool calling (dynamic and type-safe)
- ✅ Multi-step tool execution
- ✅ Streaming with callbacks and transforms
- ✅ Conversation storage with automatic history loading
- ✅ Message types (text, images, files, tool calls, reasoning)
- ✅ Error handling with retry logic
- ✅ Cancellation support
Providers:
- ✅ All 12 providers standardized
- ✅ Comprehensive README documentation for all providers
- ✅ 54/54 provider examples implemented (100%)
- ✅ Consistent builder pattern across all providers
- ✅ Provider-specific features documented
Testing & Documentation:
- ✅ 1,500+ unit tests across all crates
- ✅ 29 working examples in main repository
- ✅ 54 provider-specific examples
- ✅ Comprehensive documentation
🚧 Future Enhancements
- Additional storage providers (MongoDB, PostgreSQL)
- Performance optimizations
- Additional streaming transforms
- Batch processing utilities
- Rate limiting and token management
- Caching strategies
Contributing
Contributions are welcome! Please see the Contributing Guide for:
- Code style guidelines
- Pull request process
- Testing requirements
- Documentation standards
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgments
Inspired by Vercel's LLM Kit