otari (Rust)
Communicate with any LLM provider through the Otari gateway.
Python SDK | Documentation | Platform (Beta)
Quickstart
Add to your Cargo.toml:
[]
= "0.1" # From crates.io (once published)
= { = "1", = ["full"] }
Or install from GitHub directly:
[]
= { = "https://github.com/mozilla-ai/otari-sdk-rust" }
= { = "1", = ["full"] }
use ;
async
Installation
Requirements
- Rust 1.83 or newer
- A running Otari gateway instance
Setting Up API Keys
Set environment variables:
Alternatively, pass the API key and base URL directly in your code:
let options = with_api_key
.api_base;
Otari Gateway
The Otari gateway is a FastAPI-based proxy server that exposes an OpenAI-compatible API and routes requests to multiple upstream LLM providers. It adds enterprise-grade features:
- Budget Management - Enforce spending limits with automatic daily, weekly, or monthly resets
- API Key Management - Issue, revoke, and monitor virtual API keys without exposing provider credentials
- Usage Analytics - Track every request with full token counts, costs, and metadata
- Multi-tenant Support - Manage access and budgets across users and teams
Quick Start
Note: You can use a specific release version instead of
latest(e.g.,1.2.0). See available versions.
Managed Platform (Beta)
Prefer a hosted experience? The Otari platform provides a managed control plane for keys, usage tracking, and cost visibility across providers, while still building on the same interfaces.
Usage
Basic Completion
use ;
let messages = vec!;
let response = completion.await?;
println!;
Switching Models
Change the model string to route to different upstream providers through the gateway:
// OpenAI via gateway
let response = completion.await?;
// Anthropic via gateway
let response = completion.await?;
Streaming
use ;
use StreamExt;
let messages = vec!;
let mut stream = completion_stream.await?;
let mut accumulator = new;
while let Some = stream.next.await
println!;
Tool Calling
use ;
use json;
let weather_tool = function
.parameters
.build;
let messages = vec!;
let options = with_api_key
.api_base
.tools
.tool_choice;
let response = completion.await?;
if let Some = &response.choices.message.tool_calls
Extended Thinking (Reasoning)
For models that support extended thinking:
use ;
let messages = vec!;
let options = with_api_key
.api_base
.reasoning_effort
.max_tokens;
let response = completion.await?;
// Access reasoning content
if let Some = &response.choices.message.reasoning
println!;
Moderation
The Otari client exposes a moderation method that calls
POST /v1/moderations and returns an OpenAI-compatible response:
use ;
# async
Only upstream providers with moderation support will succeed; others
return OtariError::Unsupported { provider, operation: "moderation" }
(or "multimodal_moderation" when the request used image parts).
Batch Operations
use ;
# async
Error Handling
use ;
match completion.await
Gateway Capabilities
The gateway supports all features through upstream providers:
| Feature | Supported |
|---|---|
| Completion | ✅ |
| Streaming | ✅ |
| Tools | ✅ |
| Images | ✅ |
| Reasoning | ✅ |
| ✅ | |
| Reranking | ✅ |
| Batch | ✅ |
| Moderation | ✅ |
Why choose otari?
- Simple, unified interface - Single function for all models, switch providers by changing the model string
- Developer friendly - Full Rust type safety with serde serialization and clear, actionable error messages
- Gateway-powered - Route to any upstream provider through a single gateway endpoint
- Async-first - Built on Tokio for high-performance async I/O
- Streaming support - Real-time token streaming with async streams
- Battle-tested - Based on the proven any-llm Python library
Development
# Build
# Run all checks
&&
# Run tests
# Run the gateway example
# Build docs
Documentation
- Full Documentation - Complete guides and API reference
- Gateway Documentation - Gateway setup and deployment
- Python SDK - The full Python SDK with direct provider access
- Otari Platform (Beta) - Hosted control plane for key management, usage tracking, and cost visibility
Contributing
We welcome contributions from developers of all skill levels! Please see our Contributing Guide or open an issue to discuss changes.
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.