Skip to main content

ClientBuilder

Struct ClientBuilder 

Source
pub struct ClientBuilder { /* private fields */ }
Expand description

Build an async client for the SystemOne API.

Settings resolve in priority order: explicit builder value → OPENKIND_* environment variable → TYPESAFE_* environment variable (for drop-in parity with the Python SDK) → SDK default. The API key is required unless allow_unauthenticated is selected; everything else has a default. Cloudflare mode selects its own account URL and typesafe/jev model unless overridden explicitly.

§Examples

use openkind_client::Client;

// Hosted TypeSafe API (default base URL).
let client = Client::builder().api_key("sk-...").build()?;

// Local daemon.
let local = Client::builder()
    .api_key("dev-key")
    .base_url("http://127.0.0.1:18080")
    .build()?;

Implementations§

Source§

impl ClientBuilder

Source

pub fn new() -> Self

A builder with every setting unset (environment/defaults apply).

Source

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

Bearer API key. Falls back to OPENKIND_API_KEY, then TYPESAFE_API_KEY, when unset.

Source

pub fn allow_unauthenticated(self) -> Self

Allow a missing API key when connecting to an unauthenticated daemon. Supplied and environment keys still resolve and validate normally.

Source

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

API base URL, e.g. http://127.0.0.1:18080. Falls back to OPENKIND_BASE_URL, then TYPESAFE_BASE_URL, then DEFAULT_BASE_URL.

Source

pub fn cloudflare_account(self, account_id: impl Into<String>) -> Self

Use Cloudflare Workers AI Jev through the account’s /ai/run API. The API token is supplied with api_key. An explicit base_url may override the Cloudflare host for a proxy or test server. Cloudflare mode ignores base URL and model env defaults.

Source

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

Model alias used by Client::system_one when the request does not name one. Falls back to OPENKIND_DEFAULT_MODEL, then TYPESAFE_DEFAULT_MODEL, then DEFAULT_MODEL.

Source

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

Per-attempt request timeout. Default 10s.

Source

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

TCP connect timeout. Unset by default.

Source

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

Retry behavior. Defaults to RetryPolicy::default.

Source

pub fn header(self, name: HeaderName, value: HeaderValue) -> Self

A header sent with every request.

Source

pub fn http_client(self, client: Client) -> Self

Supply a preconfigured reqwest::Client (connection pooling, proxy, TLS settings). Default headers and timeouts are still applied per-request by this SDK.

Source

pub fn build(self) -> Result<Client, Error>

Validate settings and construct the Client.

Trait Implementations§

Source§

impl Clone for ClientBuilder

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 Default for ClientBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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