Skip to main content

llmsdk_provider/
lib.rs

1//! Provider trait abstractions for llmsdk.
2//!
3//! This crate is the Rust port of [`@ai-sdk/provider`](https://github.com/vercel/ai/tree/main/packages/provider)
4//! at specification version `v4`. It defines the contract every model provider
5//! (`OpenAI`, `Anthropic`, ...) implements, plus the shared message / content /
6//! streaming types and the unified error type.
7//!
8//! The crate is intentionally minimal: no HTTP, no retry, no middleware.
9//! Those live in `llmsdk-provider-utils` and downstream provider crates.
10//!
11//! # Layout
12//!
13//! - [`language_model`]: chat / completion models with streaming.
14//! - [`embedding_model`]: vector embedding models.
15//! - [`image_model`]: image generation models.
16//! - [`video_model`]: video generation models.
17//! - [`reranking_model`]: document reranking models.
18//! - [`files_model`]: file-upload models (e.g. `Anthropic`'s `POST /files`).
19//! - [`skills_model`]: skill-upload models (`Anthropic` skills bundles).
20//! - [`middleware`]: decorators for stacking cross-cutting concerns
21//!   (retry / logging / caching) on top of any [`LanguageModel`].
22//! - [`provider`]: top-level factory returning model instances by id.
23//! - [`error`]: unified [`ProviderError`].
24//! - [`shared`]: provider options / metadata / warnings reused across models.
25//!
26//! # Example
27//!
28//! ```
29//! use llmsdk_provider::SPECIFICATION_VERSION;
30//! assert_eq!(SPECIFICATION_VERSION, "v4");
31//! ```
32//!
33//! # Stability
34//!
35//! Until 1.0, expect breaking changes; the spec version pins compatibility
36//! with the matching `@ai-sdk/provider` major.
37// Rust guideline compliant 2026-02-21
38
39#![forbid(unsafe_code)]
40#![warn(missing_docs)]
41
42pub mod embedding_model;
43pub mod error;
44pub mod files_model;
45pub mod image_model;
46pub mod json;
47pub mod language_model;
48pub mod middleware;
49pub mod provider;
50pub mod reranking_model;
51pub mod shared;
52pub mod skills_model;
53pub mod speech_model;
54pub mod transcription_model;
55pub mod video_model;
56
57// === Top-level re-exports ===
58//
59// High-frequency types are pulled to the crate root so downstream code can
60// write `use llmsdk_provider::CallOptions;` instead of
61// `use llmsdk_provider::language_model::CallOptions;`. The original
62// `pub mod` paths above remain available for callers that prefer the
63// fully qualified form.
64
65// --- Traits ---
66#[doc(inline)]
67pub use embedding_model::EmbeddingModel;
68#[doc(inline)]
69pub use files_model::FilesModel;
70#[doc(inline)]
71pub use image_model::ImageModel;
72#[doc(inline)]
73pub use language_model::LanguageModel;
74#[doc(inline)]
75pub use provider::Provider;
76#[doc(inline)]
77pub use reranking_model::RerankingModel;
78#[doc(inline)]
79pub use skills_model::SkillsModel;
80#[doc(inline)]
81pub use speech_model::SpeechModel;
82#[doc(inline)]
83pub use transcription_model::TranscriptionModel;
84#[doc(inline)]
85pub use video_model::VideoModel;
86
87// --- Error ---
88#[doc(inline)]
89pub use error::{ApiCallErrorBuilder, ProviderError, Result};
90
91// --- JSON ---
92#[doc(inline)]
93pub use json::{JsonObject, JsonSchema, JsonValue};
94
95// --- Shared ---
96#[doc(inline)]
97pub use shared::{
98    FileBytes, FileData, Headers, ProviderMetadata, ProviderOptions, ProviderReference,
99    RequestInfo, ResponseInfo, Warning,
100};
101
102// --- language_model ---
103#[doc(inline)]
104pub use language_model::{
105    AssistantPart, BoxStream, CallOptions, Content, FilePart, FinishReason, FinishReasonKind,
106    FunctionTool, GenerateResponse, GenerateResult, InputTokenUsage, Message, OutputTokenUsage,
107    Prompt, ProviderTool, ReasoningEffort, ReasoningPart, ResponseFormat, ResponseMetadata, Source,
108    StreamPart, StreamResponse, StreamResult, SupportedUrls, TextPart, Tool, ToolApprovalRequest,
109    ToolApprovalResponsePart, ToolCallPart, ToolChoice, ToolInputExample, ToolMessagePart,
110    ToolOutputPart, ToolResult, ToolResultOutput, ToolResultPart, UrlPattern, Usage, UserPart,
111};
112
113// --- embedding_model ---
114#[doc(inline)]
115pub use embedding_model::{EmbedOptions, EmbedResult, Embedding, EmbeddingUsage};
116
117// --- image_model ---
118#[doc(inline)]
119pub use image_model::{
120    GeneratedImage, ImageOptions, ImageResult, ImageUsage, ImageUsageInputDetails,
121};
122
123// --- video_model ---
124#[doc(inline)]
125pub use video_model::{VideoData, VideoFile, VideoOptions, VideoResponseInfo, VideoResult};
126
127// --- reranking_model ---
128#[doc(inline)]
129pub use reranking_model::{RankingEntry, RerankingDocuments, RerankingOptions, RerankingResult};
130
131// --- files_model ---
132#[doc(inline)]
133pub use files_model::{UploadFileData, UploadFileOptions, UploadFileResult};
134
135// --- skills_model ---
136#[doc(inline)]
137pub use skills_model::{SkillFile, UploadSkillOptions, UploadSkillResult};
138
139// --- speech_model ---
140#[doc(inline)]
141pub use speech_model::{SpeechOptions, SpeechResponseInfo, SpeechResult};
142
143// --- transcription_model ---
144#[doc(inline)]
145pub use transcription_model::{
146    TranscriptionOptions, TranscriptionResponseInfo, TranscriptionResult, TranscriptionSegment,
147};
148
149// --- provider ---
150#[doc(inline)]
151pub use provider::{DynEmbeddingModel, DynImageModel, DynLanguageModel};
152
153// --- middleware ---
154#[doc(inline)]
155pub use middleware::{
156    CacheMiddleware, CacheStore, CachedEntry, CallKind, EmbeddingModelMiddleware,
157    ImageModelMiddleware, LanguageModelMiddleware, Logger, LoggingMiddleware, MemoryCacheStore,
158    MemoryCacheStoreBuilder, MiddlewareContext, ProviderMiddlewareSet, RerankingModelMiddleware,
159    RetryMiddleware, RetryMiddlewareBuilder, StderrLogger, VideoModelMiddleware,
160    wrap_embedding_model, wrap_image_model, wrap_language_model, wrap_provider,
161    wrap_reranking_model, wrap_video_model,
162};
163
164/// Specification version this crate implements.
165///
166/// Matches `@ai-sdk/provider` v4. Providers must be wire-compatible with this
167/// spec version.
168pub const SPECIFICATION_VERSION: &str = "v4";