pub struct LlmClientConfig {
pub api_key: String,
pub http_referer: Option<String>,
pub x_title: Option<String>,
}Expand description
Configuration for LlmClient.
Why: Separating config from the client struct makes it easy to construct the
client from different sources (env, TOML config, tests) without duplicating
the validation logic.
What: Carries the API key (mandatory), an optional HTTP-Referer, and an
optional X-Title header forwarded to OpenRouter for analytics.
Test: LlmClientConfig::from_env unit-tested in client_config_from_env.
Fields§
§api_key: StringOpenRouter API key (Bearer token).
http_referer: Option<String>Optional HTTP-Referer sent to OpenRouter for request attribution.
x_title: Option<String>Optional X-Title header sent to OpenRouter (appears in dashboards).
Implementations§
Source§impl LlmClientConfig
impl LlmClientConfig
Sourcepub fn new(api_key: impl Into<String>) -> Result<Self, LlmError>
pub fn new(api_key: impl Into<String>) -> Result<Self, LlmError>
Construct from an explicit API key string.
Why: Tests and callers that already hold the key don’t need an env read.
What: Validates that api_key is non-empty; returns MissingConfig if
it is.
Test: client_config_direct_construction.
Sourcepub fn from_env() -> Result<Self, LlmError>
pub fn from_env() -> Result<Self, LlmError>
Read the API key from the OPENROUTER_API_KEY environment variable.
Why: Binary entry points call this once at startup; library helpers
never read env variables directly (convention from CLAUDE.md).
What: Reads OPENROUTER_API_KEY; returns MissingConfig if unset or
empty.
Test: client_config_from_env_missing (key absent → error).
Sourcepub fn with_referer(self, referer: impl Into<String>) -> Self
pub fn with_referer(self, referer: impl Into<String>) -> Self
Set the optional HTTP-Referer attribution header.
Why: OpenRouter uses this for per-project analytics in their dashboard.
What: Builder-style setter; returns self for chaining.
Test: client_config_builder.
Sourcepub fn with_title(self, title: impl Into<String>) -> Self
pub fn with_title(self, title: impl Into<String>) -> Self
Set the optional X-Title attribution header.
Why: Appears in OpenRouter’s request logs as a human-readable label.
What: Builder-style setter; returns self for chaining.
Test: client_config_builder.
Trait Implementations§
Source§impl Clone for LlmClientConfig
impl Clone for LlmClientConfig
Source§fn clone(&self) -> LlmClientConfig
fn clone(&self) -> LlmClientConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for LlmClientConfig
impl RefUnwindSafe for LlmClientConfig
impl Send for LlmClientConfig
impl Sync for LlmClientConfig
impl Unpin for LlmClientConfig
impl UnsafeUnpin for LlmClientConfig
impl UnwindSafe for LlmClientConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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