pub struct AiClientBuilder { /* private fields */ }Expand description
Builder for creating clients with custom configuration.
Keep this surface area small and predictable (developer-friendly).
§Sharing across tasks
AiClient does not implement Clone (by design, for API key and ToS compliance).
To share a client across multiple async tasks, wrap it in Arc:
let client = Arc::new(
AiClientBuilder::new()
.build("openai/gpt-4o")
.await?
);
// Use Arc::clone(&client) to pass to tasks
tokio::spawn(use_client(Arc::clone(&client)));Implementations§
Source§impl AiClientBuilder
impl AiClientBuilder
pub fn new() -> AiClientBuilder
Sourcepub fn protocol_path(self, path: String) -> AiClientBuilder
pub fn protocol_path(self, path: String) -> AiClientBuilder
Set custom protocol directory path.
Sourcepub fn hot_reload(self, enable: bool) -> AiClientBuilder
pub fn hot_reload(self, enable: bool) -> AiClientBuilder
Enable hot reload of protocol files.
Sourcepub fn with_fallbacks(self, fallbacks: Vec<String>) -> AiClientBuilder
pub fn with_fallbacks(self, fallbacks: Vec<String>) -> AiClientBuilder
Set fallback models.
Sourcepub fn strict_streaming(self, enable: bool) -> AiClientBuilder
pub fn strict_streaming(self, enable: bool) -> AiClientBuilder
Enable strict streaming validation (fail fast when streaming config is incomplete).
This is intentionally opt-in to preserve compatibility with partial manifests.
Sourcepub fn feedback_sink(self, sink: Arc<dyn FeedbackSink>) -> AiClientBuilder
pub fn feedback_sink(self, sink: Arc<dyn FeedbackSink>) -> AiClientBuilder
Inject a feedback sink. Default is a no-op sink.
Sourcepub fn max_inflight(self, n: usize) -> AiClientBuilder
pub fn max_inflight(self, n: usize) -> AiClientBuilder
Limit maximum number of in-flight requests/streams. This is a simple backpressure mechanism for production safety.
Sourcepub fn base_url_override(self, base_url: impl Into<String>) -> AiClientBuilder
pub fn base_url_override(self, base_url: impl Into<String>) -> AiClientBuilder
Override the base URL from the protocol manifest.
This is primarily for testing with mock servers. In production, use the base_url defined in the protocol manifest.