pub struct BraintrustClientBuilder { /* private fields */ }Expand description
Builder for creating a BraintrustClient with configuration.
Configuration is loaded from environment variables by default, and can be overridden using builder methods.
§Example
use braintrust_sdk_rust::BraintrustClient;
// Using environment variables (BRAINTRUST_API_KEY, etc.)
let client = BraintrustClient::builder().build().await?;
// With explicit configuration
let client = BraintrustClient::builder()
.api_key("sk-...")
.org_name("my-org")
.default_project("my-project")
.blocking_login(true)
.build()
.await?;Implementations§
Source§impl BraintrustClientBuilder
impl BraintrustClientBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new builder with defaults from environment variables.
Supported environment variables:
BRAINTRUST_API_KEY: API key for authentication (required)BRAINTRUST_APP_URL: Braintrust app URL (default:https://www.braintrust.dev)BRAINTRUST_API_URL: API endpoint URL (default:https://api.braintrust.dev)BRAINTRUST_ORG_NAME: Organization name (default: first org from login)BRAINTRUST_DEFAULT_PROJECT: Default project name
Sourcepub fn api_key(self, api_key: impl Into<String>) -> Self
pub fn api_key(self, api_key: impl Into<String>) -> Self
Set the API key (overrides BRAINTRUST_API_KEY env var).
Sourcepub fn app_url(self, url: impl Into<String>) -> Self
pub fn app_url(self, url: impl Into<String>) -> Self
Set the app URL (overrides BRAINTRUST_APP_URL env var).
Sourcepub fn api_url(self, url: impl Into<String>) -> Self
pub fn api_url(self, url: impl Into<String>) -> Self
Set the API URL (overrides BRAINTRUST_API_URL env var).
Sourcepub fn org_name(self, name: impl Into<String>) -> Self
pub fn org_name(self, name: impl Into<String>) -> Self
Set the organization name (overrides BRAINTRUST_ORG_NAME env var).
Sourcepub fn default_project(self, name: impl Into<String>) -> Self
pub fn default_project(self, name: impl Into<String>) -> Self
Set the default project name (overrides BRAINTRUST_DEFAULT_PROJECT env var).
Sourcepub fn queue_size(self, size: usize) -> Self
pub fn queue_size(self, size: usize) -> Self
Set the internal queue size for buffering log events.
Sourcepub fn blocking_login(self, blocking: bool) -> Self
pub fn blocking_login(self, blocking: bool) -> Self
Block until login completes (default: false, login happens in background).
When false (default), login happens asynchronously in a background task.
When true, the build() method waits for login to complete before returning.
Sourcepub async fn build(self) -> Result<BraintrustClient>
pub async fn build(self) -> Result<BraintrustClient>
Build the client, performing login.
If blocking_login is true, waits for login to complete.
Otherwise, login happens in the background with retry logic.