pub struct ClientBuilder { /* private fields */ }Expand description
Builder for crate::Client.
Explicit settings take precedence over environment variables, which take precedence over SDK defaults. Empty or whitespace-only environment values are ignored.
§Example
use typesafe_sdk::ClientBuilder;
let client = ClientBuilder::new("sk-...")
.base_url("https://api.typesafe.ai")
.default_model("jev-latest")
.build()?;Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn new(api_key: impl Into<String>) -> Self
pub fn new(api_key: impl Into<String>) -> Self
Create a builder with the given API key.
Use ClientBuilder::new when you have the key; use
Client::from_env to read TYPESAFE_API_KEY
from the environment.
Sourcepub fn api_key(self, key: impl Into<String>) -> Self
pub fn api_key(self, key: impl Into<String>) -> Self
Set the API key. Overrides the TYPESAFE_API_KEY environment variable.
Sourcepub fn base_url(self, url: impl Into<String>) -> Self
pub fn base_url(self, url: impl Into<String>) -> Self
Set the API root URL. Trailing slashes are stripped.
Default: https://api.typesafe.ai.
Sourcepub fn default_model(self, model: impl Into<String>) -> Self
pub fn default_model(self, model: impl Into<String>) -> Self
Set the default model for requests that do not name one.
Default: jev-latest.
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Set the per-attempt timeout. Default: 10 seconds.
Sourcepub fn retry(self, policy: RetryPolicy) -> Self
pub fn retry(self, policy: RetryPolicy) -> Self
Set the retry policy. Default: RetryPolicy::default.
Sourcepub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
pub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
Add a header sent with every request.
Authentication, Accept, Content-Type, and SDK identification
headers are protected and cannot be overridden by user headers.
Sourcepub fn http_client(self, client: Client) -> Self
pub fn http_client(self, client: Client) -> Self
Set a custom HTTP client.
The provided client is used as-is; its own timeout and TLS settings apply. The SDK adds per-attempt timeouts through the request context.
Sourcepub fn log_level(self, level: LogLevel) -> Self
pub fn log_level(self, level: LogLevel) -> Self
Set the log level. Falls back to TYPESAFE_LOG_LEVEL, then warn.
Sourcepub fn build(self) -> Result<Client, Error>
pub fn build(self) -> Result<Client, Error>
Build the crate::Client.
Returns Error::Config when the API key is missing or configuration
is invalid.