pub struct ClientConfigBuilder { /* private fields */ }Expand description
Builder for ClientConfig.
Construct with ClientConfigBuilder::new and call builder methods to
customise the configuration, then call ClientConfigBuilder::build to
obtain a ClientConfig.
Implementations§
Source§impl ClientConfigBuilder
impl ClientConfigBuilder
Sourcepub fn new(api_key: impl Into<String>) -> Self
pub fn new(api_key: impl Into<String>) -> Self
Create a new builder with the given API key and sensible defaults.
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Create a builder with no explicit API key.
load_env is true by default, so the key will be read from the
provider’s environment variable (e.g. OPENAI_API_KEY) at client
construction time. Call .load_env(false) to opt out.
Sourcepub fn load_env(self, enabled: bool) -> Self
pub fn load_env(self, enabled: bool) -> Self
Enable or disable automatic API key loading from environment variables.
When true (the default) and no explicit api_key was provided,
[DefaultClient::new] reads the provider’s designated environment
variable. Set to false to require an explicit key.
Has no effect on WASM targets.
Sourcepub fn base_url(self, url: impl Into<String>) -> Self
pub fn base_url(self, url: impl Into<String>) -> Self
Override the provider base URL for all requests.
Sourcepub fn max_retries(self, retries: u32) -> Self
pub fn max_retries(self, retries: u32) -> Self
Set the maximum number of retries on 429 / 5xx responses (default: 3).
Sourcepub fn credential_provider(self, provider: Arc<dyn CredentialProvider>) -> Self
pub fn credential_provider(self, provider: Arc<dyn CredentialProvider>) -> Self
Set a dynamic credential provider for token-based or refreshable auth.
When configured, the client calls resolve() before each request
instead of using the static api_key for authentication.
Sourcepub fn header(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Result<Self>
pub fn header( self, key: impl Into<String>, value: impl Into<String>, ) -> Result<Self>
Add a custom header sent on every request.
Returns an error if either key or value is not a valid HTTP header
name / value.
This method is only available when the native-http feature is enabled
because header validation relies on reqwest’s header types.
Sourcepub fn build(self) -> ClientConfig
pub fn build(self) -> ClientConfig
Consume the builder and return the completed ClientConfig.