Skip to main content

Client

Struct Client 

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

Client for interacting with the Gradium API.

The client handles authentication and WebSocket connection management.

Implementations§

Source§

impl Client

Source

pub fn from_location(api_key: &str, location: Location) -> Self

Creates a new client for the specified Gradium API location.

§Arguments
  • api_key - Your Gradium API key
  • location - The API location (EU or US)
Source

pub fn new(api_key: &str) -> Self

Creates a new client for the production Gradium API.

§Arguments
  • api_key - Your Gradium API key
§Example
use gradium::Client;

let client = Client::new("your-api-key");
Source

pub fn us_prod(api_key: &str) -> Self

Creates a new client for the US production Gradium API endpoint.

§Arguments
  • api_key - Your Gradium API key
§Example
use gradium::Client;

let client = Client::us_prod("your-api-key");
Source

pub fn eu_prod(api_key: &str) -> Self

Creates a new client for the EU production Gradium API endpoint.

§Arguments
  • api_key - Your Gradium API key
§Example
use gradium::Client;

let client = Client::eu_prod("your-api-key");
Source

pub fn with_additional_header(self, key: &str, value: &str) -> Self

Adds an additional HTTP header to be sent with each request (builder pattern).

Source

pub fn from_env( base_url: Option<String>, api_key: Option<String>, ) -> Result<Self>

Creates a new client from environment variables.

Uses GRADIUM_API_KEY and GRADIUM_BASE_URL environment variables if the corresponding parameters are None.

§Arguments
  • base_url - Optional base URL override. If None, uses GRADIUM_BASE_URL env var or default
  • api_key - Optional API key override. If None, uses GRADIUM_API_KEY env var
§Returns

A configured Client instance

§Errors

Returns an error if:

  • API key is not provided and GRADIUM_API_KEY is not set
  • Base URL parsing fails
§Example
use gradium::Client;

// Uses environment variables
let client = Client::from_env(None, None)?;

// Override API key
let client = Client::from_env(None, Some("my-key".to_string()))?;
Source

pub fn with_api_key(self, api_key: &str) -> Self

Sets the API key for this client (builder pattern).

§Arguments
  • api_key - The API key to use
§Example
use gradium::Client;

let client = Client::new("old-key")
    .with_api_key("new-key");
Source

pub fn with_server_addr(self, server_addr: &str) -> Self

Sets the server address for this client (builder pattern).

§Arguments
  • server_addr - The server address (e.g., “eu.api.gradium.ai”)
§Example
use gradium::Client;

let client = Client::new("api-key")
    .with_server_addr("localhost:8080");
Source

pub fn with_https(self, use_https: bool) -> Self

Sets whether to use HTTPS/WSS (builder pattern).

§Arguments
  • use_https - true for HTTPS/WSS, false for HTTP/WS
§Example
use gradium::Client;

let client = Client::new("api-key")
    .with_https(false); // Use insecure connection for local testing
Source

pub fn with_path(self, path: &str) -> Self

Sets the base path for API endpoints (builder pattern).

§Arguments
  • path - The base path (e.g., “api” or “v1”)
§Example
use gradium::Client;

let client = Client::new("api-key")
    .with_path("v2");
Source

pub fn with_base_url(self, base_url: &str) -> Result<Self>

Sets the server configuration from a complete base URL (builder pattern).

Parses the URL to extract the server address, port, scheme, and path.

§Arguments
  • base_url - Complete base URL (e.g., “https://eu.api.gradium.ai/api”)
§Returns

The updated client on success

§Errors

Returns an error if the URL cannot be parsed

§Example
use gradium::Client;

let client = Client::new("api-key")
    .with_base_url("https://custom.gradium.ai:8443/v2")?;
Source

pub fn ws_url(&self, endpoint: &str) -> String

Constructs the full WebSocket URL for a given endpoint.

§Arguments
  • endpoint - The API endpoint path (e.g., “speech/tts”)
§Returns

A fully qualified WebSocket URL string

Source

pub fn http_url(&self, endpoint: &str) -> String

Source

pub async fn ws_connect(&self, endpoint: &str) -> Result<WebSocket>

Establishes a WebSocket connection to the specified endpoint.

This method handles authentication by adding the API key to the request headers.

§Arguments
  • endpoint - The API endpoint to connect to (e.g., “speech/tts”)
§Returns

A WebSocket connection on success

§Errors

Returns an error if the connection fails or if the API key is invalid

Source

pub async fn tts(&self, text: &str, setup: Setup) -> Result<TtsResult>

Performs a one-shot text-to-speech conversion.

This is a convenience method that delegates to crate::tts::tts.

§Arguments
  • text - The text to synthesize
  • setup - TTS configuration
§Returns

A TtsResult containing the complete audio data

§Errors

Returns an error if the TTS operation fails

Source

pub async fn tts_stream(&self, setup: Setup) -> Result<TtsStream>

Creates a new TTS stream for real-time text-to-speech.

This is a convenience method that delegates to crate::tts::tts_stream.

§Arguments
  • setup - TTS configuration
§Returns

A TtsStream for streaming TTS operations

§Errors

Returns an error if the stream cannot be created

Source

pub async fn tts_multiplex(&self) -> Result<TtsMultiplexStream>

Opens a multiplexing TTS WebSocket connection.

Returns a TtsMultiplexStream that allows sending multiple independent TTS requests over a single WebSocket, tracked by client_req_id.

§Errors

Returns an error if the WebSocket connection fails

Source

pub async fn stt(&self, audio: Vec<u8>, setup: Setup) -> Result<SttResult>

Performs a one-shot speech-to-text transcription.

This is a convenience method that delegates to crate::stt::stt.

§Arguments
  • audio - Raw audio data to transcribe
  • setup - STT configuration
§Returns

An SttResult containing the transcription

§Errors

Returns an error if the STT operation fails

Source

pub async fn stt_stream(&self, setup: Setup) -> Result<SttStream>

Creates a new STT stream for real-time speech recognition.

This is a convenience method that delegates to crate::stt::stt_stream.

§Arguments
  • setup - STT configuration
§Returns

An SttStream for streaming STT operations

§Errors

Returns an error if the stream cannot be created

Source

pub async fn credits(&self) -> Result<CreditsResponse>

Source

pub async fn usage(&self) -> Result<UsageResponse>

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. 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> 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: 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

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

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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

impl<T> ErasedDestructor for T
where T: 'static,