Skip to main content

Crate llm_trait

Crate llm_trait 

Source
Expand description

§llm-trait

Trait definitions and core types for LLM providers.

This crate is the interface layer: the traits and types that both llm-unified (implementations) and consumer applications (runtimes, CLIs, servers) depend on. Depending on this crate alone is enough to accept and call a provider without pulling in any vendor adapter, the model registry, or the CLI.

It is not dependency-free: ReqwestHttpClient is the default transport, so reqwest and its TLS stack come along. That trade-off is what lets adapters be unit-tested against a mocked HttpClient without a second crate in the dependency graph.

§Architecture

┌──────────────────────────┐    ┌──────────────────────────┐
│     llm-unified          │    │     your app             │
│     (implementation)     │    │     (runtime)            │
└──────────┬───────────────┘    └──────────┬───────────────┘
           │                               │
           │  depends on                   │  depends on
           ▼                               ▼
┌──────────────────────────────────────────────────────────┐
│                    llm-trait (this crate)                 │
│  LlmProvider trait, RawAdapter trait, core types         │
└──────────────────────────────────────────────────────────┘

§Quick Start

use llm_trait::{LlmConfig, LlmProvider, ChatRequest, ChatMessage};

Re-exports§

pub use backend::Protocol;
pub use capabilities::Capabilities;
pub use capabilities::ProviderInfo;
pub use config::LlmConfig;
pub use error::LlmError;
pub use http_client::HttpClient;
pub use http_client::HttpResponse;
pub use http_client::ReqwestHttpClient;
pub use message::ChatMessage;
pub use message::ImageAttachment;
pub use message::ImageDetail;
pub use message::ToolCallMessage;
pub use provider::LlmProvider;
pub use raw_adapter::CallMode;
pub use raw_adapter::HttpMethod;
pub use raw_adapter::RawAdapter;
pub use raw_adapter::RawRequest;
pub use raw_adapter::StreamState;
pub use reasoning::ReasoningConfig;
pub use reasoning::ReasoningEffort;
pub use reasoning::ReasoningMode;
pub use reasoning::ReasoningSpec;
pub use request::ChatRequest;
pub use request::ResponseFormat;
pub use response::ChatResponse;
pub use response::ChatStream;
pub use response::FinishReason;
pub use response::StreamChunk;
pub use response::ToolCall;
pub use response::extract_tool_calls;
pub use response::parse_finish_reason;
pub use types::UsageInfo;

Modules§

backend
Protocol type definitions.
capabilities
Provider capabilities and info types.
config
Unified LLM provider configuration.
error
LLM layer unified error type.
http_client
HTTP client abstraction trait.
message
Message types for LLM conversations.
provider
The unified LLM provider trait.
raw_adapter
Raw adapter trait for low-level provider implementations.
reasoning
Reasoning/thinking configuration types.
request
Chat request types.
response
Chat response, chat stream, and stream chunk types.
types
Usage info types.