liteforge
LiteForge is a Rust SDK providing a unified interface for LLM completions, streaming, tool calling, RAG, agents, guardrails, MCP, observability, and more, all through an OpenAI-compatible API.
Part of the liteforge workspace. For Python bindings see
liteforge-py, for JS/TS seeliteforge-js, for the CLI seeforge-cli.
Add to Your Project
[]
= "0.2"
Or for local workspace development:
[]
= { = "../liteforge" }
Quick Start
Synchronous
use ;
let client = new; // reads LITEFORGE_API_KEY from env
let response = client.complete.unwrap;
println!;
Asynchronous
use ;
async
Streaming
use StreamExt;
use ;
async
Module Reference
All modules are public and their key types are re-exported at the crate root for convenience.
| Module | Key Types | Description |
|---|---|---|
client |
ForgeClient, AsyncForgeClient, ForgeClientBuilder |
Sync and async LLM clients |
config |
ForgeConfig, ForgeConfigBuilder |
Configuration from env vars or builder |
error |
ForgeError, Result<T> |
Error types with From<reqwest::Error> |
types |
Message, ChatCompletion, ChatCompletionChunk, Usage, Model, ModelList |
Core request/response types |
streaming |
parse_sse_stream, parse_sse_line |
SSE stream parsing |
tools |
Tool, FnTool, ToolRegistry, ToolExecutor, ToolResult |
Function-calling framework |
agents |
Agent, ToolCallingAgent, CodeAgent, PlanningAgent, AgentConfig |
Agent framework with memory and steps |
rag |
VectorIndex, RagPipeline, RagPipelineBuilder, EmbeddedDocument |
Retrieval-augmented generation |
knowledge |
KnowledgeClient, LocalKnowledgeBackend, Document, SearchResult |
Document storage and retrieval |
chunking |
chunk, Chunk, ChunkingStrategy |
Text splitting (fixed, recursive, sentence, paragraph) |
guardrails |
detect_pii, detect_injection, redact_pii, check_all, GuardrailResult |
PII detection/redaction and injection detection |
mcp |
McpConfig, McpServerManager, McpStdioServer, McpSseServer, McpHttpServer |
Model Context Protocol client |
skills |
Skill, PromptSkill, SkillRegistry, SkillComposer |
Composable prompt-based skills |
prompts |
PromptTemplate, PromptLibrary, PromptBuilder, CommonPrompts |
Template engine and prompt libraries |
pipelines |
Pipeline, PipelineBuilder, LlmStep, TransformStep, BranchStep |
Multi-step processing pipelines |
orchestration |
AgentOrchestrator, IntentRouter, Workflow, WorkflowExecutor, Session |
Multi-agent orchestration |
conversation |
ManagedConversation, CompactingConversation, ConversationConfig |
Context window management |
hitl |
ApprovalRequest, ApprovalResult, RiskBasedHandler, RiskLevel |
Human-in-the-loop approval |
observability |
Tracer, Span, SpanBuilder, MetricsCollector, MetricsSnapshot |
Distributed tracing and metrics |
events |
EventBus, Event, EventType, Subscription |
Pub/sub event system |
hooks |
Hook, HookManager, HookContext, HookResult |
Lifecycle hook system |
evals |
Evaluator, EvalSuite, TestCase, ExactMatchEvaluator, SimilarityEvaluator |
Evaluation framework |
images |
generate_image, edit_image, ImageRequest, ImageResponse, ImageSize |
Image generation and editing |
automation |
AutomationRunner, AutomationBuilder, PromptTask, AutomationConfig |
Scheduled task automation |
scheduler |
Job, JobBuilder, CronSchedule, IntervalSchedule, OnceSchedule |
Job scheduling |
triggers |
Trigger, WebhookTrigger, FileWatchTrigger, QueueTrigger, ScheduleTrigger, TriggerManager |
Event-driven execution |
retry |
RetryConfig, with_retry, with_retry_async, is_retryable |
Exponential backoff with jitter |
Key Types
ForgeClient / AsyncForgeClient
Both clients are created with ::new() (reads env vars) or via the builder:
let client = builder
.api_key
.default_model
.base_url
.timeout_secs
.build;
Methods on both clients:
| Method | Description |
|---|---|
complete(messages) |
Chat completion (sync or async) |
complete_with_model(model, messages) |
Completion with explicit model |
chat_completions(request) |
Low-level request with full ChatCompletionRequest |
list_models() |
List available models |
embed(text) / embed_batch(texts) |
Generate embeddings |
model() / base_url() |
Inspect current config |
AsyncForgeClient also provides:
| Method | Description |
|---|---|
complete_stream(messages) |
Returns Stream<Item = Result<ChatCompletionChunk>> |
chat_completions_stream(request) |
Streaming with full request |
ForgeError
All errors are variants of ForgeError:
| Variant | Description |
|---|---|
Authentication |
Missing or invalid API key |
RateLimit |
429 Too Many Requests |
InvalidRequest |
400 Bad Request |
Server |
5xx server error |
Network |
Connection failure |
Timeout |
Request timed out |
Stream |
SSE stream error |
ModelNotFound |
Requested model unavailable |
Json |
Serialization/deserialization error |
Config |
Configuration error |
Internal |
Internal SDK error |
Tool Calling
use json;
use ;
let weather = new;
let mut registry = new;
registry.register;
let definitions = registry.definitions; // pass to LLM API
let executor = new;
let result = executor.execute;
You can also implement the Tool trait directly for custom tools:
use Tool;
;
Agents
use ;
let config = new
.with_system_prompt
.with_model
.with_max_steps
.with_tool
.with_tool;
let registry = new;
let agent = new;
Agent types:
| Type | Description |
|---|---|
ToolCallingAgent |
Executes tool calls in a loop until the LLM stops requesting tools |
CodeAgent |
Specialized for code generation and execution with sandboxing |
PlanningAgent |
Creates a plan and executes steps sequentially |
RAG Pipeline
use ;
let client = new;
// Build and populate a vector index
let mut index = new;
index.add;
// Build a RAG pipeline
let pipeline = new
.top_k
.build;
Guardrails
use ;
assert!;
assert!;
let redacted = redact_pii;
let all_results = check_all;
Observability
use ;
let tracer = new;
let span = tracer.start_span;
// ... do work ...
let spans = tracer.drain_spans;
let metrics = new;
metrics.increment;
metrics.record_duration;
let snapshot = metrics.snapshot;
Configuration
The SDK reads configuration from environment variables:
| Variable | Description | Default |
|---|---|---|
LITEFORGE_API_KEY |
API key for authentication | Required |
OPENAI_API_KEY |
Fallback API key | - |
LITEFORGE_BASE_URL |
LiteLLM endpoint URL | LiteForge production endpoint |
LITEFORGE_DEFAULT_MODEL |
Default model | claude-haiku-4.5 |
LITEFORGE_TIMEOUT |
Request timeout in seconds | 60 |
Or configure programmatically via ForgeConfig:
use ;
let config = builder
.api_key
.default_model
.timeout_secs
.build;
let client = with_config;
Examples
Run any example from the workspace root:
Source code in examples/ and crates/liteforge/examples/.
Full Documentation
See the MkDocs site for complete API reference and guides.