pub trait CompletionModel {
type Error: Error + Send + Sync + 'static;
// Required methods
fn name(&self) -> &str;
fn model(&self) -> &str;
fn chat_stream<'life0, 'async_trait>(
&'life0 self,
req: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, Result<StreamChunk, Self::Error>>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Provider-agnostic streaming completion contract.
Implementors map ChatRequest to the provider’s wire format,
open the streaming response, and translate per-chunk events into
StreamChunks. Implementations must be Send + Sync because
RetryingModel and the engine hold them
across await boundaries; the trait does not declare these
super-bounds yet — every use site adds them — but new
implementations should satisfy them.
Required Associated Types§
Sourcetype Error: Error + Send + Sync + 'static
type Error: Error + Send + Sync + 'static
Error type for the model’s transport / setup failures.
Implement crate::Retryable on it to make the model
composable with RetryingModel.
Required Methods§
Sourcefn name(&self) -> &str
fn name(&self) -> &str
Adapter family name used in telemetry, e.g. "anthropic" or
"azure-openai". Stable across model ids — changing model
name does not change this.
Sourcefn model(&self) -> &str
fn model(&self) -> &str
Model identifier this handle is bound to: Anthropic model id
("claude-sonnet-4-5"), Azure deployment name, etc. The
engine surfaces this in tracing and the JSON tracer envelope.
Sourcefn chat_stream<'life0, 'async_trait>(
&'life0 self,
req: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, Result<StreamChunk, Self::Error>>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn chat_stream<'life0, 'async_trait>(
&'life0 self,
req: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, Result<StreamChunk, Self::Error>>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Open a streaming completion. Returns a stream of
Result<StreamChunk, Self::Error> so per-chunk transport
errors can be surfaced mid-stream. Setup-time failures (auth,
schema, transport open) return the outer Err.