pub struct OpenRouterChatClient { /* private fields */ }Expand description
Process-wide OpenRouter chat client. Holds the model name so that callers
only thread the per-item prompt/schema/input through Self::complete.
Implementations§
Source§impl OpenRouterChatClient
impl OpenRouterChatClient
Sourcepub fn new(
api_key: SecretBox<String>,
model: String,
timeout_secs: u64,
) -> Result<Self, AppError>
pub fn new( api_key: SecretBox<String>, model: String, timeout_secs: u64, ) -> Result<Self, AppError>
Builds a chat client bound to model, applying timeout_secs as the
total per-request budget (wired from --openrouter-timeout). A value of
0 falls back to DEFAULT_TIMEOUT_SECS so a missing or zero flag never
degrades into reqwest`’s immediate-timeout behaviour.
Sourcepub async fn complete(
&self,
system_prompt: &str,
input_text: &str,
schema_str: &str,
max_tokens: Option<u32>,
) -> Result<(Value, f64, bool), AppError>
pub async fn complete( &self, system_prompt: &str, input_text: &str, schema_str: &str, max_tokens: Option<u32>, ) -> Result<(Value, f64, bool), AppError>
Runs a single structured-output completion.
schema_str is the JSON Schema (as a string) the model must honour
under strict: true. When input_text is empty only the system
message is sent. Returns (value, cost_usd, is_oauth) where value
is the model output parsed as JSON, cost_usd is read from
usage.cost (or 0.0 when absent), and is_oauth is always false
because OpenRouter uses an API key, not OAuth.
Auto Trait Implementations§
impl !RefUnwindSafe for OpenRouterChatClient
impl !UnwindSafe for OpenRouterChatClient
impl Freeze for OpenRouterChatClient
impl Send for OpenRouterChatClient
impl Sync for OpenRouterChatClient
impl Unpin for OpenRouterChatClient
impl UnsafeUnpin for OpenRouterChatClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more