pub trait Provider: Send + Sync {
// Required methods
fn id(&self) -> &'static str;
fn models(&self) -> Vec<ModelInfo>;
fn pricing(&self, model: &str) -> Option<ModelPricing>;
fn chat_completion<'life0, 'life1, 'async_trait>(
&'life0 self,
req: ChatCompletionRequest,
ctx: &'life1 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<ChatCompletionResponse, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn chat_completion_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
req: ChatCompletionRequest,
ctx: &'life1 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, Result<ChatCompletionChunk, ProviderError>>, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn fee_multiplier(&self) -> f64 { ... }
fn embeddings<'life0, 'life1, 'async_trait>(
&'life0 self,
_req: EmbeddingsRequest,
_ctx: &'life1 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<EmbeddingsResponse, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Adapters are stateless beyond their HTTP client and pricing table. All authentication, telemetry, and routing concerns live in the core layer.
Required Methods§
Sourcefn pricing(&self, model: &str) -> Option<ModelPricing>
fn pricing(&self, model: &str) -> Option<ModelPricing>
Pricing for a model. Drawn from the manually-curated data/pricing.toml
snapshot embedded at build time; rates are updated by hand, not
automatically. Returns None only when the model is absent from the
catalog — local providers should return Some with zero rates instead.
Sourcefn chat_completion<'life0, 'life1, 'async_trait>(
&'life0 self,
req: ChatCompletionRequest,
ctx: &'life1 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<ChatCompletionResponse, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn chat_completion<'life0, 'life1, 'async_trait>(
&'life0 self,
req: ChatCompletionRequest,
ctx: &'life1 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<ChatCompletionResponse, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Non-streaming chat completion.
Sourcefn chat_completion_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
req: ChatCompletionRequest,
ctx: &'life1 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, Result<ChatCompletionChunk, ProviderError>>, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn chat_completion_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
req: ChatCompletionRequest,
ctx: &'life1 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, Result<ChatCompletionChunk, ProviderError>>, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Streaming chat completion.
Provided Methods§
Sourcefn fee_multiplier(&self) -> f64
fn fee_multiplier(&self) -> f64
Multiplier applied to computed cost/baseline to account for a provider
surcharge on top of the underlying model cost (e.g. OpenRouter’s 5% BYOK
fee). Default 1.0 (no surcharge).
Sourcefn embeddings<'life0, 'life1, 'async_trait>(
&'life0 self,
_req: EmbeddingsRequest,
_ctx: &'life1 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<EmbeddingsResponse, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn embeddings<'life0, 'life1, 'async_trait>(
&'life0 self,
_req: EmbeddingsRequest,
_ctx: &'life1 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<EmbeddingsResponse, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Embeddings. Returns Unsupported if the provider doesn’t offer them.
Sourcefn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Liveness check. Should not call the provider’s pricey endpoints.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".