pub struct Client { /* private fields */ }Expand description
Sends decision requests. Debug isn’t derived, to keep the key out of logs.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(key: &str) -> Client
pub fn new(key: &str) -> Client
A client for OpenRouter with an API key. An empty key sends no Authorization header, for an
endpoint (see Client::with_url) that adds the key itself.
Sourcepub fn with_timeout(self, timeout: Duration) -> Client
pub fn with_timeout(self, timeout: Duration) -> Client
Gives up on a request that takes longer than timeout in all, instead of
DEFAULT_TIMEOUT. A request that timed out is not sent again: it may have been answered,
and billed, all the same.
Sourcepub fn with_http(self, http: Client) -> Client
pub fn with_http(self, http: Client) -> Client
Sends requests through http, for a proxy, other TLS roots or a shared connection pool.
The timeout is still this client’s own (Client::with_timeout).
Sourcepub fn with_url(self, url: &str) -> Client
pub fn with_url(self, url: &str) -> Client
Sends requests to url instead of OpenRouter’s decisions endpoint.
Sourcepub fn with_model(self, model: &str) -> Client
pub fn with_model(self, model: &str) -> Client
Asks model instead of DEFAULT_MODEL.
Sourcepub async fn decide<K: Into<String>>(
&self,
state: impl Serialize,
questions: impl IntoIterator<Item = (K, Question)>,
) -> Result<DecisionResponse>
pub async fn decide<K: Into<String>>( &self, state: impl Serialize, questions: impl IntoIterator<Item = (K, Question)>, ) -> Result<DecisionResponse>
Asks questions, under their ids, about state.
Sourcepub fn request<K: Into<String>>(
&self,
state: impl Serialize,
questions: impl IntoIterator<Item = (K, Question)>,
) -> Result<DecisionRequest>
pub fn request<K: Into<String>>( &self, state: impl Serialize, questions: impl IntoIterator<Item = (K, Question)>, ) -> Result<DecisionRequest>
The request Client::decide sends.
Sourcepub async fn send(&self, request: &DecisionRequest) -> Result<DecisionResponse>
pub async fn send(&self, request: &DecisionRequest) -> Result<DecisionResponse>
Sends request as it is, whatever model it names.