nav.groups.providers
ChatProvider
"The port for chat model implementations: complete, stream, capabilities."
ChatProvider
The port for chat model implementations.
ChatProvider is the trait every chat model adapter implements. It is the port in the hexagonal architecture; the adapt/ layer provides the concrete adapters.
The full file is src/provider/traits.rs.
API
#[async_trait]
pub trait ChatProvider: Send + Sync {
fn id(&self) -> ProviderId;
fn capabilities(&self) -> ProviderCapabilities;
async fn complete(&self, request: ChatRequest) -> ProviderResult<ChatResponse>;
async fn stream(&self, request: ChatRequest) -> ProviderResult<ChatStream> {
Err(ProviderError::Unsupported { provider: self.id(), feature: "chat_stream".into() })
}
}
Capabilities
pub struct ProviderCapabilities {
pub chat: bool,
pub chat_stream: bool,
pub tool_calls: bool,
pub vision: bool,
pub structured_output: bool,
pub context_overflow_retry: bool,
}
Error classification
ProviderError distinguishes retryable vs. non-retryable failures:
- Retryable:
RateLimited,Timeout,Overloaded,Transport - Non-retryable:
Authentication,Unsupported,BadRequest,Decode
The is_retryable() and is_context_overflow() methods on ProviderError are what ModelRouter uses to decide whether to retry or fall back.
See also
- EmbeddingProvider — the embedding port.
- ProviderRegistry — the routing layer.
- OpenAI Adapter — the concrete implementation.