Skip to main content

llm_trait/
lib.rs

1//! # llm-trait
2//!
3//! Trait definitions and core types for LLM providers.
4//!
5//! This crate is the **interface layer**: the traits and types that both
6//! `llm-unified` (implementations) and consumer applications (runtimes, CLIs,
7//! servers) depend on. Depending on this crate alone is enough to accept and
8//! call a provider without pulling in any vendor adapter, the model registry,
9//! or the CLI.
10//!
11//! It is not dependency-free: [`ReqwestHttpClient`] is the default transport, so
12//! reqwest and its TLS stack come along. That trade-off is what lets adapters be
13//! unit-tested against a mocked [`HttpClient`] without a second crate in the
14//! dependency graph.
15//!
16//! ## Architecture
17//!
18//! ```text
19//! ┌──────────────────────────┐    ┌──────────────────────────┐
20//! │     llm-unified          │    │     your app             │
21//! │     (implementation)     │    │     (runtime)            │
22//! └──────────┬───────────────┘    └──────────┬───────────────┘
23//!            │                               │
24//!            │  depends on                   │  depends on
25//!            ▼                               ▼
26//! ┌──────────────────────────────────────────────────────────┐
27//! │                    llm-trait (this crate)                 │
28//! │  LlmProvider trait, RawAdapter trait, core types         │
29//! └──────────────────────────────────────────────────────────┘
30//! ```
31//!
32//! ## Quick Start
33//!
34//! ```
35//! use llm_trait::{LlmConfig, LlmProvider, ChatRequest, ChatMessage};
36//! ```
37
38pub mod backend;
39pub mod capabilities;
40pub mod config;
41pub mod error;
42pub mod http_client;
43pub mod message;
44pub mod provider;
45pub mod raw_adapter;
46pub mod reasoning;
47pub mod request;
48pub mod response;
49pub mod types;
50
51// Re-export key types at crate root for convenience.
52pub use backend::Protocol;
53pub use capabilities::{Capabilities, ProviderInfo};
54pub use config::LlmConfig;
55pub use error::LlmError;
56pub use http_client::{HttpClient, HttpResponse, ReqwestHttpClient};
57pub use message::{ChatMessage, ImageAttachment, ImageDetail, ToolCallMessage};
58pub use provider::LlmProvider;
59pub use raw_adapter::{CallMode, HttpMethod, RawAdapter, RawRequest, StreamState};
60pub use reasoning::{ReasoningConfig, ReasoningEffort, ReasoningMode, ReasoningSpec};
61pub use request::{ChatRequest, ResponseFormat};
62pub use response::{
63    ChatResponse, ChatStream, FinishReason, StreamChunk, ToolCall, extract_tool_calls,
64    parse_finish_reason,
65};
66pub use types::UsageInfo;