Skip to main content

ClientConfig

Struct ClientConfig 

Source
#[non_exhaustive]
pub struct ClientConfig { pub api_key: String, pub base_url: String, pub default_model: String, pub timeout: Duration, pub retry: RetryPolicy, pub http_client: Option<Client>, }
Expand description

Configuration for constructing a TypeSafeClient.

All fields are public for inspection and mutation, but the struct is #[non_exhaustive], so external crates must use ClientConfig::new or ClientConfig::default plus the builder methods to construct configurations.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§api_key: String

API key for authentication.

Set this directly or use TypeSafeClient::from_env to read it from the TYPESAFE_API_KEY environment variable.

§base_url: String

API root. Defaults to https://api.typesafe.ai.

A base path is supported and preserved: e.g. https://example.com/api produces endpoints like https://example.com/api/v1/systemone. Credentials, query parameters, and fragments are rejected.

§default_model: String

Default model. Defaults to jev-latest.

§timeout: Duration

Per-attempt timeout. Defaults to 10 seconds.

§retry: RetryPolicy

Retry policy. Defaults to 2 retries with exponential backoff + jitter.

§http_client: Option<Client>

Custom reqwest::Client to use for HTTP requests. If None, a new client is built from the other config fields. This allows sharing a connection pool or using a custom TLS configuration.

Implementations§

Source§

impl ClientConfig

Source

pub fn new(api_key: impl Into<String>) -> Self

Create a new ClientConfig with the given API key and all other fields set to their defaults.

Use the .with_*() methods to override individual fields.

Source

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

Set the API key.

Source

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

Set the base URL.

Source

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

Set the default model.

Source

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

Set the per-attempt timeout.

This is the timeout for a single HTTP request, not the total time across all retries. The first attempt always uses the full configured timeout; subsequent attempts are capped at the remaining retry budget (if set). See RetryPolicy::budget.

Source

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

Set the retry policy.

Source

pub fn with_http_client(self, client: HttpClient) -> Self

Provide a custom reqwest::Client for HTTP requests. If not set, the client builds one from the other config fields (timeout, default headers). Use this to share a connection pool or apply custom TLS settings.

The client is used as-is, so the caller controls redirect behavior. The SDK’s default client disables redirects to prevent POST replay via 307/308; a custom client that follows redirects does not have this protection.

Trait Implementations§

Source§

impl Clone for ClientConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ClientConfig

Source§

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

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

impl Default for ClientConfig

Source§

fn default() -> Self

Create a ClientConfig with all fields at their defaults.

Note: api_key defaults to an empty string, which will cause TypeSafeClient::from_config to return an Authentication error on the first request. Use ClientConfig::new or set api_key explicitly before constructing a client.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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