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
impl Client
Sourcepub fn new(cfg: Config) -> Result<Self, Error>
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.
Sourcepub fn with_key(key: impl Into<ApiKey>) -> ClientBuilder
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()?;Sourcepub fn with_token(token: impl Into<String>) -> ClientBuilder
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()?;Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Returns a builder for more complex client configuration.
Sourcepub async fn from_token_provider(
provider: &dyn TokenProvider,
) -> Result<Self, Error>
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?;Sourcepub fn responses(&self) -> ResponsesClient
pub fn responses(&self) -> ResponsesClient
Returns the Responses client for POST /responses (streaming + non-streaming).
Sourcepub fn auth(&self) -> AuthClient
pub fn auth(&self) -> AuthClient
Returns the auth client for customer token operations.
Sourcepub fn customers(&self) -> CustomersClient
pub fn customers(&self) -> CustomersClient
Returns the customers client for customer management.
Requires a secret key (mr_sk_*) for authentication.
Sourcepub fn tiers(&self) -> TiersClient
pub fn tiers(&self) -> TiersClient
Returns the tiers client for tier operations.
Requires a secret key (mr_sk_*) for authentication.
Sourcepub fn models(&self) -> ModelsClient
pub fn models(&self) -> ModelsClient
Returns the models client for model catalog operations.
The underlying endpoint is public (no auth required).
Sourcepub fn runs(&self) -> RunsClient
pub fn runs(&self) -> RunsClient
Returns the runs client for workflow runs (/runs).
Sourcepub fn workflows(&self) -> WorkflowsClient
pub fn workflows(&self) -> WorkflowsClient
Returns the workflows client for compilation/validation (/workflows).
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)