Rust SDK
UnpublishedBlocking client; arbitrary precision via num-bigint.
Not yet published
Initialize
The API key is a positional argument; new returns a Result. The client is Clone (Arc-shared).
use counters::CountersClient;
let client = CountersClient::new(std::env::var("COUNTERS_API_KEY")?)?;Count
add and subtract are buffered and coalesced per counter (flushed as one POST /batch); add_now/subtract_now apply immediately and return the counter. Amounts accept integers, a string, or a BigInt.
let reg = client.counter("registrations")?;
reg.add(1)?; // buffered
reg.add(5)?; // coalesced
client.flush()?; // one POST /batch
let c = reg.add_now(1)?; // immediate
println!("{}", c.value); // "42"Read
Read the current value, or a per-bucket time series. from/to are RFC 3339 strings; event-time writes use the separate add_now_at/subtract_now_at methods.
let value = reg.value()?.value;
let series = reg.series(
SeriesParams::new("2026-01-01T00:00:00Z", "2026-01-08T00:00:00Z", "1d"),
)?;Manage
clear resets to zero (new epoch, history retained); delete tombstones the counter; list pages the counters in the organization.
reg.clear()?;
reg.delete()?;
let page = client.list(None, Some(50))?; // cursor, limitLifecycle
Buffered writes flush on a worker thread and at max_batch_size. Call close before the program exits so nothing is lost.
client.close()?; // flush + stop the worker threadErrors
Everything returns Result with one CountersError enum: Validation (bad input), Api (non-2xx, carries status/title/problem), and Transport (network).
use counters::CountersError;
match reg.add_now(1) {
Ok(c) => println!("value = {}", c.value),
Err(CountersError::Validation(msg)) => eprintln!("bad input: {msg}"),
Err(CountersError::Api { status, .. }) => eprintln!("api error {status}"),
Err(e) => eprintln!("{e}"),
}