Client

Struct Client 

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

Async client for the ModelRelay API.

This is the primary client for making API requests. For synchronous contexts, use BlockingClient instead (requires the blocking feature).

§Example

use modelrelay::{Client, Config, ResponseBuilder};

let client = Client::new(Config {
    api_key: Some(modelrelay::ApiKey::parse("mr_sk_...")?),
    ..Default::default()
})?;

let response = ResponseBuilder::new()
    .model("gpt-4o-mini")
    .user("Hello!")
    .send(&client.responses())
    .await?;

Implementations§

Source§

impl Client

Source

pub fn new(cfg: Config) -> Result<Self, Error>

Creates a new client with the given configuration.

Note: Either api_key or access_token must be provided. This is validated at construction time and will return an error if neither is set.

For clearer intent, consider using Client::with_key or Client::with_token which make the authentication requirement explicit.

Source

pub fn with_key(key: impl Into<ApiKey>) -> ClientBuilder

Creates a new client authenticated with an API key.

The key is required and must be non-empty. Use ClientBuilder for additional configuration options.

§Examples
use modelrelay::Client;

let client = Client::with_key(modelrelay::ApiKey::parse("mr_sk_...")?).build()?;
Source

pub fn with_token(token: impl Into<String>) -> ClientBuilder

Creates a new client authenticated with a bearer access token.

The token is required and must be non-empty. Use ClientBuilder for additional configuration options.

§Examples
use modelrelay::Client;

let client = Client::with_token("eyJ...").build()?;
Source

pub fn builder() -> ClientBuilder

Returns a builder for more complex client configuration.

Source

pub async fn from_token_provider( provider: &dyn TokenProvider, ) -> Result<Self, Error>

Creates a client using a token provider.

This calls the provider to get a token immediately, then returns a client configured with that token. The provider’s internal caching ensures efficient token reuse; call this function again when you need a fresh client with a potentially refreshed token.

§Example
use modelrelay::{Client, OIDCExchangeTokenProvider, OIDCExchangeConfig, ApiKey};

let provider = OIDCExchangeTokenProvider::new(OIDCExchangeConfig {
    api_key: ApiKey::parse("mr_pk_...")?,
    id_token_source: Box::new(|| Box::pin(async { get_id_token().await })),
    ..Default::default()
})?;

let client = Client::from_token_provider(&provider).await?;
Source

pub fn responses(&self) -> ResponsesClient

Returns the Responses client for POST /responses (streaming + non-streaming).

Source

pub fn auth(&self) -> AuthClient

Returns the auth client for customer token operations.

Source

pub fn customers(&self) -> CustomersClient

Returns the customers client for customer management.

Requires a secret key (mr_sk_*) for authentication.

Source

pub fn tiers(&self) -> TiersClient

Returns the tiers client for tier operations.

Requires a secret key (mr_sk_*) for authentication.

Source

pub fn models(&self) -> ModelsClient

Returns the models client for model catalog operations.

The underlying endpoint is public (no auth required).

Source

pub fn runs(&self) -> RunsClient

Returns the runs client for workflow runs (/runs).

Source

pub fn workflows(&self) -> WorkflowsClient

Returns the workflows client for compilation/validation (/workflows).

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

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 ()

§

impl<T> From<T> for T

§

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
§

impl<T, U> Into<U> for T
where U: From<T>,

§

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: 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: 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
§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

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