StandaloneClientBuilder

Struct StandaloneClientBuilder 

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

Builder for creating standalone mode UltrafastClient instances.

The StandaloneClientBuilder is used to configure clients that communicate directly with AI providers without going through a gateway.

§Features

  • Direct Provider Communication: Bypass gateway for lower latency
  • Provider Management: Add and configure multiple AI providers
  • Routing Strategies: Choose how requests are distributed
  • Caching: Configure response caching for performance
  • Retry Policies: Customize retry behavior

§Examples

§Basic Setup

let client = StandaloneClientBuilder::default()
    .with_openai("your-openai-key")
    .build()?;

§Multi-Provider Setup

let client = StandaloneClientBuilder::default()
    .with_openai("openai-key")
    .with_anthropic("anthropic-key")
    .with_google_vertex_ai("google-key", "project-id")
    .with_ollama("http://localhost:11434")
    .with_routing_strategy(RoutingStrategy::LoadBalance {
        weights: vec![0.4, 0.3, 0.2, 0.1],
    })
    .build()?;

§Advanced Configuration

use ultrafast_models_sdk::{CacheConfig, RoutingStrategy};
use std::time::Duration;

let cache_config = CacheConfig {
    enabled: true,
    ttl: Duration::from_hours(1),
    max_size: 1000,
    backend: CacheBackend::Memory,
};

let client = StandaloneClientBuilder::default()
    .with_openai("your-key")
    .with_routing_strategy(RoutingStrategy::Failover)
    .with_cache_config(cache_config)
    .build()?;

§Provider Methods

§OpenAI

.with_openai("your-openai-api-key")

§Anthropic

.with_anthropic("your-anthropic-api-key")

§Azure OpenAI

.with_azure_openai("your-azure-key", "deployment-name")

§Google Vertex AI

.with_google_vertex_ai("your-google-key", "project-id")

§Cohere

.with_cohere("your-cohere-api-key")

§Groq

.with_groq("your-groq-api-key")

§Ollama

.with_ollama("http://localhost:11434")

§Custom Providers

let custom_config = ProviderConfig::new("custom", "api-key");
.with_provider("custom", custom_config)

§Routing Strategies

§Single Provider

.with_routing_strategy(RoutingStrategy::Single)

§Load Balancing

.with_routing_strategy(RoutingStrategy::LoadBalance {
    weights: vec![0.6, 0.4], // 60% OpenAI, 40% Anthropic
})

§Failover

.with_routing_strategy(RoutingStrategy::Failover)

§Conditional Routing

.with_routing_strategy(RoutingStrategy::Conditional {
    conditions: vec![
        ("model", "gpt-4", "openai"),
        ("model", "claude-3", "anthropic"),
    ],
    default: "openai".to_string(),
})

§A/B Testing

.with_routing_strategy(RoutingStrategy::ABTesting {
    split: 0.5, // 50% to each provider
})

§Caching Configuration

let cache_config = CacheConfig {
    enabled: true,
    ttl: Duration::from_hours(1),
    max_size: 1000,
    backend: CacheBackend::Memory,
};

.with_cache_config(cache_config)

§Performance Optimization

  • Provider Selection: Choose providers based on your needs
  • Routing Strategy: Optimize for latency, cost, or reliability
  • Caching: Enable caching for repeated requests
  • Connection Pooling: Configure appropriate pool sizes

§Error Handling

The builder validates configuration and returns errors for:

  • Missing provider configurations
  • Invalid routing strategies
  • Configuration conflicts
  • Network connectivity issues

§Thread Safety

The builder is not thread-safe. Build the client first, then share the client instance.

§See Also

Implementations§

Source§

impl StandaloneClientBuilder

Source

pub fn with_provider( self, name: impl Into<String>, config: ProviderConfig, ) -> Self

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub fn with_routing_strategy(self, strategy: RoutingStrategy) -> Self

Source

pub fn with_cache(self, config: CacheConfig) -> Self

Source

pub fn build(self) -> Result<UltrafastClient, ClientError>

Trait Implementations§

Source§

impl Default for StandaloneClientBuilder

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> 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, 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,