pub struct ClientBuilder { /* private fields */ }Expand description
A builder for Client.
Explicit options override environment variables, and environment
variables override defaults. Environment values are trimmed, and blank
values are ignored. ClientBuilder::build returns
Error::Config for a missing or invalid API key
or an invalid setting.
Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn api_key(self, api_key: impl Into<String>) -> Self
pub fn api_key(self, api_key: impl Into<String>) -> Self
Sets the API key. Else TYPESAFE_API_KEY. Required.
The key is trimmed and validated: empty keys and keys containing
whitespace, control characters, or non-ASCII characters are rejected
with Error::Config, without echoing the key.
Sourcepub fn base_url(self, base_url: impl Into<String>) -> Self
pub fn base_url(self, base_url: impl Into<String>) -> Self
Sets the base URL. Else TYPESAFE_BASE_URL, else
https://api.typesafe.ai. A trailing / is stripped.
Any base URL that implements the TypeSafe OpenAPI spec works, for example a gateway.
Sourcepub fn default_model(self, model: impl Into<String>) -> Self
pub fn default_model(self, model: impl Into<String>) -> Self
Sets the model used when a request does not specify one. Else
TYPESAFE_DEFAULT_MODEL, else jev-latest.
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Sets the per-attempt timeout, which covers connecting through reading the full response body. Defaults to 10 seconds. Must be > 0.
Sourcepub fn retry_policy(self, policy: RetryPolicy) -> Self
pub fn retry_policy(self, policy: RetryPolicy) -> Self
Sets the default retry policy. Defaults to RetryPolicy::default.
Sourcepub fn default_header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn default_header( self, name: impl Into<String>, value: impl Into<String>, ) -> Self
Adds a default header sent on every request, for gateway attribution.
SDK-owned headers (Authorization, Accept, Content-Type,
User-Agent, X-TypeSafe-SDK, X-TypeSafe-Runtime,
X-TypeSafe-Retry-Count) always take precedence over caller headers.
Sourcepub fn log_level(self, level: LogLevel) -> Self
pub fn log_level(self, level: LogLevel) -> Self
Sets the log level. Else TYPESAFE_LOG_LEVEL, else off.
Sourcepub fn http_client(self, http: Client) -> Self
pub fn http_client(self, http: Client) -> Self
Supplies a preconfigured reqwest client. One is built otherwise.