new Brello({ apiKey, options }). Explicit options take precedence over environment variables.
An environment mismatch disables delivery while the provider client continues serving requests. Debug output masks user IDs and attributes by default.
Connect to self-hosted Brello
Set the URL of your Brello API, including its/v1 prefix:
options.apiBaseUrl when constructing the client. Use HTTPS for self-hosted deployments. Local loopback development can use http://localhost:8000/v1.
Attribute usage to users and features
UsewithContext() for a single call or a block of async calls:
wrap(client, defaults). Set endUser: false or attributes: false in a context to omit the corresponding fields. Brello sends user and attribute fields when the project configuration enables them. When hashing is enabled, the SDK omits the user until configuration supplies the HMAC settings.
Changes to collection settings can take up to 60 seconds to reach a running SDK. For Google Gen AI clients, set provider in wrap() to select the backend for that client. Use withContext() for per-call metadata.
Send application user IDs and allowlisted attributes. Brello collects usage metadata without reading prompts, output text, tool arguments or results, or embedding vectors. See privacy and collection settings.
Batch and flush events
The SDK starts a delivery after 20 events or about two seconds. It holds up to 500 events or 2 MiB of serialized events, including the batch in flight. When the buffer fills, the SDK evicts older pending events. Events expire after 60 seconds. Retries reuse the original event UUID. For429, the SDK honors Retry-After and discards expired events. After three consecutive ingestion failures caused by a network error, timeout, or HTTP 5xx, the SDK pauses delivery for 30 seconds. The next batch tests recovery. Continued failures increase the pause with jitter, up to five minutes. A rejected project key pauses delivery for that client. Provider calls continue during these pauses.
Use await brello.flush() during Node.js shutdown or before a short-lived script exits. The default wait is five seconds. Call brello.flush(timeoutMs) to use a different deadline. A flush can return earlier if delivery is paused beyond that deadline. Check Connected in project settings to confirm that the worker has stored an event.
Use Cloudflare Workers
Enable Node.js compatibility and pass the Worker secret binding asapiKey:
options.apiBaseUrl.