litellm-rust
Minimal Rust SDK port of LiteLLM (library only). Provides a unified interface for chat, embeddings, images, and video across multiple LLM providers.
Note: This project is under active development. APIs may change.
Features
- Unified client for OpenAI-compatible, Anthropic, Gemini, xAI, and Z.AI providers
- Chat completions with streaming (SSE) support
- Tool calling — model-requested function calls surfaced on
ChatResponse.tool_callsin OpenAI shape (Anthropictool_useand GeminifunctionCallnormalized through the same shape) - Text embeddings
- Image generation (OpenAI DALL-E / GPT Image)
- Video generation (Gemini Veo, OpenAI Sora)
- Model routing with
provider/modelformat - Automatic retry with exponential backoff
- Cost tracking via response headers
- Embedded model registry with pricing and context window data
- Daily model registry refreshes from LiteLLM's canonical catalog
Supported Providers
| Provider | Chat | Streaming | Embeddings | Images | Video |
|---|---|---|---|---|---|
| OpenAI-compatible | yes | yes | yes | yes | yes |
| Anthropic | yes | yes | - | - | - |
| Gemini | yes | - | - | yes | yes |
| xAI | yes | yes | - | - | - |
| Z.AI | yes | yes | - | - | - |
Installation
Prefer crates.io. The published crate is litellm-rust 0.4.0.
Or add it to your Cargo.toml:
[]
= "0.4.0"
This is a library crate (no CLI). There is no cargo install binary.
To depend on unreleased main instead of the crates.io release:
[]
= { = "https://github.com/avivsinai/litellm-rust" }
Quick Start
Astra Responses transport
Tool-enabled Astra requests use the opt-in OpenAIResponses provider kind. Keep
the existing OpenAICompatible kind for Chat Completions and for cheaper or
image models. Responses requests use max_completion_tokens (mapped to
max_output_tokens); max_tokens is rejected. Streaming function-call items
are exposed in each chunk's raw field so callers can accumulate argument
deltas and send the resulting ChatRequest tool output with its call_id.
let client = new?.with_provider;
let response = client
.completion
.await?;
use ;
async
Streaming
use StreamExt;
use ;
# async
Provider Configuration
Set API keys via environment variables:
| Variable | Provider |
|---|---|
OPENAI_API_KEY |
OpenAI |
ANTHROPIC_API_KEY |
Anthropic |
GEMINI_API_KEY |
Google Gemini |
OPENROUTER_API_KEY |
OpenRouter |
XAI_API_KEY |
xAI / Grok |
ZAI_API_KEY |
Z.AI / GLM |
Model routing uses provider/model format (e.g., openai/gpt-4o, openrouter/anthropic/claude-sonnet-4-5).
Minimum Supported Rust Version
The MSRV is Rust 1.88. This is verified in CI.
Notes
- xAI uses OpenAI-compatible endpoints. Configure provider
xaiwith base URLhttps://api.x.ai/v1andXAI_API_KEY. - Z.AI uses OpenAI-compatible endpoints. The built-in
zairoute useshttps://api.z.ai/api/paas/v4andZAI_API_KEY. - Model IDs are passed through to providers rather than allow-listed. The embedded registry is used for pricing and context metadata and is refreshed daily by an automated pull request that merges itself once validation CI passes; failed refreshes surface as a GitHub issue and retry the next day.
- This crate intentionally excludes LiteLLM proxy/server features.
Contributing
See CONTRIBUTING.md for development setup and guidelines.
License
MIT - This project is a Rust port of LiteLLM by Berri AI (also MIT licensed).