pub struct OpenRouterProvider {
pub api_key: String,
pub model: String,
pub sampling: SamplingParams,
}Expand description
Cloud chat provider backed by OpenRouter.
Why: lets callers pick OpenRouter or a local model uniformly through
the ChatProvider trait.
What: stores an API key and model id; POSTs OpenAI-compatible streaming
chat completions with bearer auth and trusty-common branding headers.
Test: shape covered by openrouter_provider_reports_metadata; the
streaming and tool-call paths are covered by integration tests in
downstream crates plus the SSE-pump unit tests in this module.
Fields§
§api_key: String§model: String§sampling: SamplingParams#3758: sampling knobs forwarded on the streaming request so a streamed turn matches the blocking path’s style/verbosity/stopping. Default (all-absent) reproduces the pre-#3758 body exactly.
Implementations§
Source§impl OpenRouterProvider
impl OpenRouterProvider
Sourcepub fn new(api_key: impl Into<String>, model: impl Into<String>) -> Self
pub fn new(api_key: impl Into<String>, model: impl Into<String>) -> Self
Construct a provider from an API key and model id.
Why: keeps callers from poking the public fields directly so the
struct can grow optional knobs without breaking call sites.
What: stores both fields verbatim.
Test: trivially exercised by openrouter_provider_reports_metadata.
Sourcepub fn with_sampling(self, sampling: SamplingParams) -> Self
pub fn with_sampling(self, sampling: SamplingParams) -> Self
Attach sampling parameters to every request this provider sends.
Why (#3758): callers that also have a blocking path must be able to send
the SAME temperature / token ceiling / stop sequences on the streaming
path, without new() growing three arguments that every existing call
site would have to spell out.
What: consuming builder; returns self with sampling replaced.
Test: sampling_params_serialize_into_request_body.
Trait Implementations§
Source§impl ChatProvider for OpenRouterProvider
impl ChatProvider for OpenRouterProvider
Source§fn chat_stream<'life0, 'async_trait>(
&'life0 self,
messages: Vec<ChatMessage>,
tools: Vec<ToolDef>,
tx: Sender<ChatEvent>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn chat_stream<'life0, 'async_trait>(
&'life0 self,
messages: Vec<ChatMessage>,
tools: Vec<ToolDef>,
tx: Sender<ChatEvent>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
tx. tools empty disables tool use.