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
impl ClientBuilder
Sourcepub fn api_key(self, api_key: impl Into<SecretString>) -> Self
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.
Sourcepub fn credential_provider(self, provider: impl CredentialProvider) -> Self
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.
Sourcepub fn credentials_fn<F, Fut, T, E>(self, provider: F) -> Self
pub fn credentials_fn<F, Fut, T, E>(self, provider: F) -> Self
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()?;Sourcepub fn base_url(self, base_url: impl Into<String>) -> Self
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.
Sourcepub fn allow_insecure_http(self, allow: bool) -> Self
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.
Sourcepub fn log_bodies(self, log_bodies: bool) -> Self
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.
Sourcepub fn default_model(self, model: impl Into<String>) -> Self
pub fn default_model(self, model: impl Into<String>) -> Self
Default model; falls back to TYPESAFE_DEFAULT_MODEL, then jev-latest.
Sourcepub fn retry(self, retry: RetryPolicy) -> Self
pub fn retry(self, retry: RetryPolicy) -> Self
Retry policy; defaults to RetryPolicy::default.
Sourcepub fn timeout(self, timeout: Duration) -> Self
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.
Sourcepub fn total_timeout(self, total_timeout: impl Into<Option<Duration>>) -> Self
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.
Sourcepub fn max_concurrent_requests(self, max: usize) -> Self
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.
Sourcepub fn default_header(self, name: HeaderName, value: HeaderValue) -> Self
pub fn default_header(self, name: HeaderName, value: HeaderValue) -> Self
Add a header sent with every request. Per-call headers take precedence.
Sourcepub fn default_headers(self, headers: HeaderMap) -> Self
pub fn default_headers(self, headers: HeaderMap) -> Self
Add headers sent with every request, replacing earlier values for the same names.
Sourcepub fn http_client(self, http: Client) -> Self
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.