Skip to main content

ClientBuilder

Struct ClientBuilder 

Source
pub struct ClientBuilder { /* private fields */ }
Expand description

Builder for Client.

Values set here take precedence over environment variables, then defaults. Blank environment values are ignored.

Implementations§

Source§

impl ClientBuilder

Source

pub fn api_key(self, api_key: impl Into<SecretString>) -> Self

Authenticate with a TypeSafe API key; falls back to TYPESAFE_API_KEY.

The key is held as a SecretString and wiped from memory when the client is dropped. Don’t embed an API key in software that runs on user machines; use ClientBuilder::credential_provider with your own backend instead.

Source

pub fn credential_provider(self, provider: impl CredentialProvider) -> Self

Authenticate with a bearer token from a provider, asked before every attempt.

Replaces any API key set on the builder, and the environment key is not read.

Source

pub fn credentials_fn<F, Fut, T, E>(self, provider: F) -> Self
where F: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<T, E>> + Send + 'static, T: Into<SecretString> + 'static, E: Into<BoxError> + 'static,

Authenticate with a bearer token from an async closure, asked before every attempt.

use kunobi_jev::Client;

let client = Client::builder()
    .base_url("https://jev.example.com")
    .credentials_fn(|| async { Ok::<_, std::io::Error>(String::from("short-lived-token")) })
    .build()?;
Source

pub fn base_url(self, base_url: impl Into<String>) -> Self

API root; falls back to TYPESAFE_BASE_URL, then https://api.typesafe.ai.

Must be https. Plain http is accepted only for loopback hosts, unless ClientBuilder::allow_insecure_http is set.

Source

pub fn allow_insecure_http(self, allow: bool) -> Self

Accept a plain-http base_url on any host. Credentials then travel unencrypted.

Meant for trusted private networks, such as a sidecar on the same pod.

Source

pub fn log_bodies(self, log_bodies: bool) -> Self

Include request and response bodies in debug logs. Default: off.

Bodies carry the state you send and the answers you get, which may include personal data. Headers are always logged with credentials redacted.

Source

pub fn default_model(self, model: impl Into<String>) -> Self

Default model; falls back to TYPESAFE_DEFAULT_MODEL, then jev-latest.

Source

pub fn retry(self, retry: RetryPolicy) -> Self

Retry policy; defaults to RetryPolicy::default.

Source

pub fn timeout(self, timeout: Duration) -> Self

Timeout per attempt, including the response body. Default: DEFAULT_TIMEOUT, 5 s.

A credential provider gets the same timeout. To bound a whole call, retries included, use ClientBuilder::total_timeout.

Source

pub fn total_timeout(self, total_timeout: impl Into<Option<Duration>>) -> Self

Upper bound for a whole call, including credentials, retries and backoff. Default: DEFAULT_TOTAL_TIMEOUT, 10 s.

Pass None to remove the bound and let the retry policy run to its end. Per-call Call::total_timeout takes precedence.

Source

pub fn max_concurrent_requests(self, max: usize) -> Self

Limit how many attempts this client and its clones send at once. Default: no limit.

Calls over the limit wait for a slot; the wait counts against total_timeout but not the per-attempt timeout. A slot is held for one attempt and released during retry backoff.

Source

pub fn default_header(self, name: HeaderName, value: HeaderValue) -> Self

Add a header sent with every request. Per-call headers take precedence.

Source

pub fn default_headers(self, headers: HeaderMap) -> Self

Add headers sent with every request, replacing earlier values for the same names.

Source

pub fn http_client(self, http: Client) -> Self

Use a preconfigured HTTP client, for proxies, custom TLS or tests.

Leave its own timeout unset: the client applies ClientBuilder::timeout per attempt.

Source

pub fn build(self) -> Result<Client>

Build the client.

Fails when credentials are missing or configuration is invalid.

Trait Implementations§

Source§

impl Debug for ClientBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ClientBuilder

Source§

fn default() -> ClientBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more