pub trait LlmProvider: Send + Sync {
// Required methods
fn complete<'life0, 'async_trait>(
&'life0 self,
request: Request,
) -> Pin<Box<dyn Future<Output = Result<Response, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn stream<'life0, 'async_trait>(
&'life0 self,
request: Request,
) -> Pin<Box<dyn Future<Output = Result<ProviderEventStream, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Trait for LLM providers (Anthropic, OpenAI, etc.).
Implement this trait to add support for a new LLM provider.
Two API surfaces, two transports:
complete— single-shot HTTP, fully buffered response. Lowest overhead when the caller wants the final answer in one go.stream— Server-Sent Events HTTP, emits incrementalStreamEvents as the model produces them.
Implementations are independent code paths: streaming is not
derived from complete() and vice-versa. Errors that happen
before the stream begins (auth, malformed request, connection
refused) surface from the stream(...) async fn itself; errors
that surface mid-stream (parse failures, mid-body HTTP errors)
arrive as Err items inside the stream.