ai_sdk_provider/lib.rs
1//! # AI SDK Provider Specification (v3)
2//!
3//! Provider interface specification defining trait-based contracts for AI model implementations.
4//! This crate establishes the core abstractions that enable provider-agnostic AI applications
5//! through standardized interfaces for language models, embeddings, image generation, speech
6//! synthesis, transcription, and document reranking.
7//!
8//! ## Architecture
9//!
10//! The specification employs a trait-based design where each AI capability is represented by
11//! a dedicated trait (e.g., `LanguageModel`, `EmbeddingModel`). Provider implementations
12//! satisfy these traits to expose their services through a uniform API surface.
13//!
14//! ### Supported Model Types
15//!
16//! - **Language Models** - Text generation, chat completion, and conversational AI
17//! - **Embedding Models** - Vector representations for semantic text similarity
18//! - **Image Models** - Text-to-image and image-to-image generation
19//! - **Speech Models** - Text-to-speech synthesis with voice customization
20//! - **Transcription Models** - Speech-to-text conversion with timestamps
21//! - **Reranking Models** - Semantic document reordering by relevance
22//!
23//! ## Usage
24//!
25//! Provider traits expose low-level `do_*` methods for direct model interaction and
26//! high-level builder methods for ergonomic usage with optional parameters.
27//!
28//! ```rust,ignore
29//! use ai_sdk_provider::{LanguageModel, CallOptions, Message, UserContentPart};
30//!
31//! async fn generate_text<M: LanguageModel>(model: &M) {
32//! let options = CallOptions {
33//! prompt: vec![Message::User {
34//! content: vec![UserContentPart::Text {
35//! text: "Explain quantum entanglement".to_string(),
36//! }],
37//! }].into(),
38//! max_output_tokens: Some(500),
39//! temperature: Some(0.7),
40//! ..Default::default()
41//! };
42//!
43//! let response = model.do_generate(options).await.unwrap();
44//! println!("Generated: {:?}", response.content);
45//! }
46//! ```
47//!
48//! ## Provider Implementations
49//!
50//! Reference implementations maintained in companion crates:
51//!
52//! - [`ai-sdk-openai`] - OpenAI GPT, DALL-E, Whisper, and embeddings
53//!
54//! ## Version Compatibility
55//!
56//! This crate implements specification version 3. Provider implementations must return "v3"
57//! from their `specification_version()` method to ensure compatibility with this interface.
58//!
59//! [`ai-sdk-openai`]: https://crates.io/crates/ai-sdk-openai
60
61#![cfg_attr(docsrs, feature(doc_cfg))]
62#![warn(missing_docs)]
63#![warn(rustdoc::broken_intra_doc_links)]
64
65/// Embedding model interfaces and types for text embedding generation.
66pub mod embedding_model;
67/// Error types used across various operations.
68pub mod error;
69/// Image model interfaces and types for image generation.
70pub mod image_model;
71/// JSON value types for provider metadata and structured data.
72pub mod json_value;
73/// Language model interfaces and types for text generation and chat completion.
74pub mod language_model;
75/// Provider trait for AI model factories.
76pub mod provider;
77/// Reranking model interfaces and types for document reranking.
78pub mod reranking_model;
79/// Shared types and utilities used across all model types.
80pub mod shared;
81/// Speech model interfaces and types for text-to-speech synthesis.
82pub mod speech_model;
83/// Transcription model interfaces and types for speech-to-text transcription.
84pub mod transcription_model;
85
86// Re-export commonly used types
87pub use embedding_model::{EmbedOptions, EmbedResponse, Embedding, EmbeddingModel, EmbeddingUsage};
88pub use image_model::{
89 CallWarning as ImageCallWarning, ImageData, ImageGenerateOptions, ImageGenerateResponse,
90 ImageModel, ImageProviderMetadata,
91};
92pub use json_value::{JsonArray, JsonObject, JsonValue};
93pub use language_model::{
94 CallOptions, Content, FinishReason, GenerateResponse, LanguageModel, StreamPart,
95 StreamResponse, Usage,
96};
97pub use provider::ProviderV3;
98pub use reranking_model::{
99 Documents, RankingItem, RerankOptions, RerankResponse, RerankingModel,
100 ResponseInfo as RerankingResponseInfo,
101};
102pub use shared::{SharedHeaders, SharedProviderMetadata, SharedProviderOptions, SharedWarning};
103pub use speech_model::{
104 AudioData, CallWarning as SpeechCallWarning, SpeechGenerateOptions, SpeechGenerateResponse,
105 SpeechModel,
106};
107pub use transcription_model::{
108 AudioInput, CallWarning as TranscriptionCallWarning, RequestInfo as TranscriptionRequestInfo,
109 ResponseInfo as TranscriptionResponseInfo, TranscriptionModel, TranscriptionOptions,
110 TranscriptionResponse, TranscriptionSegment,
111};
112
113pub use error::{Error, Result};