Expand description
§AI SDK Provider Specification (v3)
Provider interface specification defining trait-based contracts for AI model implementations. This crate establishes the core abstractions that enable provider-agnostic AI applications through standardized interfaces for language models, embeddings, image generation, speech synthesis, transcription, and document reranking.
§Architecture
The specification employs a trait-based design where each AI capability is represented by
a dedicated trait (e.g., LanguageModel, EmbeddingModel). Provider implementations
satisfy these traits to expose their services through a uniform API surface.
§Supported Model Types
- Language Models - Text generation, chat completion, and conversational AI
- Embedding Models - Vector representations for semantic text similarity
- Image Models - Text-to-image and image-to-image generation
- Speech Models - Text-to-speech synthesis with voice customization
- Transcription Models - Speech-to-text conversion with timestamps
- Reranking Models - Semantic document reordering by relevance
§Usage
Provider traits expose low-level do_* methods for direct model interaction and
high-level builder methods for ergonomic usage with optional parameters.
use ai_sdk_provider::{LanguageModel, CallOptions, Message, UserContentPart};
async fn generate_text<M: LanguageModel>(model: &M) {
let options = CallOptions {
prompt: vec![Message::User {
content: vec![UserContentPart::Text {
text: "Explain quantum entanglement".to_string(),
}],
}].into(),
max_output_tokens: Some(500),
temperature: Some(0.7),
..Default::default()
};
let response = model.do_generate(options).await.unwrap();
println!("Generated: {:?}", response.content);
}§Provider Implementations
Reference implementations maintained in companion crates:
ai-sdk-openai- OpenAI GPT, DALL-E, Whisper, and embeddings
§Version Compatibility
This crate implements specification version 3. Provider implementations must return “v3”
from their specification_version() method to ensure compatibility with this interface.
Re-exports§
pub use embedding_model::EmbedOptions;pub use embedding_model::EmbedResponse;pub use embedding_model::Embedding;pub use embedding_model::EmbeddingModel;pub use embedding_model::EmbeddingUsage;pub use image_model::CallWarning as ImageCallWarning;pub use image_model::ImageData;pub use image_model::ImageGenerateOptions;pub use image_model::ImageGenerateResponse;pub use image_model::ImageModel;pub use image_model::ImageProviderMetadata;pub use json_value::JsonArray;pub use json_value::JsonObject;pub use json_value::JsonValue;pub use language_model::CallOptions;pub use language_model::Content;pub use language_model::FinishReason;pub use language_model::GenerateResponse;pub use language_model::LanguageModel;pub use language_model::StreamPart;pub use language_model::StreamResponse;pub use language_model::Usage;pub use provider::ProviderV3;pub use reranking_model::Documents;pub use reranking_model::RankingItem;pub use reranking_model::RerankOptions;pub use reranking_model::RerankResponse;pub use reranking_model::RerankingModel;pub use reranking_model::ResponseInfo as RerankingResponseInfo;pub use speech_model::AudioData;pub use speech_model::CallWarning as SpeechCallWarning;pub use speech_model::SpeechGenerateOptions;pub use speech_model::SpeechGenerateResponse;pub use speech_model::SpeechModel;pub use transcription_model::AudioInput;pub use transcription_model::CallWarning as TranscriptionCallWarning;pub use transcription_model::RequestInfo as TranscriptionRequestInfo;pub use transcription_model::ResponseInfo as TranscriptionResponseInfo;pub use transcription_model::TranscriptionModel;pub use transcription_model::TranscriptionOptions;pub use transcription_model::TranscriptionResponse;pub use transcription_model::TranscriptionSegment;pub use error::Error;pub use error::Result;
Modules§
- embedding_
model - Embedding model interfaces and types for text embedding generation. Embedding Model v3 Specification Implementation
- error
- Error types used across various operations.
- image_
model - Image model interfaces and types for image generation. Image generation model provider interface and types.
- json_
value - JSON value types for provider metadata and structured data.
- language_
model - Language model interfaces and types for text generation and chat completion. Language Model v3 specification types
- provider
- Provider trait for AI model factories. Provider trait for AI model factories.
- reranking_
model - Reranking model interfaces and types for document reranking. Reranking model provider interface and types.
- shared
- Shared types and utilities used across all model types.
- speech_
model - Speech model interfaces and types for text-to-speech synthesis. Speech synthesis model provider interface and types.
- transcription_
model - Transcription model interfaces and types for speech-to-text transcription. Audio transcription model provider interface and types.