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
UltrafastClient- The main client structUltrafastClientBuilder- The main builderGatewayClientBuilder- For gateway modeProviderConfig- For provider configurationCacheConfig- For cache configuration
Implementations§
Source§impl StandaloneClientBuilder
impl StandaloneClientBuilder
pub fn with_provider( self, name: impl Into<String>, config: ProviderConfig, ) -> Self
pub fn with_openai(self, api_key: impl Into<String>) -> Self
pub fn with_anthropic(self, api_key: impl Into<String>) -> Self
pub fn with_azure_openai( self, api_key: impl Into<String>, deployment_name: impl Into<String>, ) -> Self
pub fn with_google_vertex_ai( self, api_key: impl Into<String>, project_id: impl Into<String>, ) -> Self
pub fn with_cohere(self, api_key: impl Into<String>) -> Self
pub fn with_groq(self, api_key: impl Into<String>) -> Self
pub fn with_mistral(self, api_key: impl Into<String>) -> Self
pub fn with_perplexity(self, api_key: impl Into<String>) -> Self
pub fn with_openrouter(self, api_key: impl Into<String>) -> Self
pub fn with_ollama(self, base_url: impl Into<String>) -> Self
pub fn with_custom( self, name: impl Into<String>, api_key: impl Into<String>, base_url: impl Into<String>, ) -> Self
pub fn with_routing_strategy(self, strategy: RoutingStrategy) -> Self
pub fn with_cache(self, config: CacheConfig) -> Self
pub fn build(self) -> Result<UltrafastClient, ClientError>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StandaloneClientBuilder
impl RefUnwindSafe for StandaloneClientBuilder
impl Send for StandaloneClientBuilder
impl Sync for StandaloneClientBuilder
impl Unpin for StandaloneClientBuilder
impl UnwindSafe for StandaloneClientBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more