pub trait LanguageModel:
Send
+ Sync
+ Debug {
// Required methods
fn provider(&self) -> &str;
fn model_id(&self) -> &str;
fn do_generate<'life0, 'async_trait>(
&'life0 self,
options: CallOptions,
) -> Pin<Box<dyn Future<Output = Result<GenerateResult>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn do_stream<'life0, 'async_trait>(
&'life0 self,
options: CallOptions,
) -> Pin<Box<dyn Future<Output = Result<StreamResult>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn specification_version(&self) -> &'static str { ... }
fn supported_urls<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = SupportedUrls> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Contract every chat / completion model implements.
Mirrors LanguageModelV4. Method names keep the do_ prefix from ai-sdk
to discourage direct end-user usage; downstream llmsdk crates wrap
these into ergonomic helpers.
Required Methods§
Sourcefn do_generate<'life0, 'async_trait>(
&'life0 self,
options: CallOptions,
) -> Pin<Box<dyn Future<Output = Result<GenerateResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn do_generate<'life0, 'async_trait>(
&'life0 self,
options: CallOptions,
) -> Pin<Box<dyn Future<Output = Result<GenerateResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Run a non-streaming generation.
§Errors
Returns a crate::ProviderError when the upstream call fails,
the response is malformed, or the prompt is rejected.
Sourcefn do_stream<'life0, 'async_trait>(
&'life0 self,
options: CallOptions,
) -> Pin<Box<dyn Future<Output = Result<StreamResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn do_stream<'life0, 'async_trait>(
&'life0 self,
options: CallOptions,
) -> Pin<Box<dyn Future<Output = Result<StreamResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Run a streaming generation.
The returned stream yields StreamParts. Errors come in two flavors:
- Outer
Result::Err— the call itself failed before any data flowed. - Inner
StreamPart::Error— the stream is alive but the provider reported a recoverable issue (content filter, partial failure).
§Errors
Same conditions as Self::do_generate.
Provided Methods§
Sourcefn specification_version(&self) -> &'static str
fn specification_version(&self) -> &'static str
Specification version (currently "v4").
Mirrors LanguageModelV4.specificationVersion (ai-sdk
language-model-v4.ts). Acts as the trait-version tag for middleware
composing across versions; provider impls inherit the default.
Sourcefn supported_urls<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = SupportedUrls> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn supported_urls<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = SupportedUrls> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
URL patterns the model can ingest natively, by media type.
Returning a pattern tells the SDK not to download a matching URL before calling the model. Defaults to an empty map (no native URL support).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".